CI / lint-backend (push) Failing after 1m19s
CI / lint-mobile (push) Canceled after 5m20s
CI / test-backend (push) Canceled after 0s
CI / test-mobile (push) Canceled after 0s
CI / build-backend (push) Canceled after 0s
CI / docker (push) Canceled after 0s
249 lines
9.4 KiB
YAML
249 lines
9.4 KiB
YAML
# Pipeline Gitea Actions pour Kazier — lint + test + build + image registre.
|
|
#
|
|
# Prérequis act_runner (une seule fois) :
|
|
# - Runner act_runner enregistré contre l'instance Gitea, labels `ubuntu-24.04` dispo.
|
|
# - Job `docker` : utilise le daemon Docker de l'hôte du runner via le
|
|
# socket monté (`-v /var/run/docker.sock:/var/run/docker.sock`, pas de
|
|
# DinD, pas de `--privileged`, pas d'attente TCP). Le runner doit donc
|
|
# autoriser ce mount (config act_runner : `valid_volumes` inclut
|
|
# `/var/run/docker.sock`) et son hôte doit avoir un daemon Docker sain.
|
|
# - Gitea app.ini : [actions] ENABLED=true, DEFAULT_ACTIONS_URL=https://github.com
|
|
# - Droits d'écriture du runner sur son répertoire de travail/cache.
|
|
#
|
|
# Secrets (Settings > Actions) :
|
|
# - CONTAINER_REGISTRY_TOKEN PAT scope write:package (registre conteneur)
|
|
# - CONTAINER_REGISTRY_USER utilisateur propriétaire du PAT ci-dessus
|
|
|
|
name: CI
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
tags: ["v*"]
|
|
pull_request:
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
env:
|
|
GO_VERSION: "1.26"
|
|
ANDROID_IMAGE: cimg/android:2024.01-node
|
|
CGO_ENABLED: "0"
|
|
# Registre conteneur Gitea (ex: cname de l'instance)
|
|
REGISTRY_HOST: gitea.thirdshop.fr
|
|
|
|
jobs:
|
|
lint-backend:
|
|
runs-on: ubuntu-24.04
|
|
container: golang:${{ env.GO_VERSION }}-alpine
|
|
steps:
|
|
# golang:alpine n'a ni node ni git — requis par les actions JS
|
|
# (checkout/cache) exécutées dans le container par act_runner.
|
|
- name: Install node + git (actions JS)
|
|
run: apk add --no-cache nodejs git
|
|
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
- uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
/go/pkg/mod
|
|
~/.cache/go-build
|
|
key: go-${{ runner.os }}-${{ hashFiles('backend/go.mod', 'backend/go.sum') }}
|
|
restore-keys: |
|
|
go-${{ runner.os }}-
|
|
|
|
- run: go mod download
|
|
working-directory: backend
|
|
- run: go vet ./...
|
|
working-directory: backend
|
|
- run: go install honnef.co/go/tools/cmd/staticcheck@2026.2.1 && staticcheck ./...
|
|
working-directory: backend
|
|
|
|
lint-mobile:
|
|
runs-on: ubuntu-24.04
|
|
container: ${{ env.ANDROID_IMAGE }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
- uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
~/.gradle/caches
|
|
~/.gradle/wrapper
|
|
key: gradle-${{ runner.os }}-${{ hashFiles('mobile-kotlin/gradle/libs.versions.toml', 'mobile-kotlin/gradle.properties', 'mobile-kotlin/settings.gradle.kts', 'mobile-kotlin/build.gradle.kts', 'mobile-kotlin/app/build.gradle.kts') }}
|
|
restore-keys: |
|
|
gradle-${{ runner.os }}-
|
|
- run: ./gradlew :app:lint -q
|
|
working-directory: mobile-kotlin
|
|
|
|
test-backend:
|
|
runs-on: ubuntu-24.04
|
|
container: golang:${{ env.GO_VERSION }}-alpine
|
|
services:
|
|
postgres:
|
|
image: postgres:17-alpine
|
|
env:
|
|
POSTGRES_DB: kazier_test
|
|
POSTGRES_USER: kazier
|
|
POSTGRES_PASSWORD: kazier
|
|
options: >-
|
|
--health-cmd "pg_isready -U kazier"
|
|
--health-interval 5s
|
|
--health-timeout 3s
|
|
--health-retries 10
|
|
steps:
|
|
- name: Install node + git (actions JS)
|
|
run: apk add --no-cache nodejs git
|
|
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
- uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
/go/pkg/mod
|
|
~/.cache/go-build
|
|
key: go-${{ runner.os }}-${{ hashFiles('backend/go.mod', 'backend/go.sum') }}
|
|
restore-keys: |
|
|
go-${{ runner.os }}-
|
|
- run: |
|
|
set -euo pipefail
|
|
# dbtest fait un skip silencieux si Postgres est injoignable : on
|
|
# attend explicitement que le service accepte les connexions pour
|
|
# que le job échoue (pas skip) si PG ne monte jamais.
|
|
apk add --no-cache postgresql-client >/dev/null
|
|
for i in $(seq 1 30); do
|
|
if pg_isready -h postgres -U kazier -d kazier_test; then
|
|
exit 0
|
|
fi
|
|
sleep 1
|
|
done
|
|
echo "Postgres jamais prêt après 30s" >&2
|
|
exit 1
|
|
- run: go test ./...
|
|
working-directory: backend
|
|
env:
|
|
TEST_DATABASE_URL: postgres://kazier:kazier@postgres:5432/kazier_test?sslmode=disable
|
|
|
|
test-mobile:
|
|
runs-on: ubuntu-24.04
|
|
container: ${{ env.ANDROID_IMAGE }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
- uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
~/.gradle/caches
|
|
~/.gradle/wrapper
|
|
key: gradle-${{ runner.os }}-${{ hashFiles('mobile-kotlin/gradle/libs.versions.toml', 'mobile-kotlin/gradle.properties', 'mobile-kotlin/settings.gradle.kts', 'mobile-kotlin/build.gradle.kts', 'mobile-kotlin/app/build.gradle.kts') }}
|
|
restore-keys: |
|
|
gradle-${{ runner.os }}-
|
|
- run: ./gradlew :app:testDebugUnitTest -q
|
|
working-directory: mobile-kotlin
|
|
|
|
build-backend:
|
|
runs-on: ubuntu-24.04
|
|
container: golang:${{ env.GO_VERSION }}-alpine
|
|
needs: [lint-backend, test-backend]
|
|
steps:
|
|
- name: Install node + git (actions JS)
|
|
run: apk add --no-cache nodejs git
|
|
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
- run: |
|
|
set -euo pipefail
|
|
export VERSION="$(cat VERSION)"
|
|
CGO_ENABLED=0 GOOS=linux go build \
|
|
-trimpath \
|
|
-ldflags "-s -w -X main.version=${VERSION}" \
|
|
-o bin/kazier-server \
|
|
cmd/server/main.go
|
|
./bin/kazier-server --version
|
|
working-directory: backend
|
|
# v4 demande le service d'artefacts v2 (@actions/artifact v2) non fourni
|
|
# par Gitea (détecté comme GHES → GHESNotSupportedError). v3 reste le
|
|
# protocole legacy supporté par l'API artefacts de Gitea.
|
|
- uses: actions/upload-artifact@v3
|
|
with:
|
|
name: kazier-server
|
|
path: backend/bin/kazier-server
|
|
if-no-files-found: error
|
|
|
|
docker:
|
|
runs-on: ubuntu-24.04
|
|
# `build-backend` n'est qu'un garde-fou : le job docker ne télécharge pas
|
|
# son artifact, le Dockerfile recompile le binaire lui-même (build local
|
|
# autonome et reproductible). Le `needs` interdit juste de construire une
|
|
# image si lint + test + build échouent.
|
|
needs: [build-backend]
|
|
# Push branches uniquement : pas sur PR (pas de build d'image à la review),
|
|
# pas sur tag (c'est release.yml qui construit, évite une course dans le
|
|
# registre entre le job `docker` et `release-docker`).
|
|
if: github.event_name == 'push' && github.ref_type == 'branch'
|
|
# Daemon Docker de l'hôte du runner via socket monté (pas de DinD :
|
|
# act_runner ne supporte pas `services.docker:docker-dind + --privileged`
|
|
# de façon fiable — le daemon TCP 2375 restait injoignable après 60s).
|
|
# Prérequis runner : mount autorisé (valid_volumes inclut /var/run/docker.sock).
|
|
container:
|
|
image: docker:27
|
|
options: -v /var/run/docker.sock:/var/run/docker.sock
|
|
env:
|
|
DOCKER_HOST: unix:///var/run/docker.sock
|
|
steps:
|
|
- name: Install node + git (actions JS)
|
|
run: apk add --no-cache nodejs git
|
|
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
- name: Sanity daemon Docker hôte
|
|
run: |
|
|
set -euo pipefail
|
|
docker info >/dev/null
|
|
echo "daemon Docker hôte joignable"
|
|
|
|
- name: Login registre Gitea
|
|
env:
|
|
CONTAINER_REGISTRY_TOKEN: ${{ secrets.CONTAINER_REGISTRY_TOKEN }}
|
|
CONTAINER_REGISTRY_USER: ${{ secrets.CONTAINER_REGISTRY_USER }}
|
|
run: |
|
|
set -euo pipefail
|
|
: "${CONTAINER_REGISTRY_TOKEN:?CONTAINER_REGISTRY_TOKEN manquant (PAT scope write:package)}"
|
|
: "${CONTAINER_REGISTRY_USER:?CONTAINER_REGISTRY_USER manquant (propriétaire du PAT)}"
|
|
echo "$CONTAINER_REGISTRY_TOKEN" | docker login "$REGISTRY_HOST" -u "$CONTAINER_REGISTRY_USER" --password-stdin
|
|
# Le registre impose un namespace minuscule (github.repository_owner
|
|
# peut être `Thirdshop` avec une majuscule → tag Docker invalide).
|
|
OWNER_LC="$(printf '%s' "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')"
|
|
echo "REGISTRY_IMAGE=${REGISTRY_HOST}/${OWNER_LC}/kazier" >> "$GITHUB_ENV"
|
|
echo "SHA_TAG=sha-$(printf '%s' "$GITHUB_SHA" | cut -c1-7)" >> "$GITHUB_ENV"
|
|
|
|
- name: Build + push (registre Gitea)
|
|
run: |
|
|
set -euo pipefail
|
|
# --pull : base alpine/golang fraîche ; --cache-from : réutilise les
|
|
# layers du dernier build `main` si dispo (build plus rapide).
|
|
docker pull "$REGISTRY_IMAGE:main" 2>/dev/null || true
|
|
docker build \
|
|
--pull \
|
|
--cache-from "$REGISTRY_IMAGE:main" \
|
|
--build-arg VERSION="$(cat VERSION)" \
|
|
--build-arg BUILD_DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
|
|
-t "$REGISTRY_IMAGE:main" \
|
|
-t "$REGISTRY_IMAGE:$SHA_TAG" \
|
|
./backend
|
|
docker run --rm "$REGISTRY_IMAGE:$SHA_TAG" --version
|
|
docker push "$REGISTRY_IMAGE:main"
|
|
docker push "$REGISTRY_IMAGE:$SHA_TAG" |