Discovered while opening the first-ever PR against this repo (previous sessions always pushed straight to master): publish-docker.yml only ever triggered on push (branches: [master]) or a tag - there was no pull_request trigger at all, so a PR sat with zero CI signal until whatever merged it also happened to push to master for the first time. Added pull_request (branches: [master]) alongside the existing triggers. The publish job needed its own guard for this to be safe - it has no event-type check today, just needs: test, so without one, a PR's own CI run would have gone on to build and push a real Docker image (latest included) to the production registry from unreviewed, unmerged code. if: github.event_name != 'pull_request' keeps a PR run to the test job alone; push/tag/workflow_dispatch are unaffected. Note: a pull_request trigger only takes effect once it exists on the BASE branch (master) - GitHub/Forgejo Actions won't run a trigger a PR branch merely adds to its own copy of the workflow, for the obvious reason (a PR from anywhere could otherwise grant itself a run with repo secrets). So this doesn't give the PR carrying it its own CI run - only the next one, once this merges. Verified by reading the existing workflow and the job dependency it already had (needs: test with no event guard); not verified against a real PR run (can't be, until this lands on master) - flagged the same way this project already flags what it can't check from here. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
155 lines
5.4 KiB
YAML
155 lines
5.4 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)
|
|
# - PR vers `master` -> job `test` seul (voir `if` du job `publish` -
|
|
# sans ça, une PR depuis une branche non fusionnée pousserait quand même
|
|
# une vraie image sur le registre, `latest` compris)
|
|
#
|
|
# 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*']
|
|
pull_request:
|
|
branches: [master]
|
|
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
|
|
if: github.event_name != 'pull_request'
|
|
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"
|