Files
projet_gestion_commande/.github/workflows/backend-build.yml
T
2026-05-03 20:24:18 +02:00

117 lines
4.1 KiB
YAML

name: Backend - Build & Lint
on:
push:
branches: [main, pre-prod]
paths:
- "backend/**"
pull_request:
branches: [main, pre-prod]
paths:
- "backend/**"
jobs:
lint:
name: Static Analysis (golangci-lint)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.24.4"
cache-dependency-path: backend/gestion/go.sum
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
continue-on-error: true
with:
version: latest
working-directory: backend/gestion
args: --timeout=5m
build:
name: Build
needs: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.24.4"
cache-dependency-path: backend/gestion/go.sum
- name: Download dependencies
working-directory: backend/gestion
run: go mod download
- name: Build
working-directory: backend/gestion
run: go build -v ./...
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 backend (runtime)
uses: docker/build-push-action@v6
with:
context: .
file: docker/backend/Dockerfile
target: runtime
push: true
tags: xor1234/backend-mln:${{ (github.ref == 'refs/heads/main' || github.base_ref == 'main') && 'latest' || 'pre-prod' }}
cache-from: type=gha,scope=backend-runtime
cache-to: type=gha,mode=max,scope=backend-runtime
- name: Build & push WAF
uses: docker/build-push-action@v6
with:
context: .
file: docker/backend/Dockerfile
target: waf
push: true
tags: xor1234/backend-mln:${{ (github.ref == 'refs/heads/main' || github.base_ref == 'main') && 'waf' || 'waf-pre-prod' }}
cache-from: type=gha,scope=backend-waf
cache-to: type=gha,mode=max,scope=backend-waf
deploy:
name: Deploy to server
needs: docker
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:
- 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 }}
username: ${{ secrets.SERVER_USER }}
key: ${{ (github.ref == 'refs/heads/main' || github.base_ref == 'main') && secrets.SERVER_SSH_KEY_PROD || secrets.SERVER_SSH_KEY }}
script: |
docker compose -f ${{ secrets.COMPOSE_PATH }} pull backend waf
docker compose -f ${{ secrets.COMPOSE_PATH }} up -d --no-deps backend waf