Skip to content

Commit

Permalink
chore: keep release process in GitHub (#9165)
Browse files Browse the repository at this point in the history
* chore: release to staging from github

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

* chore: push to prod on PR merge

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

* fix: naming

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

* fix: hotfix branch name prefix

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

* fix: poll for pipeline in staging

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

---------

Signed-off-by: Matt Krick <matt.krick@gmail.com>
  • Loading branch information
mattkrick committed Dec 20, 2023
1 parent 86db0dc commit b5a7e58
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 52 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/release-to-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Release to Production
on:
pull_request:
branches:
- production
types: [closed]
jobs:
release:
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 }}'
- 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
96 changes: 96 additions & 0 deletions .github/workflows/release-to-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Release to Staging
on:
pull_request:
branches:
- master
- hotfix**
types: [closed]
jobs:
release:
if: ${{ github.event.pull_request.merged == true && startsWith(github.head_ref, 'release-please--') }}
runs-on: ubuntu-latest
permissions:
contents: "read"
id-token: "write"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup environment variables
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"
with:
token_format: "access_token"
workload_identity_provider: ${{ secrets.GCP_WI_PROVIDER_NAME }}
service_account: ${{ secrets.GCP_SA_EMAIL }}
- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v1"
- name: "Tag image with production version"
run: |-
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 Version Commit to Staging Server
run: |
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" \
--form "commit_message=release v${{ env.ACTION_VERSION }}" \
--form "actions[][action]=update" \
--form "actions[][file_path]=version.yaml" \
--form "actions[][content]=
# Change it to use a valid docker tag, which are the same of the GitHub tags. Ex: v6.110.0
applicationVersion: &applicationVersion v${{ env.ACTION_VERSION }}
global:
image:
tag: *applicationVersion" | jq .id)
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"
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}"
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
52 changes: 0 additions & 52 deletions .github/workflows/release.yml

This file was deleted.

0 comments on commit b5a7e58

Please sign in to comment.