Skip to content

Deploy Nevus App

Deploy Nevus App #5

name: Deploy Nevus Tool Frontend
on:
workflow_dispatch:
inputs:
tier:
description: "Deploy environment"
required: true
default: "dev"
type: choice
options:
- dev
- qa
- stage
- prod
permissions:
id-token: write
contents: read
jobs:
deploy-cloudfront:
timeout-minutes: 10
runs-on: ubuntu-latest
environment: ${{ inputs.tier }}
env:
TIER: ${{ inputs.tier }}
APP: nevustool
AWS_REGION: us-east-1
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v5.1.0
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/github-actions-cicd
role-session-name: ${{ env.TIER }}-nevustool-frontend-${{ github.ref_name }}
aws-region: ${{ env.AWS_REGION }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: client/package-lock.json
- name: Build frontend assets
run: |
cd client
npm install
npm run build
env:
REACT_APP_PROJECT: ${{ env.APP }}
- name: Copy build assets to S3
run: |
STACK_NAME="${{ inputs.tier }}-${{ env.APP }}-cloudfront-s3"
S3_BUCKET=$(aws cloudformation describe-stacks \
--stack-name "$STACK_NAME" \
--query "Stacks[0].Outputs[?OutputKey=='BucketName'].OutputValue" \
--output text)
if [ -z "$S3_BUCKET" ] || [ "$S3_BUCKET" = "None" ]; then
echo "❌ S3 Bucket name not found. Redeploy CloudFront stack with BucketName output."
exit 1
fi
echo "✅ Deploying to S3 bucket: $S3_BUCKET"
aws s3 sync client/build/ s3://$S3_BUCKET --delete
- name: Invalidate CloudFront Cache
run: |
STACK_NAME="${{ inputs.tier }}-${{ env.APP }}-cloudfront-s3"
DISTRIBUTION_ID=$(aws cloudformation describe-stacks \
--stack-name "$STACK_NAME" \
--query "Stacks[0].Outputs[?OutputKey=='DistributionId'].OutputValue" \
--output text)
if [ -z "$DISTRIBUTION_ID" ] || [ "$DISTRIBUTION_ID" = "None" ]; then
echo "❌ CloudFront Distribution ID not found. Redeploy CloudFront stack to get the output."
exit 1
fi
echo "Invalidating CloudFront cache for distribution: $DISTRIBUTION_ID"
aws cloudfront create-invalidation \
--distribution-id "$DISTRIBUTION_ID" \
--paths "/*" \
--output table \
--query "Invalidation.{Status:Status,CreateTime:CreateTime}" 2>/dev/null
if [ $? -eq 0 ]; then
echo "✅ CloudFront cache invalidation successful"
else
echo "❌ CloudFront cache invalidation failed"
exit 1
fi