.github/workflows/default.yaml #281
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
workflow_dispatch: | |
inputs: | |
force_rollback: | |
type: boolean | |
required: true | |
default: false | |
description: 'Force an immediate rollback' | |
prevent_rollback: | |
type: boolean | |
required: true | |
default: false | |
description: 'Prevent rollback on workflow failure' | |
force_unconditional_execution: | |
type: boolean | |
required: true | |
default: false | |
description: 'Force unconditional execution of jobs without Gradle caching' | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- 'decisions/**' | |
- '.github/workflows/*.manual-test.yaml' | |
schedule: | |
- cron: '30 7 * * 0' | |
permissions: | |
id-token: write | |
checks: write | |
contents: write # for git rollback | |
actions: write # for rollback workflow run | |
concurrency: | |
group: default | |
cancel-in-progress: false | |
jobs: | |
force-rollback: | |
runs-on: ubuntu-22.04 | |
if: ${{ inputs.force_rollback }} | |
steps: | |
- name: force-rollback | |
run: | | |
echo "Forced rollback" >> $GITHUB_STEP_SUMMARY | |
false | |
changes: | |
runs-on: ubuntu-22.04 | |
outputs: | |
stacks: ${{ steps.wildcard-stacks.outputs.stacks }}${{ steps.all-stacks.outputs.stacks }} | |
steps: | |
- name: checkout | |
uses: actions/[email protected] | |
- id: filter | |
uses: dorny/[email protected] | |
with: | |
filters: | | |
WorkflowMetrics: WorkflowMetrics/** | |
- id: wildcard-stacks | |
run: echo "stacks=$(jq -r '. | map(. + "*") | @sh' <<< '${{ steps.filter.outputs.changes }}')" >> $GITHUB_OUTPUT | |
if: ${{ !inputs.force_unconditional_execution }} | |
- id: all-stacks | |
run: echo "stacks='WorkflowMetrics*'" >> $GITHUB_OUTPUT | |
if: ${{ inputs.force_unconditional_execution }} | |
cdk-deploy: | |
environment: test | |
runs-on: ubuntu-22.04 | |
needs: [force-rollback, changes] | |
if: ${{ !cancelled() && needs.force-rollback.result == 'skipped' && (inputs.force_unconditional_execution || needs.changes.outputs.stacks != '')}} | |
steps: | |
- name: aws-assume-role | |
uses: hertzsprung/binsley/actions/aws-assume-role@main | |
with: | |
account-id: ${{ vars.AWS_ACCOUNT_ID }} | |
- name: npm-install-cdk | |
run: npm install -g [email protected] | |
- name: checkout | |
uses: actions/[email protected] | |
- name: setup-java | |
uses: hertzsprung/binsley/actions/setup-java@main | |
with: | |
force_unconditional_execution: ${{ inputs.force_unconditional_execution }} | |
- name: cdk-permissions-broadening | |
id: cdk-permissions-broadening | |
run: cdk diff --security-only --fail ${{ needs.changes.outputs.stacks }} > cdk-diff-security | |
continue-on-error: true | |
- name: cdk-diff-security | |
id: cdk-diff-security | |
uses: actions/[email protected] | |
if: ${{ !cancelled() && steps.cdk-permissions-broadening.outcome == 'failure' }} | |
with: | |
name: cdk-diff-security | |
path: cdk-diff-security | |
- name: cdk-deploy | |
run: cdk deploy --require-approval never ${{ needs.changes.outputs.stacks }} | |
if: ${{ !cancelled() && (steps.cdk-permissions-broadening.outcome == 'success' || steps.cdk-permissions-broadening.outcome == 'failure') }} | |
test: | |
uses: ./.github/workflows/test.yaml | |
needs: cdk-deploy | |
if: always() && !cancelled() && !failure() # https://github.com/actions/runner/issues/491#issuecomment-1507495166 | |
with: | |
environment: test | |
rollback: | |
runs-on: ubuntu-22.04 | |
needs: [force-rollback, cdk-deploy, test] | |
if: ${{ always() && !cancelled() && contains(needs.*.result, 'failure') && !inputs.prevent_rollback }} | |
steps: | |
- name: checkout | |
uses: actions/[email protected] | |
with: | |
fetch-depth: 2 | |
token: ${{ secrets.ROLLBACK_TOKEN }} | |
- name: git-rollback | |
shell: bash | |
run: | | |
branch_name="rollback-$(printf '%(%Y-%m-%d_%H.%M.%S)T\n')" | |
git config user.name 'Binsley GitHub Actions' | |
git config user.email '[email protected]' | |
git branch $branch_name | |
git checkout main | |
git reset --hard HEAD~1 | |
git push origin main --force | |
git push --set-upstream origin $branch_name | |
- name: gh-workflow-run | |
shell: bash | |
run: gh workflow run default.yaml -f prevent_rollback=true | |
env: | |
GH_TOKEN: ${{ github.token }} |