Files
FarmaFinder/.gitea/workflows/docker.yaml
T
Antoni Nuñez Romeu 5ae3ebecee
Run Tests on Branches / Run Tests (push) Successful in 1m44s
ci: consolidate test jobs into single workflow with npm caching
- Merge 3 parallel test jobs (backend/frontend/mobile) into one sequential job
- Remove dependency on dorny/paths-filter@v3 (replaced with git diff script)
- Add npm cache via setup-node to speed up dependency installation
- Downgrade Node.js from 24 to 22 LTS for stability
- Reduce checkout fetch-depth from full history to 2 commits
2026-07-13 21:16:46 +02:00

137 lines
4.0 KiB
YAML

name: Build & Push Docker Images
run-name: ${{ gitea.actor }} - ${{ gitea.ref }}
on:
push:
branches:
- 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
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests
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
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test --workspace=farma-clic-frontend -- --run --reporter=basic
build-backend:
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
- name: Log in to Gitea registry
uses: docker/login-action@v3
with:
registry: git.hacecalor.net
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push backend image
uses: docker/build-push-action@v5
with:
context: .
file: ./apps/backend/Dockerfile
push: true
tags: |
git.hacecalor.net/ichitux/farmafinder-backend:latest
git.hacecalor.net/ichitux/farmafinder-backend:${{ gitea.sha }}
build-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
- name: Log in to Gitea registry
uses: docker/login-action@v3
with:
registry: git.hacecalor.net
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push frontend image
uses: docker/build-push-action@v5
with:
context: ./apps/frontend
push: true
tags: |
git.hacecalor.net/ichitux/farmafinder-frontend:latest
git.hacecalor.net/ichitux/farmafinder-frontend:${{ gitea.sha }}
deploy:
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
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
script: |
cd /docker/FarmaFinder
git pull
docker compose pull
docker compose down --remove-orphans
docker compose up -d