Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: release to staging debug #4 #9315

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions .github/workflows/release-to-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
permissions:
contents: "read"
id-token: "write"
pull-requests: "write"
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -68,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 @@ -90,7 +103,7 @@ jobs:
- name: Poll Staging Release
uses: artiz/[email protected]
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
Loading