From 5aabb623bcff6840b77553ff3ed36b56a4c6ad6b Mon Sep 17 00:00:00 2001 From: Matt Krick Date: Thu, 9 Nov 2023 13:37:28 -0800 Subject: [PATCH 1/5] chore: release to staging from github Signed-off-by: Matt Krick --- .github/workflows/release.yml | 36 ++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cf585472b50..4beb0eafede 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,9 +34,9 @@ jobs: gcloud container images add-tag -q \ ${{ secrets.GCP_AR_PARABOL_DEV }}:${{github.event.pull_request.head.sha}} \ ${{ secrets.GCP_AR_PARABOL }}:v${{ env.ACTION_VERSION }} - - name: Bump version in GitLab + - name: Push to Staging Server run: | - curl "https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/repository/commits" \ + COMMIT_ID=$(curl "https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/repository/commits" \ --request POST \ --header 'PRIVATE-TOKEN: ${{ secrets.GITLAB_API_TOKEN }}' \ --form "branch=main" \ @@ -49,4 +49,34 @@ jobs: global: image: - tag: *applicationVersion" + tag: *applicationVersion" | jq .id) + PIPELINES=$(curl "https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/pipelines" \ + --header 'PRIVATE-TOKEN: ${{ secrets.GITLAB_API_TOKEN }}') + PIPELINE_ID=$(echo $PIPELINES | jq ".[] | select(.sha == \"$COMMIT_ID\")" | jq .id) + JOBS=$(curl "https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/pipelines/$PIPELINE_ID/jobs" \ + --header 'PRIVATE-TOKEN: ${{ secrets.GITLAB_API_TOKEN }}') + JOB_ID=$(echo $JOBS | jq '.[] | select(.name == "staging-release")' | jq .id) + curl "https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/jobs/$JOB_ID/play" \ + --request POST \ + --header 'PRIVATE-TOKEN: ${{ secrets.GITLAB_API_TOKEN }}' + echo "JOB_ID=${JOB_ID}" >> $GITHUB_ENV + sleep 90 + - name: Open PR to Push to Prod + run: | + TEMPLATE=$(tail -n +12 .github/ISSUE_TEMPLATE/release_test.md) + CHANGES=$(perl -0777ne 'print "$1\n" and exit if m/\n##\s[^\n]*\n+(.*?\n)##?\s|$/gs;' CHANGELOG.md) + BODY="${TEMPLATE}\n\n\n${CHANGES}" + gh pr create \ + --assignee ${{ github.actor }} + --base production + --title "chore(release): Test v${{ env.ACTION_VERSION }}" + --body "$BODY" + - name: Poll Staging Release + uses: artiz/poll-endpoint@1.0.2 + with: + url: https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/jobs/${{ env.JOB_ID }} + method: GET + expect-status: 200 + expect-response-regex: '"status":"success"' + timeout: 120000 + interval: 3000 From 6023d2b7ad1ebda44c436b6eb7ea66ab29faffc2 Mon Sep 17 00:00:00 2001 From: Matt Krick Date: Thu, 9 Nov 2023 15:09:34 -0800 Subject: [PATCH 2/5] chore: push to prod on PR merge Signed-off-by: Matt Krick --- .github/workflows/release-to-prod.yml | 35 +++++++++++++++++++++++++++ .github/workflows/release.yml | 10 ++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release-to-prod.yml diff --git a/.github/workflows/release-to-prod.yml b/.github/workflows/release-to-prod.yml new file mode 100644 index 00000000000..e338cba206e --- /dev/null +++ b/.github/workflows/release-to-prod.yml @@ -0,0 +1,35 @@ +name: Release +on: + pull_request: + branches: + - production + types: [closed] +jobs: + release-to-prod: + if: ${{ github.event.pull_request.merged == true }} + runs-on: ubuntu-latest + permissions: + contents: "read" + id-token: "write" + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Push to Production Server + run: | + JOB_ID=$(echo ${{ github.event.pull_request.body}} | perl -ne 'print "$1\n" and exit if m/^Production Job Id:\s(\w+)/;') + echo "JOB_ID=${JOB_ID}" >> $GITHUB_ENV + curl "https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/jobs/$JOB_ID/play" \ + --request POST \ + --header 'PRIVATE-TOKEN: ${{ secrets.GITLAB_API_TOKEN }}' + sleep 90 + + - name: Poll Production Release + uses: artiz/poll-endpoint@1.0.2 + with: + url: https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/jobs/${{ env.JOB_ID }} + method: GET + expect-status: 200 + expect-response-regex: '"status":"success"' + timeout: 120000 + interval: 3000 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4beb0eafede..acd4677ad3d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -35,6 +35,9 @@ jobs: ${{ secrets.GCP_AR_PARABOL_DEV }}:${{github.event.pull_request.head.sha}} \ ${{ secrets.GCP_AR_PARABOL }}:v${{ env.ACTION_VERSION }} - name: Push to Staging Server + env: + STAGING_JOB: staging-release + PRODUCTION_JOB: prod-release run: | COMMIT_ID=$(curl "https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/repository/commits" \ --request POST \ @@ -55,17 +58,20 @@ jobs: PIPELINE_ID=$(echo $PIPELINES | jq ".[] | select(.sha == \"$COMMIT_ID\")" | jq .id) JOBS=$(curl "https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/pipelines/$PIPELINE_ID/jobs" \ --header 'PRIVATE-TOKEN: ${{ secrets.GITLAB_API_TOKEN }}') - JOB_ID=$(echo $JOBS | jq '.[] | select(.name == "staging-release")' | jq .id) + JOB_ID=$(echo $JOBS | jq '.[] | select(.name == "${{ env.STAGING_JOB }}")' | jq .id) curl "https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/jobs/$JOB_ID/play" \ --request POST \ --header 'PRIVATE-TOKEN: ${{ secrets.GITLAB_API_TOKEN }}' + PROD_JOB_ID=$(echo $JOBS | jq '.[] | select(.name == "${{ env.PRODUCTION_JOB}}")' | jq .id) echo "JOB_ID=${JOB_ID}" >> $GITHUB_ENV + echo "PROD_JOB_ID=${PROD_JOB_ID}" >> $GITHUB_ENV sleep 90 - name: Open PR to Push to Prod run: | + BACKLINK="Production Job Id: $PROD_JOB_ID\nStaging Job Id: $JOB_ID" TEMPLATE=$(tail -n +12 .github/ISSUE_TEMPLATE/release_test.md) CHANGES=$(perl -0777ne 'print "$1\n" and exit if m/\n##\s[^\n]*\n+(.*?\n)##?\s|$/gs;' CHANGELOG.md) - BODY="${TEMPLATE}\n\n\n${CHANGES}" + BODY="${BACKLINK}\n\n${TEMPLATE}\n\n\n${CHANGES}" gh pr create \ --assignee ${{ github.actor }} --base production From b9242fcd47e60c772072c9e4d2435ca8725737a4 Mon Sep 17 00:00:00 2001 From: Matt Krick Date: Thu, 9 Nov 2023 15:30:12 -0800 Subject: [PATCH 3/5] fix: naming Signed-off-by: Matt Krick --- .github/workflows/release-please.yml | 2 +- .github/workflows/release-to-prod.yml | 6 ++---- .github/workflows/{release.yml => release-to-staging.yml} | 3 +-- 3 files changed, 4 insertions(+), 7 deletions(-) rename .github/workflows/{release.yml => release-to-staging.yml} (99%) diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index ec769544ae4..52770bd9800 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -19,4 +19,4 @@ jobs: command: manifest default-branch: ${{ github.ref_name}} release-type: node - token: ${{ steps.generate_token.outputs.token }} \ No newline at end of file + token: ${{ steps.generate_token.outputs.token }} diff --git a/.github/workflows/release-to-prod.yml b/.github/workflows/release-to-prod.yml index e338cba206e..3d0700ed7fe 100644 --- a/.github/workflows/release-to-prod.yml +++ b/.github/workflows/release-to-prod.yml @@ -1,11 +1,11 @@ -name: Release +name: Release to Production on: pull_request: branches: - production types: [closed] jobs: - release-to-prod: + release: if: ${{ github.event.pull_request.merged == true }} runs-on: ubuntu-latest permissions: @@ -14,7 +14,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 - - name: Push to Production Server run: | JOB_ID=$(echo ${{ github.event.pull_request.body}} | perl -ne 'print "$1\n" and exit if m/^Production Job Id:\s(\w+)/;') @@ -23,7 +22,6 @@ jobs: --request POST \ --header 'PRIVATE-TOKEN: ${{ secrets.GITLAB_API_TOKEN }}' sleep 90 - - name: Poll Production Release uses: artiz/poll-endpoint@1.0.2 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release-to-staging.yml similarity index 99% rename from .github/workflows/release.yml rename to .github/workflows/release-to-staging.yml index acd4677ad3d..ced31bbf06b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release-to-staging.yml @@ -1,4 +1,4 @@ -name: Release +name: Release to Staging on: pull_request: branches: @@ -19,7 +19,6 @@ jobs: run: | ACTION_VERSION=$(grep '"version":' package.json | cut -d\" -f4) echo "ACTION_VERSION=${ACTION_VERSION}" >> $GITHUB_ENV - - id: "auth" name: "Authenticate to Google Cloud" uses: "google-github-actions/auth@v1" From 84482a499edfde6de17a2dac5056896fd2be336e Mon Sep 17 00:00:00 2001 From: Matt Krick Date: Wed, 13 Dec 2023 16:19:33 -0800 Subject: [PATCH 4/5] fix: hotfix branch name prefix Signed-off-by: Matt Krick --- .github/workflows/release-to-prod.yml | 1 - .github/workflows/release-to-staging.yml | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/release-to-prod.yml b/.github/workflows/release-to-prod.yml index 3d0700ed7fe..ee44ca23312 100644 --- a/.github/workflows/release-to-prod.yml +++ b/.github/workflows/release-to-prod.yml @@ -21,7 +21,6 @@ jobs: curl "https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/jobs/$JOB_ID/play" \ --request POST \ --header 'PRIVATE-TOKEN: ${{ secrets.GITLAB_API_TOKEN }}' - sleep 90 - name: Poll Production Release uses: artiz/poll-endpoint@1.0.2 with: diff --git a/.github/workflows/release-to-staging.yml b/.github/workflows/release-to-staging.yml index ced31bbf06b..d8081321d97 100644 --- a/.github/workflows/release-to-staging.yml +++ b/.github/workflows/release-to-staging.yml @@ -3,7 +3,7 @@ on: pull_request: branches: - master - - hotfix-* + - hotfix** types: [closed] jobs: release: @@ -64,7 +64,6 @@ jobs: PROD_JOB_ID=$(echo $JOBS | jq '.[] | select(.name == "${{ env.PRODUCTION_JOB}}")' | jq .id) echo "JOB_ID=${JOB_ID}" >> $GITHUB_ENV echo "PROD_JOB_ID=${PROD_JOB_ID}" >> $GITHUB_ENV - sleep 90 - name: Open PR to Push to Prod run: | BACKLINK="Production Job Id: $PROD_JOB_ID\nStaging Job Id: $JOB_ID" From ff22016c5497f06cc71b692a1413aab2d6014f18 Mon Sep 17 00:00:00 2001 From: Matt Krick Date: Tue, 19 Dec 2023 12:32:48 -0800 Subject: [PATCH 5/5] fix: poll for pipeline in staging Signed-off-by: Matt Krick --- .github/workflows/release-to-staging.yml | 42 +++++++++++++++--------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/.github/workflows/release-to-staging.yml b/.github/workflows/release-to-staging.yml index d8081321d97..05087648370 100644 --- a/.github/workflows/release-to-staging.yml +++ b/.github/workflows/release-to-staging.yml @@ -33,10 +33,7 @@ jobs: gcloud container images add-tag -q \ ${{ secrets.GCP_AR_PARABOL_DEV }}:${{github.event.pull_request.head.sha}} \ ${{ secrets.GCP_AR_PARABOL }}:v${{ env.ACTION_VERSION }} - - name: Push to Staging Server - env: - STAGING_JOB: staging-release - PRODUCTION_JOB: prod-release + - name: Push Version Commit to Staging Server run: | COMMIT_ID=$(curl "https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/repository/commits" \ --request POST \ @@ -52,18 +49,31 @@ jobs: global: image: tag: *applicationVersion" | jq .id) - PIPELINES=$(curl "https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/pipelines" \ - --header 'PRIVATE-TOKEN: ${{ secrets.GITLAB_API_TOKEN }}') - PIPELINE_ID=$(echo $PIPELINES | jq ".[] | select(.sha == \"$COMMIT_ID\")" | jq .id) - JOBS=$(curl "https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/pipelines/$PIPELINE_ID/jobs" \ - --header 'PRIVATE-TOKEN: ${{ secrets.GITLAB_API_TOKEN }}') - JOB_ID=$(echo $JOBS | jq '.[] | select(.name == "${{ env.STAGING_JOB }}")' | jq .id) - curl "https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/jobs/$JOB_ID/play" \ - --request POST \ - --header 'PRIVATE-TOKEN: ${{ secrets.GITLAB_API_TOKEN }}' - PROD_JOB_ID=$(echo $JOBS | jq '.[] | select(.name == "${{ env.PRODUCTION_JOB}}")' | jq .id) - echo "JOB_ID=${JOB_ID}" >> $GITHUB_ENV - echo "PROD_JOB_ID=${PROD_JOB_ID}" >> $GITHUB_ENV + echo "COMMIT_ID=${COMMIT_ID}" >> $GITHUB_ENV + - name: Poll for new pipeline + env: + STAGING_JOB: staging-release + PRODUCTION_JOB: prod-release + uses: nick-fields/retry@v2 + with: + timeout_minutes: 10 + max_attempts: 100 + retry_wait_seconds: 5 + command: | + echo ${{ env.COMMIT_ID }} + PIPELINES=$(curl "https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/pipelines" \ + --header 'PRIVATE-TOKEN: ${{ secrets.GITLAB_API_TOKEN }}') + PIPELINE_ID=$(echo $PIPELINES | jq ".[] | select(.sha == \"${{ env.COMMIT_ID }}\")" | jq .id) + [ -z "$PIPELINE_ID" ] && exit 1 + JOBS=$(curl "https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/pipelines/$PIPELINE_ID/jobs" \ + --header 'PRIVATE-TOKEN: ${{ secrets.GITLAB_API_TOKEN }}') + JOB_ID=$(echo $JOBS | jq '.[] | select(.name == "${{ env.STAGING_JOB }}")' | jq .id) + curl "https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/jobs/$JOB_ID/play" \ + --request POST \ + --header 'PRIVATE-TOKEN: ${{ secrets.GITLAB_API_TOKEN }}' + PROD_JOB_ID=$(echo $JOBS | jq '.[] | select(.name == "${{ env.PRODUCTION_JOB}}")' | jq .id) + echo "JOB_ID=${JOB_ID}" >> $GITHUB_ENV + echo "PROD_JOB_ID=${PROD_JOB_ID}" >> $GITHUB_ENV - name: Open PR to Push to Prod run: | BACKLINK="Production Job Id: $PROD_JOB_ID\nStaging Job Id: $JOB_ID"