Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 30 additions & 16 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@ env:
SERVICES: db community thread comment vote search popular

jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
check-cluster:
name: Check if GKE cluster exists
runs-on: ubuntu-latest
environment: production
outputs:
exists: ${{ steps.set-exists.outputs.exists }}

permissions:
contents: read
id-token: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
Expand All @@ -37,30 +35,46 @@ jobs:
with:
project_id: ${{ env.PROJECT_ID }}

- name: Check if GKE cluster exists
id: check-cluster
- id: set-exists
run: |
if gcloud container clusters describe $CLUSTER_NAME --zone $ZONE --project $PROJECT_ID; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "Cluster does not exist"
echo "exists=false" >> $GITHUB_OUTPUT
fi

build-publish-deploy:
name: Build, Publish, and Deploy
needs: check-cluster
if: needs.check-cluster.outputs.exists == 'true'
runs-on: ubuntu-latest
environment: production

permissions:
contents: read
id-token: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}

- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v2
with:
project_id: ${{ env.PROJECT_ID }}

- name: Set up GKE credentials
if: steps.check-cluster.outputs.exists == 'true'
uses: google-github-actions/get-gke-credentials@v2
with:
project_id: ${{ env.PROJECT_ID }}
cluster_name: ${{ env.CLUSTER_NAME }}
location: ${{ env.ZONE }}

- name: Cluster not created. Skip deployment
if: steps.check-cluster.outputs.exists == 'false'
run: |
echo "Cluster doesn't exist — skipping deployment."
exit 0

- name: Configure Docker for GCR
run: |
gcloud auth configure-docker --quiet
Expand Down