|
| 1 | +name: deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - 130_MS_Github_Actions |
| 7 | + # pull_request: |
| 8 | +# types: |
| 9 | +# - closed |
| 10 | +# branches: |
| 11 | +# - master |
| 12 | +# - dev |
| 13 | +# - 130_MS_Github_Actions |
| 14 | +# - "*" |
| 15 | +# paths: |
| 16 | +# - .github/** |
| 17 | +# - .circleci/** |
| 18 | + workflow_dispatch: |
| 19 | + inputs: |
| 20 | + version_bump: |
| 21 | + description: 'Version increment to bump (patch, minor, major)' |
| 22 | + required: true |
| 23 | + |
| 24 | +jobs: |
| 25 | + get-version-bump: |
| 26 | +# if: github.event.pull_request.merged == true |
| 27 | + runs-on: ubuntu-latest |
| 28 | + outputs: |
| 29 | + increment: ${{ steps.run-script.outputs.result }} |
| 30 | + steps: |
| 31 | + - name: Check for PR labels or workflow dispatch input |
| 32 | + id: run-script |
| 33 | + uses: actions/github-script@v7 |
| 34 | + with: |
| 35 | + result-encoding: string |
| 36 | + script: | |
| 37 | + var versionBump = null; |
| 38 | + console.log(`Event name: ${context.eventName}`); |
| 39 | + |
| 40 | + // check if the event is a pull request or a dispatch |
| 41 | + // if it is a pull request, check which labels it has |
| 42 | + // if it is a pull request that was merged into the `dev` branch, default to a pre-release version bump |
| 43 | + if (context.eventName == 'pull_request') { |
| 44 | + // Get the pull request number from the context |
| 45 | + var pullRequestNumber = context.issue.number; |
| 46 | + if (!pullRequestNumber) { |
| 47 | + console.log('No pull request number found in context, trying to get it from commit'); |
| 48 | + // Otherwise get issue number from the commit |
| 49 | + pullRequestNumber = ( |
| 50 | + await github.rest.repos.listPullRequestsAssociatedWithCommit({ |
| 51 | + commit_sha: context.sha, |
| 52 | + owner: context.repo.owner, |
| 53 | + repo: context.repo.repo, |
| 54 | + }) |
| 55 | + ).data[0].number; |
| 56 | + } |
| 57 | + console.log(`Pull request number: ${pullRequestNumber}`); |
| 58 | + // now get the pull request from the API |
| 59 | + const { data: pullRequest } = await github.rest.pulls.get({ |
| 60 | + owner: context.repo.owner, |
| 61 | + repo: context.repo.repo, |
| 62 | + pull_number: pullRequestNumber, |
| 63 | + }); |
| 64 | + console.log(`Pull request labels: ${JSON.stringify(pullRequest.labels, null, 2)}`); |
| 65 | + |
| 66 | + // check if on dev branch |
| 67 | + if (pullRequest.base.ref !== 'master') { |
| 68 | + console.log('On dev branch, defaulting to pre-release version bump'); |
| 69 | + versionBump = "prerelease"; |
| 70 | + return versionBump; |
| 71 | + } |
| 72 | + |
| 73 | + for (const label of (pullRequest.labels ?? [])) { |
| 74 | + if (['major', 'minor', 'patch'].includes(label.name)) { |
| 75 | + versionBump = label.name; |
| 76 | + break; |
| 77 | + } |
| 78 | + } |
| 79 | + // if it is a workflow dispatch, check what the input was |
| 80 | + } else if (context.eventName == 'workflow_dispatch') { |
| 81 | + if (['major', 'minor', 'patch'].includes(${{ toJSON(inputs.version_bump) }})) { |
| 82 | + versionBump = ${{ toJSON(inputs.version_bump) }}; |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + console.log(`Version bump: ${versionBump}`); |
| 87 | + return versionBump; |
| 88 | +
|
| 89 | + bump-version: |
| 90 | + needs: get-version-bump |
| 91 | + runs-on: ubuntu-latest |
| 92 | + # Grant GITHUB_TOKEN the permissions required to make a Pages deployment |
| 93 | + permissions: |
| 94 | + contents: write |
| 95 | + id-token: write # to verify the deployment originates from an appropriate source |
| 96 | + |
| 97 | + steps: |
| 98 | + - name: Check if version bump is needed |
| 99 | + if: needs.get-version-bump.outputs.increment == null || needs.get-version-bump.outputs.increment == 'null' |
| 100 | + # exit 0 to prevent further steps from running |
| 101 | + run: exit 0 |
| 102 | + |
| 103 | + - name: Checkout code |
| 104 | + uses: actions/checkout@v4 |
| 105 | + with: |
| 106 | + fetch-depth: 0 # Fetch all history for all branches and tags. |
| 107 | + ref: ${{ github.base_ref }} |
| 108 | + |
| 109 | + - name: Setup Node.js |
| 110 | + uses: actions/setup-node@v4 |
| 111 | + with: |
| 112 | + node-version: 20 |
| 113 | + cache: yarn |
| 114 | + |
| 115 | + - name: Clean input string |
| 116 | + run: | |
| 117 | + INPUT_VERSION="${{ needs.get-version-bump.outputs.increment }}" |
| 118 | + INPUT_VERSION=${INPUT_VERSION,,} |
| 119 | + echo "INPUT_VERSION=${INPUT_VERSION// /}" >> $GITHUB_ENV |
| 120 | +
|
| 121 | + - name: Bump version and push tag |
| 122 | + run: | |
| 123 | + # Configure the credentials of the GitHub Actions Bot |
| 124 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 125 | + git config user.name "github-actions[bot]" |
| 126 | +
|
| 127 | + # add args to yarn version command if INPUT_VERSION is "prerelease" |
| 128 | + if [ $INPUT_VERSION == "prerelease" ]; then |
| 129 | + yarn version --prerelease --preid dev --message "chore(release): bump version to v%s" |
| 130 | + else |
| 131 | + yarn version --${{ env.INPUT_VERSION }} --message "chore(release): bump version to v%s" |
| 132 | + fi |
| 133 | + git push |
| 134 | + git push --tags |
| 135 | +
|
| 136 | + build-image: |
| 137 | + runs-on: ubuntu-latest |
| 138 | + # Grant GITHUB_TOKEN the permissions required to make a Pages deployment |
| 139 | + permissions: |
| 140 | + contents: read |
| 141 | + id-token: write # to verify the deployment originates from an appropriate source |
| 142 | + |
| 143 | + needs: |
| 144 | + - bump-version |
| 145 | + steps: |
| 146 | + - uses: actions/checkout@v4 |
| 147 | + |
| 148 | + - name: Authenticate to Google Cloud |
| 149 | + id: auth |
| 150 | + uses: google-github-actions/auth@v2 |
| 151 | + with: |
| 152 | + token_format: access_token |
| 153 | + workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }} |
| 154 | + service_account: ${{ secrets.SERVICE_ACCOUNT }} |
| 155 | + |
| 156 | + # This example uses the docker login action |
| 157 | + - name: Login to Artifact Registry |
| 158 | + uses: docker/login-action@v3 |
| 159 | + with: |
| 160 | + registry: us-docker.pkg.dev |
| 161 | + username: oauth2accesstoken |
| 162 | + password: ${{ steps.auth.outputs.access_token }} |
| 163 | + |
| 164 | + - name: Set up Docker Buildx |
| 165 | + uses: docker/setup-buildx-action@v3 |
| 166 | + |
| 167 | + - name: Extract version |
| 168 | + id: extract-version |
| 169 | + run: | |
| 170 | + echo "PACKAGE_VERSION=$(jq -r '.version' package.json)" >> $GITHUB_ENV |
| 171 | +
|
| 172 | + - name: Build and push server image |
| 173 | + uses: docker/build-push-action@v5 |
| 174 | + with: |
| 175 | + push: true |
| 176 | + tags: | |
| 177 | + us-docker.pkg.dev/motrpac-portal-dev/datahub/frontend:${{ github.sha }} |
| 178 | + us-docker.pkg.dev/motrpac-portal-dev/datahub/frontend:${{ env.PACKAGE_VERSION }} |
| 179 | + us-docker.pkg.dev/motrpac-portal-dev/datahub/frontend:latest |
| 180 | + cache-from: type=gha |
| 181 | + cache-to: type=gha,mode=max |
| 182 | + build-args: | |
| 183 | + REACT_APP_ES_PROXY_HOST="${{secrets.REACT_APP_ES_PROXY_HOST}}" |
| 184 | + REACT_APP_ES_PROXY_HOST_DEV="${{secrets.REACT_APP_ES_PROXY_HOST_DEV}}" |
| 185 | + REACT_APP_API_SERVICE_ADDRESS="${{secrets.REACT_APP_API_SERVICE_ADDRESS}}" |
| 186 | + REACT_APP_API_SERVICE_ADDRESS_DEV="${{secrets.REACT_APP_API_SERVICE_ADDRESS_DEV}}" |
| 187 | + REACT_APP_API_SERVICE_KEY="${{secrets.REACT_APP_API_SERVICE_KEY}}" |
| 188 | + REACT_APP_API_SERVICE_KEY_DEV="${{secrets.REACT_APP_API_SERVICE_KEY_DEV}}" |
| 189 | + REACT_APP_SIGNED_URL_ENDPOINT="${{secrets.REACT_APP_SIGNED_URL_ENDPOINT}}" |
| 190 | + REACT_APP_USER_REGISTRATION_ENDPOINT="${{secrets.REACT_APP_USER_REGISTRATION_ENDPOINT}}" |
| 191 | + REACT_APP_SEND_EMAIL_ENDPOINT="${{secrets.REACT_APP_SEND_EMAIL_ENDPOINT}}" |
| 192 | + REACT_APP_FILE_DOWNLOAD_ENDPOINT="${{secrets.REACT_APP_FILE_DOWNLOAD_ENDPOINT}}" |
| 193 | + REACT_APP_QC_DATA_ENDPOINT="${{secrets.REACT_APP_QC_DATA_ENDPOINT}}" |
| 194 | + REACT_APP_ES_ENDPOINT="${{secrets.REACT_APP_ES_ENDPOINT}}" |
| 195 | + REACT_APP_FILE_SEARCH_ENDPOINT="${{secrets.REACT_APP_FILE_SEARCH_ENDPOINT}}" |
| 196 | + REACT_APP_DATA_FILE_BUCKET="${{secrets.REACT_APP_DATA_FILE_BUCKET}}" |
| 197 | + REACT_APP_QC_REPORT_BUCKET="${{secrets.REACT_APP_QC_REPORT_BUCKET}}" |
| 198 | + REACT_APP_QC_REPORT_BUCKET_DEV="${{secrets.REACT_APP_QC_REPORT_BUCKET_DEV}}" |
| 199 | + REACT_APP_ES_ACCESS_TOKEN="${{secrets.REACT_APP_ES_ACCESS_TOKEN}}" |
| 200 | + REACT_APP_ES_ACCESS_TOKEN_DEV="${{secrets.REACT_APP_ES_ACCESS_TOKEN_DEV}}" |
| 201 | + REACT_APP_reCAPTCHA_SITE_KEY="${{secrets.REACT_APP_reCAPTCHA_SITE_KEY}}" |
| 202 | + REACT_APP_AUTH0_CLIENT_ID="${{secrets.REACT_APP_AUTH0_CLIENT_ID}}" |
| 203 | + REACT_APP_QUALTRICS_SURVEY_URL="${{secrets.REACT_APP_QUALTRICS_SURVEY_URL}}" |
| 204 | + REACT_APP_USER_SURVEY_SUBMIT_URL="${{secrets.REACT_APP_USER_SURVEY_SUBMIT_URL}}" |
| 205 | + REACT_APP_USER_SURVEY_INPUT_1="${{secrets.REACT_APP_USER_SURVEY_INPUT_1}}" |
| 206 | + REACT_APP_USER_SURVEY_INPUT_2="${{secrets.REACT_APP_USER_SURVEY_INPUT_2}}" |
| 207 | + REACT_APP_USER_SURVEY_INPUT_3="${{secrets.REACT_APP_USER_SURVEY_INPUT_3}}" |
| 208 | + REACT_APP_USER_SURVEY_INPUT_4="${{secrets.REACT_APP_USER_SURVEY_INPUT_4}}" |
| 209 | + REACT_APP_USER_SURVEY_INPUT_5="${{secrets.REACT_APP_USER_SURVEY_INPUT_5}}" |
| 210 | + REACT_APP_OFFICE_HOUR_DAY="${{secrets.REACT_APP_OFFICE_HOUR_DAY}}" |
| 211 | + REACT_APP_OFFICE_HOUR_DATE="${{secrets.REACT_APP_OFFICE_HOUR_DATE}}" |
| 212 | + REACT_APP_OFFICE_HOUR_SIGNUP_URL="${{secrets.REACT_APP_OFFICE_HOUR_SIGNUP_URL}}" |
0 commit comments