Skip to content

Adding Cloudwatch Dashboard to help monitor state of each leaf stack, and debug problems #27

Adding Cloudwatch Dashboard to help monitor state of each leaf stack, and debug problems

Adding Cloudwatch Dashboard to help monitor state of each leaf stack, and debug problems #27

name: Main Pipeline - CDK Actions
on:
workflow_dispatch: {}
pull_request:
types:
# For Synth
- opened
- reopened
- synchronize
- edited
# For Deploy
- closed
# NOTE: You CAN'T have the `paths` key here!!
# if you do, and the PR doesn't trigger this,
# you won't be able to merge it.
# (Apart of dependabot updates. See the
# README.md in this dir for more details...)
branches:
- main
#### Overall Strategy:
# If Open a PR: Make sure everything can Synth (No deploy)
# If Merge a PR: Deploy to your account (No synth, it just passed)
# If workflow_dispatch: Synth first, then deploy if pass
env:
EXAMPLES_PATH: ./Examples # No trailing slash plz!
jobs:
setup-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.setup-matrix.outputs.example-config-files }}
steps:
- uses: actions/checkout@v4
- name: Setup matrix
id: setup-matrix
run: |
file_list=$(cd "${{ env.EXAMPLES_PATH }}" && find * -regextype egrep -regex '.*ya?ml$')
json_list=$(echo $file_list | jq --raw-input --compact-output 'split(" ")')
echo "example-config-files=$json_list" >> "$GITHUB_OUTPUT"
cdk-synth:
if: ( github.event_name == 'pull_request' && github.event.action != 'closed' ) ||
( github.event_name == 'workflow_dispatch' )
runs-on: ubuntu-latest
needs:
- setup-matrix
strategy:
matrix:
example-config: ${{ fromJson(needs.setup-matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: ./.github/workflows/composite-setup-python
- name: Install NPM Stuff (aws-cdk)
run: |
### Setup NPM for non-root:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo "PATH=~/.npm-global/bin:$PATH" >> "$GITHUB_ENV"
### Update:
make update-npm
- name: "Synthesize: ${{ matrix.example-config }}"
run: make cdk-synth config-file="${{ env.EXAMPLES_PATH }}/${{ matrix.example-config }}"
cdk-deploy:
## If the PR is merged, or if we manually trigger it (MAIN ONLY):
# !failure() && !cancelled(): Let it check the 'if' block here, even if the last job skipped.
if: |
!failure() && !cancelled() && (
( github.event_name == 'pull_request' && github.event.pull_request.merged ) ||
( github.event_name == 'workflow_dispatch' )
)
runs-on: ubuntu-latest
needs:
- setup-matrix
- cdk-synth
steps:
# Moved this check away from the job-level 'if', so it actually fails if you're
# not on main and it's easier to see.
- name: Fail if not 'main' (else skips this step)
# Yes the pull_request line is redundant with the 'branch' trigger at the top of the
# file, but better safe than sorry. Keeps the logic uniform with workflow_dispatch too.
if: ( github.event_name == 'pull_request' && github.base_ref != 'main' ) ||
( github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/main' )
run: exit -1
# TODO: First have it deploy the base stack, THEN matrix out to all the leafs.
# - If we add resources to base, this will let the deployment succeed and leafs use it.
# - Also each leaf should check against a "REPOSITORY VARIABLE" to see if it should run.
# (Check *there* so forks can have their own list, and not conflict with eachother.
# Make sure to update docs w/ how it should be formated too).
# There might be a chance the matrix leafs will trip on eachother, but hopefully deploying
# base first will mean no changes will happen. It'd be so much cleaner if we can do it, so
# I think I'll try it first.
- name: TODO
run: echo TODO