From 562ede196161c168e644dfe10ab540c7f1358eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoni=20Nu=C3=B1ez=20Romeu?= Date: Tue, 7 Jul 2026 18:15:38 +0200 Subject: [PATCH] chore: optimize CI/CD workflows with path-based detection - Add dorny/paths-filter to detect changes per component - Run only relevant tests (backend/frontend/frontend-mobile) - Build only changed Docker images - Fix Docker container removal error with --remove-orphans - Add conditional deploy based on actual changes --- .gitea/workflows/docker.yaml | 48 ++++++++++++++++++++++++++-- .gitea/workflows/test-branches.yaml | 49 +++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/docker.yaml b/.gitea/workflows/docker.yaml index fc83815..1897f53 100644 --- a/.gitea/workflows/docker.yaml +++ b/.gitea/workflows/docker.yaml @@ -7,7 +7,29 @@ on: - main jobs: + detect-changes: + name: Detect Changes + runs-on: ubuntu-latest + outputs: + backend: ${{ steps.filter.outputs.backend }} + frontend: ${{ steps.filter.outputs.frontend }} + steps: + - uses: actions/checkout@v4 + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + backend: + - 'apps/backend/**' + - 'packages/**' + frontend: + - 'apps/frontend/**' + - 'packages/**' + test-backend: + name: Backend Tests + needs: detect-changes + if: needs.detect-changes.outputs.backend == 'true' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -22,6 +44,9 @@ jobs: run: npm test --workspace=farma-clic-backend -- --ci test-frontend: + name: Frontend Tests + needs: detect-changes + if: needs.detect-changes.outputs.frontend == 'true' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -36,7 +61,12 @@ jobs: run: npm test --workspace=farma-clic-frontend -- --run --reporter=basic build-backend: - needs: [ test-backend, test-frontend ] + name: Build Backend + needs: [ detect-changes, test-backend ] + if: | + always() && + needs.detect-changes.outputs.backend == 'true' && + (needs.test-backend.result == 'success' || needs.test-backend.result == 'skipped') runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -57,7 +87,12 @@ jobs: git.hacecalor.net/ichitux/farmafinder-backend:${{ gitea.sha }} build-frontend: - needs: [ test-backend, test-frontend ] + name: Build Frontend + needs: [ detect-changes, test-frontend ] + if: | + always() && + needs.detect-changes.outputs.frontend == 'true' && + (needs.test-frontend.result == 'success' || needs.test-frontend.result == 'skipped') runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -77,7 +112,13 @@ jobs: git.hacecalor.net/ichitux/farmafinder-frontend:${{ gitea.sha }} deploy: - needs: [ build-backend, build-frontend ] + name: Deploy + needs: [ detect-changes, build-backend, build-frontend ] + if: | + always() && + (needs.build-backend.result == 'success' || needs.build-backend.result == 'skipped') && + (needs.build-frontend.result == 'success' || needs.build-frontend.result == 'skipped') && + (needs.detect-changes.outputs.backend == 'true' || needs.detect-changes.outputs.frontend == 'true') runs-on: ubuntu-latest steps: - name: SSH to remote server @@ -91,4 +132,5 @@ jobs: cd /docker/FarmaFinder git pull docker compose pull + docker compose down --remove-orphans docker compose up -d diff --git a/.gitea/workflows/test-branches.yaml b/.gitea/workflows/test-branches.yaml index a82d007..42c8838 100644 --- a/.gitea/workflows/test-branches.yaml +++ b/.gitea/workflows/test-branches.yaml @@ -6,8 +6,33 @@ on: - 'main' jobs: + detect-changes: + name: Detect Changes + runs-on: ubuntu-latest + outputs: + backend: ${{ steps.filter.outputs.backend }} + frontend: ${{ steps.filter.outputs.frontend }} + frontend-mobile: ${{ steps.filter.outputs.frontend-mobile }} + steps: + - uses: actions/checkout@v4 + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + backend: + - 'apps/backend/**' + - 'packages/**' + frontend: + - 'apps/frontend/**' + - 'packages/**' + frontend-mobile: + - 'apps/frontend-mobile/**' + - 'packages/**' + test-backend: name: Backend Tests + needs: detect-changes + if: needs.detect-changes.outputs.backend == 'true' runs-on: ubuntu-latest steps: - name: Checkout Code @@ -27,6 +52,8 @@ jobs: test-frontend: name: Frontend Tests + needs: detect-changes + if: needs.detect-changes.outputs.frontend == 'true' runs-on: ubuntu-latest steps: - name: Checkout Code @@ -43,3 +70,25 @@ jobs: - name: Run Frontend Tests run: npm test --workspace=farma-clic-frontend -- --run --reporter=basic + + test-frontend-mobile: + name: Frontend Mobile Tests + needs: detect-changes + if: needs.detect-changes.outputs.frontend-mobile == 'true' + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '24' + cache: 'npm' + + - name: Install Dependencies + run: npm ci + + - name: Run Frontend Mobile Tests + run: npm test --workspace=frontend-mobile -- --ci + continue-on-error: true -- 2.52.0