Skip to content

Commit

Permalink
fix: release to staging debug #4 (#9315)
Browse files Browse the repository at this point in the history
* fix: add pr write permission to CI

Signed-off-by: Matt Krick <matt.krick@gmail.com>

* fix: release-staging handle async job creation

Signed-off-by: Matt Krick <matt.krick@gmail.com>

---------

Signed-off-by: Matt Krick <matt.krick@gmail.com>
  • Loading branch information
mattkrick committed Jan 9, 2024
1 parent 333454a commit ba32950
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions .github/workflows/release-to-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,32 @@ jobs:
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: Push to staging
uses: nick-fields/retry@v2
with:
timeout_minutes: 1
max_attempts: 20
retry_wait_seconds: 5
# If the job isn't created yet, will return {"message":"400 Bad request - Unplayable Job"}
command: |
RES=$(curl "https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/jobs/${{ env.JOB_ID }}/play" \
--request POST \
--header 'PRIVATE-TOKEN: ${{ secrets.GITLAB_API_TOKEN }}')
JOB_ID_DONE=$(echo $RES | jq .id)
[ -z "$JOB_ID_DONE" ] && exit 1
- name: Open PR to Push to Prod
env:
GH_TOKEN: ${{ github.token }}
# gh cli does not interpret \n, so we first write to a file
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="${BACKLINK}\n\n${TEMPLATE}\n\n\n${CHANGES}"
echo -e "${BACKLINK}\n\n${TEMPLATE}\n\n\n${CHANGES}" > BODY
export BODY=$(cat BODY)
gh pr create \
--assignee ${{ github.actor }} \
--base production \
Expand All @@ -91,7 +103,7 @@ jobs:
- 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 }}
url: https://gitlab.com/api/v4/projects/${{ vars.GITLAB_PROJECT_ID }}/jobs/${{ env.JOB_ID }}?access_token=${{ secrets.GITLAB_API_TOKEN }}
method: GET
expect-status: 200
expect-response-regex: '"status":"success"'
Expand Down

0 comments on commit ba32950

Please sign in to comment.