|
| 1 | +name: Build and deploy CARE FE to GCS for egov staging HMIS |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - develop |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + issues: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + # Step 1: Build the application |
| 14 | + build: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + environment: Production |
| 17 | + outputs: |
| 18 | + build-artifact-id: ${{ steps.upload-artifact.outputs.artifact-id }} |
| 19 | + steps: |
| 20 | + - name: Checkout repository |
| 21 | + uses: actions/checkout@v3 |
| 22 | + |
| 23 | + - name: Set up Node.js |
| 24 | + uses: actions/setup-node@v3 |
| 25 | + with: |
| 26 | + node-version: 22 |
| 27 | + |
| 28 | + - name: Update .env file |
| 29 | + run: | |
| 30 | + echo "${{ vars.DEPLOYMENT_ENV_FILE }}" | base64 --decode > .env |
| 31 | +
|
| 32 | + - name: Install dependencies |
| 33 | + run: npm install |
| 34 | + |
| 35 | + - name: Build the React app |
| 36 | + run: npm run build |
| 37 | + |
| 38 | + - name: Upload build artifact |
| 39 | + id: upload-artifact |
| 40 | + uses: actions/upload-artifact@v4 |
| 41 | + with: |
| 42 | + name: build-artifact |
| 43 | + path: build/ |
| 44 | + retention-days: 1 |
| 45 | + |
| 46 | + # Step 2: Deploy to GCS |
| 47 | + deploy-to-gcs: |
| 48 | + runs-on: ubuntu-latest |
| 49 | + environment: Production |
| 50 | + needs: build |
| 51 | + steps: |
| 52 | + - name: Download build artifact |
| 53 | + uses: actions/download-artifact@v4 |
| 54 | + with: |
| 55 | + name: build-artifact |
| 56 | + path: build/ |
| 57 | + |
| 58 | + - name: Authenticate to Google Cloud |
| 59 | + uses: google-github-actions/auth@v2 |
| 60 | + with: |
| 61 | + credentials_json: ${{ secrets.GCP_SA_KEY }} |
| 62 | + |
| 63 | + - name: Set up Cloud SDK |
| 64 | + uses: google-github-actions/setup-gcloud@v2 |
| 65 | + |
| 66 | + - name: Upload build to GCS |
| 67 | + run: | |
| 68 | + gsutil -m rsync -r -d build/ gs://${{ secrets.GCS_BUCKET_NAME }}/ |
| 69 | +
|
| 70 | + # Step 3: Invalidate CDN cache |
| 71 | + invalidate-cdn: |
| 72 | + runs-on: ubuntu-latest |
| 73 | + environment: Production |
| 74 | + needs: deploy-to-gcs |
| 75 | + steps: |
| 76 | + - name: Authenticate to Google Cloud |
| 77 | + uses: google-github-actions/auth@v2 |
| 78 | + with: |
| 79 | + credentials_json: ${{ secrets.GCP_SA_KEY }} |
| 80 | + |
| 81 | + - name: Set up Cloud SDK |
| 82 | + uses: google-github-actions/setup-gcloud@v2 |
| 83 | + |
| 84 | + - name: Invalidate Cloud CDN cache |
| 85 | + run: | |
| 86 | + gcloud compute url-maps invalidate-cdn-cache ${{ secrets.CDN_URL_MAP_NAME }} \ |
| 87 | + --path "/*" \ |
| 88 | + --project=${{ secrets.GCP_PROJECT_ID }} |
| 89 | +
|
| 90 | + # Step 4: Notify deployment status |
| 91 | + notify: |
| 92 | + runs-on: ubuntu-latest |
| 93 | + needs: [build, deploy-to-gcs, invalidate-cdn] |
| 94 | + if: always() |
| 95 | + steps: |
| 96 | + - name: Check deployment status |
| 97 | + run: | |
| 98 | + if [ "${{ needs.build.result }}" == "success" ] && \ |
| 99 | + [ "${{ needs.deploy-to-gcs.result }}" == "success" ] && \ |
| 100 | + [ "${{ needs.invalidate-cdn.result }}" == "success" ]; then |
| 101 | + echo "✅ Deployment completed successfully" |
| 102 | + echo "DEPLOYMENT_STATUS=success" >> $GITHUB_ENV |
| 103 | + else |
| 104 | + echo "❌ Deployment failed" |
| 105 | + echo "DEPLOYMENT_STATUS=failure" >> $GITHUB_ENV |
| 106 | + exit 1 |
| 107 | + fi |
| 108 | +
|
| 109 | + - name: Create deployment summary |
| 110 | + run: | |
| 111 | + echo "## Deployment Summary" >> $GITHUB_STEP_SUMMARY |
| 112 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 113 | + echo "| Step | Status |" >> $GITHUB_STEP_SUMMARY |
| 114 | + echo "|------|--------|" >> $GITHUB_STEP_SUMMARY |
| 115 | + echo "| Build | ${{ needs.build.result }} |" >> $GITHUB_STEP_SUMMARY |
| 116 | + echo "| Deploy to GCS | ${{ needs.deploy-to-gcs.result }} |" >> $GITHUB_STEP_SUMMARY |
| 117 | + echo "| CDN Invalidation | ${{ needs.invalidate-cdn.result }} |" >> $GITHUB_STEP_SUMMARY |
| 118 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 119 | + echo "**Environment:** Production" >> $GITHUB_STEP_SUMMARY |
| 120 | + echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY |
| 121 | + echo "**Triggered by:** ${{ github.actor }}" >> $GITHUB_STEP_SUMMARY |
0 commit comments