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
This commit is contained in:
@@ -7,7 +7,29 @@ on:
|
|||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
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:
|
test-backend:
|
||||||
|
name: Backend Tests
|
||||||
|
needs: detect-changes
|
||||||
|
if: needs.detect-changes.outputs.backend == 'true'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -22,6 +44,9 @@ jobs:
|
|||||||
run: npm test --workspace=farma-clic-backend -- --ci
|
run: npm test --workspace=farma-clic-backend -- --ci
|
||||||
|
|
||||||
test-frontend:
|
test-frontend:
|
||||||
|
name: Frontend Tests
|
||||||
|
needs: detect-changes
|
||||||
|
if: needs.detect-changes.outputs.frontend == 'true'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -36,7 +61,12 @@ jobs:
|
|||||||
run: npm test --workspace=farma-clic-frontend -- --run --reporter=basic
|
run: npm test --workspace=farma-clic-frontend -- --run --reporter=basic
|
||||||
|
|
||||||
build-backend:
|
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
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -57,7 +87,12 @@ jobs:
|
|||||||
git.hacecalor.net/ichitux/farmafinder-backend:${{ gitea.sha }}
|
git.hacecalor.net/ichitux/farmafinder-backend:${{ gitea.sha }}
|
||||||
|
|
||||||
build-frontend:
|
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
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -77,7 +112,13 @@ jobs:
|
|||||||
git.hacecalor.net/ichitux/farmafinder-frontend:${{ gitea.sha }}
|
git.hacecalor.net/ichitux/farmafinder-frontend:${{ gitea.sha }}
|
||||||
|
|
||||||
deploy:
|
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
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: SSH to remote server
|
- name: SSH to remote server
|
||||||
@@ -91,4 +132,5 @@ jobs:
|
|||||||
cd /docker/FarmaFinder
|
cd /docker/FarmaFinder
|
||||||
git pull
|
git pull
|
||||||
docker compose pull
|
docker compose pull
|
||||||
|
docker compose down --remove-orphans
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
|
|||||||
@@ -6,8 +6,33 @@ on:
|
|||||||
- 'main'
|
- 'main'
|
||||||
|
|
||||||
jobs:
|
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:
|
test-backend:
|
||||||
name: Backend Tests
|
name: Backend Tests
|
||||||
|
needs: detect-changes
|
||||||
|
if: needs.detect-changes.outputs.backend == 'true'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
@@ -27,6 +52,8 @@ jobs:
|
|||||||
|
|
||||||
test-frontend:
|
test-frontend:
|
||||||
name: Frontend Tests
|
name: Frontend Tests
|
||||||
|
needs: detect-changes
|
||||||
|
if: needs.detect-changes.outputs.frontend == 'true'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
@@ -43,3 +70,25 @@ jobs:
|
|||||||
|
|
||||||
- name: Run Frontend Tests
|
- name: Run Frontend Tests
|
||||||
run: npm test --workspace=farma-clic-frontend -- --run --reporter=basic
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user