|
| 1 | +on: |
| 2 | + workflow_call: |
| 3 | + inputs: |
| 4 | + version: |
| 5 | + required: true |
| 6 | + type: string |
| 7 | + description: "Version of the application being deployed, used for versioned S3 paths and cache invalidation" |
| 8 | + environment: |
| 9 | + type: string |
| 10 | + required: true |
| 11 | + description: "environment to deploy to, used for selecting correct AWS credentials and CloudFront distribution based on environment specific secrets and variables" |
| 12 | + secrets: |
| 13 | + AWS_OIDC_ROLE_ARN: |
| 14 | + description: "OIDC role ARN for AWS credentials" |
| 15 | + required: true |
| 16 | + AWS_DEPLOYMENT_ROLE_ARN: |
| 17 | + description: "Deployment role ARN for AWS credentials" |
| 18 | + required: true |
| 19 | + |
| 20 | +jobs: |
| 21 | + # todo push to versioned s3 path / dont invalidate cache / instead create PR on Infrastructure repo to update origin path or copy the directory |
| 22 | + build-push-s3: |
| 23 | + name: Build and push application to S3 bucket |
| 24 | + runs-on: ubuntu-latest |
| 25 | + environment: ${{ inputs.environment }} |
| 26 | + timeout-minutes: 5 |
| 27 | + # todo activate once requried |
| 28 | + #FONTAWESOME_PACKAGE_TOKEN: ${{ secrets.FONTAWESOME_PACKAGE_TOKEN }} |
| 29 | + permissions: |
| 30 | + id-token: write |
| 31 | + contents: read |
| 32 | + steps: |
| 33 | + - name: Print GitHub Context Safely |
| 34 | + run: | |
| 35 | + echo "--- GitHub Context ---" |
| 36 | + echo "${GITHUB_REPOSITORY}" |
| 37 | + echo "${GITHUB_REF}" |
| 38 | + echo "${GITHUB_SHA}" |
| 39 | +
|
| 40 | + - name: Checkout |
| 41 | + uses: actions/checkout@v6 |
| 42 | + with: |
| 43 | + ref: ${{ format('v{0}', inputs.version) }} |
| 44 | + |
| 45 | + - name: Set up pnpm |
| 46 | + uses: pnpm/action-setup@v4 |
| 47 | + |
| 48 | + - name: Set up Node.js |
| 49 | + uses: actions/setup-node@v6 |
| 50 | + with: |
| 51 | + node-version: 24 |
| 52 | + cache: pnpm |
| 53 | + cache-dependency-path: pnpm-lock.yaml |
| 54 | + |
| 55 | + - name: pnpm install |
| 56 | + run: pnpm install --frozen-lockfile --ignore-scripts |
| 57 | + |
| 58 | + - name: Build |
| 59 | + # todo maybe adjust with env specific config eg: pnpm build -- --configuration=${{ steps.resolve-inputs.outputs.configuration }} |
| 60 | + run: pnpm build |
| 61 | + |
| 62 | + - name: Configure AWS credentials (OIDC) |
| 63 | + uses: aws-actions/configure-aws-credentials@v4 |
| 64 | + with: |
| 65 | + role-to-assume: ${{ secrets.AWS_OIDC_ROLE_ARN }} |
| 66 | + aws-region: ${{ vars.AWS_REGION }} |
| 67 | + |
| 68 | + - name: Assume deployment role |
| 69 | + uses: aws-actions/configure-aws-credentials@v4 |
| 70 | + with: |
| 71 | + role-to-assume: ${{ secrets.AWS_DEPLOYMENT_ROLE_ARN }} |
| 72 | + aws-region: ${{ vars.AWS_REGION }} |
| 73 | + role-chaining: true |
| 74 | + role-skip-session-tagging: true |
| 75 | + |
| 76 | + - name: Deploy to S3 bucket |
| 77 | + env: |
| 78 | + VERSION: ${{ inputs.version }} |
| 79 | + run: | |
| 80 | + set -euo pipefail |
| 81 | +
|
| 82 | + # Allowlist validation (adjust to your conventions) |
| 83 | + [[ "$VERSION" =~ ^[0-9]+(\.[0-9]+){2}([.-][0-9A-Za-z]+)*$ ]] || { echo "Invalid version"; exit 1; } |
| 84 | +
|
| 85 | +
|
| 86 | + echo "Deploying version: v${VERSION}" |
| 87 | +
|
| 88 | + aws s3 sync "dist/atlas-agate-frontend/browser/" "s3://${{vars.FRONTEND_S3_BUCKET}}/" \ |
| 89 | + --region "$AWS_REGION" \ |
| 90 | + --delete |
| 91 | +
|
| 92 | + - name: Invalidate CloudFront cache |
| 93 | + run: | |
| 94 | + echo "Creating CloudFront invalidation for distribution: ${{ vars.CLOUDFRONT_DISTRIBUTION_ID }}" |
| 95 | + aws cloudfront create-invalidation \ |
| 96 | + --distribution-id ${{ vars.CLOUDFRONT_DISTRIBUTION_ID }} \ |
| 97 | + --paths "/*" |
| 98 | +
|
| 99 | + - name: Display deployment URL |
| 100 | + run: | |
| 101 | + echo "✅ Deployment complete!" |
| 102 | + echo "🌐 Your application is available at: https://www.blw-agate-dev.pc-core.isceco.admin.ch" |
0 commit comments