# 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` : le service `docker:27-dind` est lancé avec # `options: --privileged` (obligatoire pour DinD) et `DOCKER_TLS_CERTDIR: ""` # (sinon l'image écoute en TLS sur 2376 et non en clair sur 2375). # - 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.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') }} 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.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') }} 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' container: image: docker:27 env: DOCKER_HOST: tcp://docker:2375 DOCKER_TLS_CERTDIR: "" services: docker: image: docker:27-dind env: DOCKER_TLS_CERTDIR: "" options: >- --privileged --health-cmd "docker info" --health-interval 5s --health-timeout 5s --health-retries 12 --health-start-period 5s steps: - name: Install node + git (actions JS) run: apk add --no-cache nodejs git - uses: actions/checkout@v4 with: token: ${{ secrets.GITEA_TOKEN }} - name: Attendre le daemon Docker (dind) env: DOCKER_HOST: tcp://docker:2375 run: | set -euo pipefail for i in $(seq 1 30); do if docker info >/dev/null 2>&1; then echo "daemon Docker prêt" exit 0 fi sleep 2 done echo "Daemon Docker injoignable après 60s" >&2 docker info >&2 || true exit 1 - 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 echo "REGISTRY_IMAGE=${REGISTRY_HOST}/${{ github.repository_owner }}/kazier" >> "$GITHUB_ENV" echo "IMAGE_TAG=${GITHUB_REF_NAME}" >> "$GITHUB_ENV" - name: Build + push (registre Gitea) run: | set -euo pipefail docker build \ --build-arg VERSION="$(cat VERSION)" \ --build-arg BUILD_DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ -t "$REGISTRY_IMAGE:$IMAGE_TAG" \ ./backend docker run --rm "$REGISTRY_IMAGE:$IMAGE_TAG" --version docker push "$REGISTRY_IMAGE:$IMAGE_TAG"