I'm making some CICD and I'm using github labels to demonstrate intent to deploy into production.
So in my github actions, I have some boolean that checks if there to be a label 'deploy-prd'. There's a check for pull request review with status approved.
But... if a user commits some code after it has been approved, then the approval is still valid in the eyes of the cicd.
When the user adds the label 'deploy-prd' and the cicd runs, it just sees that there is an existing approval and that there is a 'deploy-prd' tag and deploys the newly committed and unapproved code to prod. Is there a way to compare the latest commit to the timestamp of the approval? Or is there another logic I should follow?
The current soln is making deploy-prd only accessible by admins.. which is meh at best.
Also: Would a synchronize trigger to remove existing approvals be a good idea in terms of performance, execution limits, and future technical debt? Or would this cause more headache down the line?
Below are some key excerpts from the cicd workflows.
Pull Request Trigger label flow
name: 'Label Trigger'
on:
pull_request:
types: [labeled]
jobs:
gcp-pull-request-ci:
if: github.event.review.state == 'approved'
uses: ${{github.repository}}/github-actions/.github/workflows/gcp-label-ci.yaml@master
with:
repository: ${{ github.repository }}
deploy-prod: ${{ contains( github.event.pull_request.labels.*.name, 'deploy-prd') }}
pull-request-number: ${{ github.event.pull_request.number }}
Reusable workflow job logic
check-for-deploy-prd:
needs: deploy-stg
if: inputs.deploy-prod
outputs:
data: ${{ steps.get_approved_prs.outputs.data }}
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
# Query approval status
- uses: octokit/request-action@v2.x
id: get_approved_prs
with:
route: GET /repos/${{inputs.repository}}/pulls/${{inputs.pull-request-number}}/reviews
env:
GITHUB_TOKEN: ${{ secrets.token }}
deploy-prod:
needs: check-for-deploy-prd
if: contains(fromJSON(needs.check-for-deploy-prd.outputs.data).*.state,'APPROVED')