Created
March 27, 2023 20:33
-
-
Save mtliendo/5eb355dbb1155ddd2c4756130a89270e to your computer and use it in GitHub Desktop.
GitHub action flow to deploy multi-env cdk app that then deploy an Amplify frontend
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
name: Deploy CDK Project | |
on: | |
push: | |
branches: | |
- develop | |
pull_request: | |
branches: | |
- main | |
types: | |
- closed | |
jobs: | |
aws_cdk: | |
if: github.event.pull_request.merged == true || github.event_name == 'push' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v3 | |
- uses: actions/setup-node@v2 | |
with: | |
node-version: '18' | |
- run: npm install | |
- name: cdk diff | |
uses: youyo/aws-cdk-github-actions@v2 | |
with: | |
cdk_subcommand: 'diff' | |
actions_comment: true | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: cdk deploy | |
uses: youyo/aws-cdk-github-actions@v2 | |
with: | |
cdk_subcommand: 'deploy' | |
cdk_stack: '*' | |
cdk_args: '--require-approval never' | |
actions_comment: false | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- name: Trigger Amplify Build (optional) | |
run: | | |
if [ "${{ github.event_name }}" == "push" ] && [ "${{ github.ref }}" == "refs/heads/develop" ]; then | |
WEBHOOK_URL="${{ secrets.DEVELOP_WEBHOOK_URL }}" | |
elif [ "${{ github.event_name }}" == "pull_request" ] && [ "${{ github.event.pull_request.merged }}" == "true" ]; then | |
WEBHOOK_URL="${{ secrets.MAIN_WEBHOOK_URL }}" | |
fi | |
if [ ! -z "${WEBHOOK_URL}" ]; then | |
curl -X POST -d {} "${WEBHOOK_URL}" -H "Content-Type:application/json" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment