From d6999f49c7a0ac11d95142d80357615636f0d15a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Proen=C3=A7a?= Date: Wed, 28 May 2025 01:40:09 +0100 Subject: [PATCH] Workflow improvement --- .github/workflows/main.yaml | 46 ++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index e01f2c1..ce7cd04 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -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: @@ -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