Deploy Nevus App #23
This file contains hidden or 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 Nevus App | |
| permissions: | |
| id-token: write | |
| contents: read | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| tier: | |
| description: "Deploy environment" | |
| required: true | |
| default: "dev" | |
| type: choice | |
| options: | |
| - dev | |
| - qa | |
| - stage | |
| - prod | |
| jobs: | |
| deploy-cloudfront: | |
| timeout-minutes: 10 | |
| runs-on: ubuntu-latest | |
| environment: ${{ inputs.tier }} | |
| env: | |
| APP: nevustool | |
| TIER: ${{ inputs.tier }} | |
| TZ: America/New_York | |
| AWS_REGION: us-east-1 | |
| CICD_ROLE_ARN: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/power-user-github-actions-cicd | |
| steps: | |
| - uses: "actions/checkout@v6.0.2" | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v6.0.0 | |
| with: | |
| role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/power-user-github-actions-cicd | |
| role-session-name: ${{ env.TIER }}-nevustool-app-${{ github.ref_name }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| - name: Build app | |
| run: | | |
| cd client | |
| npm ci | |
| npm run build | |
| - 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: | | |
| DISTRIBUTION_ID=$(aws cloudformation describe-stacks \ | |
| --stack-name "${{ env.TIER }}-${{ env.APP }}-cloudfront-s3" \ | |
| --query "Stacks[0].Outputs[?OutputKey=='DistributionId'].OutputValue" \ | |
| --output text) | |
| 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 | |
| - name: Deployment summary | |
| run: | | |
| echo "## Deployment Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Tier:** ${{ env.TIER }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Branch:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY |