watchparty/.forgejo/workflows/publish-docker.yml
Nicolas fc678b313c
Some checks failed
Publier l'image Docker / test (push) Failing after 11s
Publier l'image Docker / publish (push) Has been skipped
Add a real server test suite and gate CI's Docker publish on it
- server/test/*.test.ts: formalizes this project's many ad-hoc scratchpad
  test scripts into a committed suite, one file per service
  (musicQueueService, partyService, socketGateway, catalogService), using
  Node's built-in node:test + node:assert/strict - zero new dependencies.
  Runs straight against TypeScript source via `tsx --test` (npm test), no
  compile step.
- server/tsconfig.test.json: extends the base config, overrides rootDir to
  "." and adds test/**/*.ts to include, so `npm run typecheck` covers the
  test files too without pulling them into dist/ (npm run build still
  uses the unmodified base tsconfig, scoped to src/ only).
- server/package.json: typecheck now runs against tsconfig.test.json; new
  test script.
- .forgejo/workflows/publish-docker.yml: new `test` job (node:20-alpine
  container - the publish job's docker:27-cli has no Node) running server
  typecheck+test and client typecheck+build; publish now depends on it via
  needs: test. Removed the stale "no test suite yet" comment.
- README.md, docs/architecture.md: documented the test suite, how to run
  it locally, and the new CI job/gating.

Verified locally: server typecheck, server test (25/25 passing), server
build, client typecheck, and client build all pass individually - the
same commands the new CI job runs.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-14 09:57:47 +02:00

149 lines
5.1 KiB
YAML

# Build et publie l'image Docker de Watch Party sur le registre de
# conteneurs Forgejo :
# git.dev.kyuno.fr/kyuno/watchparty
#
# - push sur `master` -> tags `latest` + `<sha court>`
# - push d'un tag `vX.Y.Z` -> tags `X.Y.Z`, `X.Y`, `latest`
# - déclenchement manuel possible (Actions -> Run workflow)
#
# Repris de mediaDrop (.forgejo/workflows/publish-docker.yml) - mêmes
# prérequis côté instance :
# 1. Actions activé pour le dépôt : Settings -> Actions -> Enable.
# 2. Un runner enregistré avec le label `ubuntu-latest`, capable de lancer
# `docker` dans les jobs conteneurisés (socket hôte monté dans le
# runner - voir la config qui fait déjà tourner mediaDrop).
# 3. Registre : secret REGISTRY_TOKEN (déjà présent sur CE dépôt au moment
# où ce fichier a été écrit) - un jeton avec les scopes write:package/
# read:package (Forgejo -> Settings -> Applications), le jeton
# automatique de l'Action n'a pas ce droit.
#
# Deux jobs :
# - test : typecheck + tests serveur (node:test, voir server/test/) et
# typecheck + build client, dans un conteneur node:20-alpine
# (docker:27-cli n'a pas Node, donc un conteneur séparé).
# - publish : build + push l'image Docker, seulement si `test` passe
# (needs: test) - clone les sources une seconde fois dans son
# propre conteneur, les deux jobs ne partagent pas de filesystem.
name: Publier l'image Docker
on:
push:
branches: [master]
tags: ['v*']
workflow_dispatch:
permissions:
contents: read
packages: write
env:
REGISTRY: git.dev.kyuno.fr
IMAGE: git.dev.kyuno.fr/${{ github.repository_owner }}/watchparty
jobs:
test:
runs-on: ubuntu-latest
container:
image: node:20-alpine
steps:
# node:20-alpine n'a pas git préinstallé - même approche de clone
# manuel que le job publish (pas d'actions/checkout, action JS qui a
# ses propres soucis dans les conteneurs Alpine minimalistes ici).
- name: Récupérer les sources
run: |
set -eu
apk add --no-cache git
git init -q
git remote add origin "${{ github.server_url }}/${{ github.repository }}.git"
git fetch -q --depth 1 origin "${{ github.ref_name }}"
git checkout -q FETCH_HEAD
- name: Serveur - installer les dépendances
working-directory: server
run: npm ci
- name: Serveur - vérifier les types (src/ + test/)
working-directory: server
run: npm run typecheck
- name: Serveur - lancer la suite de tests
working-directory: server
run: npm test
- name: Client - installer les dépendances
working-directory: client
run: npm ci
- name: Client - vérifier les types
working-directory: client
run: npm run typecheck
- name: Client - build (esbuild)
working-directory: client
run: npm run build
publish:
needs: test
runs-on: ubuntu-latest
container:
image: docker:27-cli
steps:
# `docker:27-cli` (Alpine) n'a pas Node : pas d'actions/checkout
# (action JS) possible ici. Clone Git direct du dépôt, comme mediaDrop.
- name: Récupérer les sources
run: |
set -eu
apk add --no-cache git
git init -q
git remote add origin "${{ github.server_url }}/${{ github.repository }}.git"
git fetch -q --depth 1 origin "${{ github.ref_name }}"
git checkout -q FETCH_HEAD
- name: Calculer les tags
id: tags
run: |
set -eu
if [ "${{ github.ref_type }}" = "tag" ]; then
v="${{ github.ref_name }}"
v="${v#v}"
list="${IMAGE}:${v} ${IMAGE}:${v%.*} ${IMAGE}:latest"
else
short="$(echo "${{ github.sha }}" | cut -c1-12)"
list="${IMAGE}:latest ${IMAGE}:${short}"
fi
echo "list=${list}" >> "$GITHUB_OUTPUT"
echo "Tags : ${list}"
- name: Connexion au registre
run: |
set -eu
if [ -z "${{ secrets.REGISTRY_TOKEN }}" ]; then
echo "Secret REGISTRY_TOKEN manquant (voir l'en-tête du workflow)." >&2
exit 1
fi
echo "${{ secrets.REGISTRY_TOKEN }}" | \
docker login "$REGISTRY" -u "${{ github.repository_owner }}" --password-stdin
- name: Build
run: |
set -eu
args=""
for t in ${{ steps.tags.outputs.list }}; do args="$args -t $t"; done
# Contexte = racine du dépôt (le Dockerfile copie aussi client/) -
# shellcheck disable=SC2086
docker build $args \
-f server/Dockerfile \
--label "org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}" \
--label "org.opencontainers.image.revision=${{ github.sha }}" \
--label "org.opencontainers.image.created=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
.
- name: Push
run: |
set -eu
for t in ${{ steps.tags.outputs.list }}; do docker push "$t"; done
- name: Déconnexion
if: always()
run: docker logout "$REGISTRY"