.github/workflows/default.yaml #191
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' | |
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: | |
cdk-deploy: | |
environment: test | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: force-rollback | |
run: | | |
echo "Forced rollback" >> $GITHUB_STEP_SUMMARY | |
false | |
if: ${{ inputs.force_rollback }} | |
- name: check-aws-account-id | |
uses: actions/github-script@v7.0.1 | |
with: | |
script: | | |
if ("${{ vars.AWS_ACCOUNT_ID }}" == "") { | |
core.setFailed("AWS_ACCOUNT_ID is unspecified") | |
} else { | |
core.info("AWS_ACCOUNT_ID is ${{ vars.AWS_ACCOUNT_ID }}") | |
} | |
- 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 aws-cdk@2.140.0 | |
- name: checkout | |
uses: actions/checkout@v4.1.5 | |
- name: setup-java | |
uses: hertzsprung/binsley/actions/setup-java@main | |
- name: cdk-permissions-broadening | |
id: cdk-permissions-broadening | |
run: cdk diff --security-only --fail Binsley > cdk-diff-security | |
continue-on-error: true | |
- name: cdk-diff-security | |
id: cdk-diff-security | |
uses: actions/upload-artifact@v4.3.3 | |
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 Binsley | |
if: ${{ !cancelled() && (steps.cdk-permissions-broadening.outcome == 'success' || steps.cdk-permissions-broadening.outcome == 'failure') }} | |
test: | |
uses: ./.github/workflows/test.yaml | |
needs: cdk-deploy | |
with: | |
environment: test | |
rollback: | |
runs-on: ubuntu-22.04 | |
needs: [cdk-deploy, test] | |
if: ${{ !cancelled() && contains(needs.*.result, 'failure') && !inputs.prevent_rollback }} | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4.1.5 | |
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 'hertzsprung+binsley@users.noreply.github.com' | |
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 }} |