diff --git a/.github/workflows/deploy-to-gcp.yaml b/.github/workflows/deploy-to-gcp.yaml index 74a65f3..11bf8c3 100644 --- a/.github/workflows/deploy-to-gcp.yaml +++ b/.github/workflows/deploy-to-gcp.yaml @@ -1,44 +1,60 @@ name: Deploy Xplorers API to GCP - -on: push - +on: + push: + pull_request: + types: + - ready_for_review permissions: - contents: read id-token: write - + contents: write + pull-requests: write jobs: deploy-xplorers-api: name: Deploy Xplorers API to GCP runs-on: ubuntu-latest - defaults: run: shell: bash - steps: - name: Checkout uses: actions/checkout@v4 - - id: auth uses: google-github-actions/auth@v2.0.0 with: workload_identity_provider: ${{ secrets.GOOGLE_CLOUD_WORKLOAD_IDENTITY_PROVIDER }} - - name: Setup Terraform uses: hashicorp/setup-terraform@v1 - - name: Setup pnpm uses: pnpm/action-setup@v4 with: version: 9 - - name: Install taskfile run: | sudo snap install task --classic - - name: Terraform Plan + if: github.event_name == 'pull_request' + id: plan run: task terraform-plan - - - name: Terraform Apply - if: github.ref == 'refs/heads/"main"' && github.event_name == 'push' - run: task terraform-apply + - name: Update Pull Request + uses: actions/github-script@v6 + if: github.event_name == 'pull_request' + env: + PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" + with: + result-encoding: string + script: | + const output = `#### TASK Terraform Plan 📖\`${{ steps.plan.outcome }}\` +
Show Plan + \n + \`\`\`\n + ${process.env.PLAN} + \`\`\` + \n +
+ *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: output + }) diff --git a/Taskfile.yml b/Taskfile.yml index 0e9e633..cf8a450 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -108,6 +108,7 @@ tasks: terraform init \ -backend-config="bucket=${ARTIFACTS_BUCKET_NAME}" \ -backend-config="prefix=${ARTIFACTS_BUCKET_TERRAFORM_PREFIX}" + - terraform validate -no-color terraform-plan: dir: terraform @@ -118,6 +119,7 @@ tasks: - task: package - | terraform plan \ + -no-color \ -var "artifacts_bucket_name=${ARTIFACTS_BUCKET_NAME}" \ -var "project_id=${GOOGLE_CLOUD_PROJECT_ID}" \ -var "project_number=${GOOGLE_PROJECT_NUMBER}" \ @@ -134,7 +136,7 @@ tasks: - task: package - task: build-xplorers-backend-image - | - terraform apply -auto-approve \ + terraform apply -no-color -auto-approve \ -var "artifacts_bucket_name=${ARTIFACTS_BUCKET_NAME}" \ -var "project_id=${GOOGLE_CLOUD_PROJECT_ID}" \ -var "project_number=${GOOGLE_PROJECT_NUMBER}" \