Merge pull request #592 from NASA-IMPACT/staging-cloudfront-deploy #171
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 Staging | |
on: | |
push: | |
branches: | |
- 'develop' | |
env: | |
NODE_VERSION: 14 | |
DOMAIN_STAGING: https://d3p0lkft682kz.cloudfront.net | |
DEPLOY_BUCKET_STAGING: nasa-apt-v5-staging | |
DEPLOY_BUCKET_STAGING_REGION: us-east-1 | |
STAGING_CLOUDFRONT_DISTRIBUTION_ID: E2XF0H60GJHF3E | |
OIDC_ROLE: arn:aws:iam::552819999234:role/nasa-apt-frontend-ci | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Cancel Previous Runs | |
uses: styfle/cancel-workflow-action@0.12.0 | |
with: | |
access_token: ${{ github.token }} | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Use Node.js ${{ env.NODE_VERSION }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Cache dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ~/.yarn | |
key: ${{ runner.OS }}-node-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.OS }}-node- | |
- name: Install dependencies | |
run: yarn install --frozen-lockfile | |
- name: Build staging | |
run: PUBLIC_URL="${{ env.DOMAIN_STAGING }}" yarn stage | |
- name: Configure AWS credentials using OIDC | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ env.OIDC_ROLE }} | |
aws-region: ${{ env.DEPLOY_BUCKET_STAGING_REGION }} | |
- name: Deploy to S3 | |
run: | | |
aws s3 sync ./dist s3://${{ env.DEPLOY_BUCKET_STAGING }} \ | |
--delete \ | |
--follow-symlinks | |
- name: Invalidate CloudFront cache | |
run: | | |
aws cloudfront create-invalidation \ | |
--distribution-id ${{ env.STAGING_CLOUDFRONT_DISTRIBUTION_ID }} \ | |
--paths "/*" |