Skip to content

Deploy Production Environments #7

Deploy Production Environments

Deploy Production Environments #7

Workflow file for this run

name: Deploy Production Environments
on:
workflow_run:
workflows:
- Build and Push Docker Image
types:
- completed
concurrency:
group: deploy-production
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
jobs:
deploy-production:
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' }}
runs-on: ubuntu-latest
steps:
- name: Create GitHub App token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.DEPLOYMENT_APP_ID }}
private-key: ${{ secrets.DEPLOYMENT_APP_PRIVATE_KEY }}
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: Set image tag
id: vars
env:
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: echo "image_tag=sha-${HEAD_SHA::7}" >> "$GITHUB_OUTPUT"
- name: Update mainnet indexer image tag
uses: mikefarah/yq@v4
env:
IMAGE_TAG: ${{ steps.vars.outputs.image_tag }}
with:
cmd: yq -i '.indexer.image.tag = strenv(IMAGE_TAG)' environments/main.yaml
- name: Update mainnet query image tag
uses: mikefarah/yq@v4
env:
IMAGE_TAG: ${{ steps.vars.outputs.image_tag }}
with:
cmd: yq -i '.query.image.tag = strenv(IMAGE_TAG)' environments/main.yaml
- name: Update testnet indexer image tag
uses: mikefarah/yq@v4
env:
IMAGE_TAG: ${{ steps.vars.outputs.image_tag }}
with:
cmd: yq -i '.indexer.image.tag = strenv(IMAGE_TAG)' environments/test.yaml
- name: Update testnet query image tag
uses: mikefarah/yq@v4
env:
IMAGE_TAG: ${{ steps.vars.outputs.image_tag }}
with:
cmd: yq -i '.query.image.tag = strenv(IMAGE_TAG)' environments/test.yaml
- name: Open deployment PR
id: cpr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ steps.app-token.outputs.token }}
author: "api-gitops[bot] <${{ secrets.DEPLOYMENT_APP_ID }}+api-gitops[bot]@users.noreply.github.com>"
branch: deployment
delete-branch: true
base: main
commit-message: "chore(cd): update production env tags to ${{ steps.vars.outputs.image_tag }}"
title: "chore(cd): update deployment env tags"
body: |
Automated environment tag update for main and test.
labels: |
deployment
add-paths: |
environments/main.yaml
environments/test.yaml
- name: Enable auto-merge (squash)
if: ${{ steps.cpr.outputs.pull-request-number != '' }}
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: gh pr merge ${{ steps.cpr.outputs.pull-request-number }} --auto --squash