Skip to content

Deploying to CloudFront #6

Deploying to CloudFront

Deploying to CloudFront #6

Workflow file for this run

name: Deploy
on:
push:
branches: [develop]
workflow_dispatch:
run-name: Deploying to CloudFront
permissions:
id-token: write
contents: read
jobs:
build-and-test:
name: Build and Test
uses: ./.github/workflows/build-and-test.yaml
with:
stage: true
deploy:
needs: build-and-test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-1
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
role-session-name: ${{ secrets.AWS_ROLE_SESSION_NAME }}
promote-approval:
if: |
contains(fromJson('["skipped", "success"]'), needs.deploy.result) &&
!contains(needs.*.result, 'failure')
needs: [build-and-test, deploy]
runs-on: ubuntu-latest
environment:
name: promote-approval
steps:
- name: Awaiting Approval
run: echo "Please approve the deployment by commenting 'approve' on this issue."
promote:
timeout-minutes: 10
if: |
always() &&
contains(fromJson('["skipped", "success"]'), needs.promote-approval.result) &&
!contains(needs.*.result, 'failure')
needs: [build-and-test, deploy, promote-approval]
runs-on: ubuntu-latest
steps:
- name: Promote Staging to Production
run: |
STAGING_CONFIG=$(aws cloudfront get-distribution-config --id ${{ secrets.AWS_CLOUDFRONT_STAGE_DISTRIBUTION_ID }} --output json)
ETAG=$(echo $STAGING_CONFIG | jq -r '.ETag')
DISTRIBUTION_CONFIG=$(echo $STAGING_CONFIG | jq '.DistributionConfig')
aws cloudfront update-distribution --id ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }} \
--distribution-config "$DISTRIBUTION_CONFIG" \
--if-match $ETAG