Parallelize GHA workflow #2
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: Build and deploy | |
| on: | |
| push: | |
| branches: [main] | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| env: | |
| TF_VAR_aws_region: us-east-1 | |
| TF_VAR_project: iporaitech | |
| TF_VAR_env: prod # Only prod for the moment | |
| TF_VAR_dns_google_site_verification_txt: ${{ vars.GOOGLE_SITE_VERIFICATION_TXT }} | |
| TF_VAR_dns_dkim_txt: ${{ vars.DNS_DKIM_TXT }} | |
| permissions: | |
| contents: read | |
| id-token: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Parse .tool-versions | |
| uses: ./.github/actions/parse-tool-versions | |
| id: tool-versions | |
| - uses: actions/setup-node@v5 | |
| with: | |
| node-version: ${{ fromJSON(steps.tool-versions.outputs.versions).nodejs }} | |
| cache: 'yarn' | |
| - run: node -v | |
| - run: yarn set version ${{ fromJSON(steps.tool-versions.outputs.versions).yarn }} | |
| - run: yarn install --inmutable | |
| - run: yarn build:prod | |
| - name: Upload dist bundle | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist-artifact | |
| path: dist | |
| infra: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| tf_output: ${{ steps.tf_output.outputs.json}} | |
| env: | |
| TF_IN_AUTOMATION: true | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Parse .tool-versions | |
| uses: ./.github/actions/parse-tool-versions | |
| id: tool-versions | |
| - uses: aws-actions/configure-aws-credentials@v5.0.0 | |
| with: | |
| role-to-assume: ${{ secrets.AWS_ROLE }} | |
| aws-region: ${{ env.TF_VAR_aws_region }} | |
| - uses: hashicorp/setup-terraform@v3 | |
| with: | |
| terraform_version: ${{ fromJSON(steps.tool-versions.outputs.versions).terraform }} | |
| - name: Terraform init | |
| run: | | |
| terraform init -input=false \ | |
| -backend-config="bucket=${{env.TF_VAR_project}}-tfbackend" \ | |
| -backend-config="region=${{env.TF_VAR_aws_region}}" | |
| working-directory: ./terraform | |
| - run: terraform plan -out=tfplan -input=false | |
| working-directory: ./terraform | |
| - run: terraform apply -input=false tfplan | |
| working-directory: ./terraform | |
| - run: echo "json=$(terraform output -json | jq -c .)" >> $GITHUB_OUTPUT | |
| working-directory: ./terraform | |
| id: tf_output | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: [build, infra] | |
| steps: | |
| - uses: aws-actions/configure-aws-credentials@v5.0.0 | |
| with: | |
| role-to-assume: ${{ secrets.AWS_ROLE }} | |
| aws-region: ${{ env.TF_VAR_aws_region }} | |
| - name: Download dist artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: dist-artifact | |
| path: dist | |
| - name: Sync to S3 | |
| env: | |
| S3_BUCKET_NAME: ${{ fromJson(needs.infra.outputs.tf_output).s3_bucket_name.value }} | |
| run: aws s3 sync ./dist s3://${{env.S3_BUCKET_NAME}}/ --delete | |
| - name: Invalidate CloudFront | |
| env: | |
| CLOUDFRONT_DIST_ID: ${{ fromJson(needs.infra.outputs.tf_output).cloudfront_dist_id.value }} | |
| run: | | |
| aws cloudfront create-invalidation \ | |
| --distribution-id ${{env.CLOUDFRONT_DIST_ID}} \ | |
| --paths "/*" "/en/*" |