Skip to content

Commit

Permalink
Merge pull request #13 from xplorer-io/feat/ci-enhancements
Browse files Browse the repository at this point in the history
Feat/ci enhancements
  • Loading branch information
samurato authored Oct 6, 2024
2 parents 59efcca + 20d9e79 commit 7c47455
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
48 changes: 32 additions & 16 deletions .github/workflows/deploy-to-gcp.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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 }}\`
<details><summary>Show Plan</summary>
\n
\`\`\`\n
${process.env.PLAN}
\`\`\`
\n
</details>
*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
})
4 changes: 3 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}" \
Expand All @@ -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}" \
Expand Down

0 comments on commit 7c47455

Please sign in to comment.