Files
projet_gestion_commande/.github/workflows/frontend-web-build.yml
T
2026-06-14 18:18:37 +02:00

111 lines
3.8 KiB
YAML

name: Frontend Web - Build & Lint
on:
push:
branches: [main, pre-prod]
paths:
- "frontend-prep/**"
pull_request:
branches: [main, pre-prod]
paths:
- "frontend-prep/**"
jobs:
lint-typecheck:
name: Lint & Typecheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: frontend-prep/package-lock.json
- name: Install dependencies
working-directory: frontend-prep
run: npm ci
- name: Typecheck
working-directory: frontend-prep
run: npx tsc -b --noEmit
- name: Lint
working-directory: frontend-prep
run: npm run lint
build:
name: Build
needs: lint-typecheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: frontend-prep/package-lock.json
- name: Install dependencies
working-directory: frontend-prep
run: npm ci
- name: Build
working-directory: frontend-prep
env:
VITE_TOMTOM_API_KEY: ${{ secrets.VITE_TOMTOM_API_KEY }}
run: npm run build
docker:
name: Docker Build & Push
needs: build
runs-on: ubuntu-latest
if: >
(github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/pre-prod')) ||
(github.event_name == 'pull_request' && (github.base_ref == 'main' || github.base_ref == 'pre-prod'))
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build & push frontend
uses: docker/build-push-action@v6
with:
context: .
file: docker-prod/frontend/Dockerfile
push: true
tags: xor1234/frontend-mln:${{ (github.ref == 'refs/heads/main' || github.base_ref == 'main') && 'latest' || 'pre-prod' }}
build-args: |
VITE_TOMTOM_API_KEY=${{ secrets.VITE_TOMTOM_API_KEY }}
deploy:
name: Deploy to server
needs: docker
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- name: SSH deploy
uses: appleboy/ssh-action@v1
with:
host: ${{ (github.ref == 'refs/heads/main' || github.base_ref == 'main') && secrets.SERVER_HOST_PROD || secrets.SERVER_HOST_PRE_PROD }}
username: ${{ secrets.SERVER_USER }}
key: ${{ (github.ref == 'refs/heads/main' || github.base_ref == 'main') && secrets.SERVER_SSH_KEY_PROD || secrets.SERVER_SSH_KEY_PRE_PROD }}
script: |
docker compose -f ${{ (github.ref == 'refs/heads/main' || github.base_ref == 'main') && secrets.COMPOSE_PATH_PROD || secrets.COMPOSE_PATH_PRE_PROD }} pull frontend
docker compose -f ${{ (github.ref == 'refs/heads/main' || github.base_ref == 'main') && secrets.COMPOSE_PATH_PROD || secrets.COMPOSE_PATH_PRE_PROD }} up -d --no-deps frontend