From 263e38f23ecd85bb730b61001b7390ce50a67ae3 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Thu, 26 Feb 2026 16:52:24 +0100 Subject: [PATCH] Separate version check from action --- .github/workflows/cd-android-live-update.yml | 32 ++++++++------- .github/workflows/cd-api.yml | 41 ++++++++++---------- 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/.github/workflows/cd-android-live-update.yml b/.github/workflows/cd-android-live-update.yml index 8d0df364..9d4c2a64 100644 --- a/.github/workflows/cd-android-live-update.yml +++ b/.github/workflows/cd-android-live-update.yml @@ -1,24 +1,23 @@ name: CD Android Live Update on: push: - branches: [main, master] + branches: [ main, master ] paths: - 'android/capawesome.json' - '.github/workflows/cd-android-live-update.yml' jobs: - deploy: - name: Deploy + check-version: + name: Check Version runs-on: ubuntu-latest + outputs: + changed: ${{ steps.check.outputs.changed }} steps: - name: Checkout uses: actions/checkout@v4 with: - fetch-depth: 0 # we need full history for git log - - - name: Install jq - run: sudo apt-get install -y jq + fetch-depth: 2 - name: Read current version id: current @@ -29,7 +28,6 @@ jobs: - name: Read previous version id: previous run: | - # Get previous commit’s package.json (if it existed) if git show HEAD^:android/capawesome.json >/dev/null 2>&1; then previous=$(git show HEAD^:android/capawesome.json | jq -r '.version') else @@ -37,29 +35,37 @@ jobs: fi echo "version=$previous" >> $GITHUB_OUTPUT - - name: Check version change + - name: Compare versions id: check run: | echo "current=${{ steps.current.outputs.version }}" echo "previous=${{ steps.previous.outputs.version }}" if [ "${{ steps.current.outputs.version }}" = "${{ steps.previous.outputs.version }}" ]; then + echo "Version unchanged. Skipping deploy." echo "changed=false" >> $GITHUB_OUTPUT else echo "changed=true" >> $GITHUB_OUTPUT fi + deploy: + name: Deploy + runs-on: ubuntu-latest + needs: check-version + if: needs.check-version.outputs.changed == 'true' + + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Node.js - if: steps.check.outputs.changed == 'true' uses: actions/setup-node@v4 with: node-version: '22' - name: Install dependencies - if: steps.check.outputs.changed == 'true' run: yarn install - name: Deploy Live Update - if: steps.check.outputs.changed == 'true' env: NEXT_PUBLIC_FIREBASE_API_KEY: ${{ secrets.NEXT_PUBLIC_FIREBASE_API_KEY }} NEXT_PUBLIC_SUPABASE_INSTANCE_ID: ${{ secrets.NEXT_PUBLIC_SUPABASE_INSTANCE_ID }} @@ -67,4 +73,4 @@ jobs: CAPAWESOME_TOKEN: ${{ secrets.CAPAWESOME_TOKEN }} commitRef: ${{ github.head_ref || github.ref_name }} commitSha: ${{ github.sha }} - run: yarn android-live-update + run: yarn android-live-update \ No newline at end of file diff --git a/.github/workflows/cd-api.yml b/.github/workflows/cd-api.yml index 438c0567..e5436a92 100644 --- a/.github/workflows/cd-api.yml +++ b/.github/workflows/cd-api.yml @@ -7,18 +7,17 @@ on: - '.github/workflows/cd-api.yml' jobs: - deploy: - name: Deploy + check-version: + name: Check Version runs-on: ubuntu-latest + outputs: + changed: ${{ steps.check.outputs.changed }} steps: - name: Checkout uses: actions/checkout@v4 with: - fetch-depth: 0 # we need full history for git log - - - name: Install jq - run: sudo apt-get install -y jq + fetch-depth: 2 - name: Read current version id: current @@ -29,7 +28,6 @@ jobs: - name: Read previous version id: previous run: | - # Get previous commit’s package.json (if it existed) if git show HEAD^:backend/api/package.json >/dev/null 2>&1; then previous=$(git show HEAD^:backend/api/package.json | jq -r '.version') else @@ -37,60 +35,61 @@ jobs: fi echo "version=$previous" >> $GITHUB_OUTPUT - - name: Check version change + - name: Compare versions id: check run: | echo "current=${{ steps.current.outputs.version }}" echo "previous=${{ steps.previous.outputs.version }}" if [ "${{ steps.current.outputs.version }}" = "${{ steps.previous.outputs.version }}" ]; then + echo "Version unchanged. Skipping deploy." echo "changed=false" >> $GITHUB_OUTPUT else echo "changed=true" >> $GITHUB_OUTPUT fi + deploy: + name: Deploy + runs-on: ubuntu-latest + needs: check-version + if: needs.check-version.outputs.changed == 'true' + + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Node.js - if: steps.check.outputs.changed == 'true' uses: actions/setup-node@v4 with: node-version: '22' - name: Install dependencies - if: steps.check.outputs.changed == 'true' run: yarn install - name: Authenticate to GCP - if: steps.check.outputs.changed == 'true' uses: google-github-actions/auth@v2 with: credentials_json: ${{ secrets.GCP_SA_KEY }} - name: Install gcloud CLI - if: steps.check.outputs.changed == 'true' uses: google-github-actions/setup-gcloud@v2 with: project_id: compass-130ba - name: Configure Docker for Artifact Registry - if: steps.check.outputs.changed == 'true' - run: | - gcloud auth configure-docker us-west1-docker.pkg.dev --quiet + run: gcloud auth configure-docker us-west1-docker.pkg.dev --quiet - name: Install Tofu (Terraform) - if: steps.check.outputs.changed == 'true' run: | - sudo apt-get update - sudo apt-get install -y wget unzip LATEST=https://github.com/opentofu/opentofu/releases/download/v1.10.5/tofu_1.10.5_linux_amd64.zip curl -LO "$LATEST" unzip -o tofu_*_linux_amd64.zip sudo mv tofu /usr/local/bin/ rm tofu_*_linux_amd64.zip echo "OpenTofu version: $(tofu version)" - cd backend/api || exit 1 + cd backend/api tofu init - name: Run deploy script - if: steps.check.outputs.changed == 'true' run: | chmod +x backend/api/deploy-api.sh - backend/api/deploy-api.sh + backend/api/deploy-api.sh \ No newline at end of file