From 40f6dbc3fd1a0afb087b1e6cc0824ccfaf946406 Mon Sep 17 00:00:00 2001 From: docker24002 <350525360+docker24002@users.noreply.github.com> Date: Sat, 31 Oct 2026 13:21:26 +0000 Subject: [PATCH] ci(#112): publier le tag exact sur un runner GitHub --- .github/workflows/ci.yml | 5 ++- .github/workflows/guard-main.yml | 2 +- .github/workflows/release.yml | 17 +++++++--- .yamllint.yaml | 21 ++++++++++++ CHANGELOG.md | 4 +++ tests/test_workflow_release.py | 57 ++++++++++++++++++++++++++++++++ 6 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 .yamllint.yaml create mode 100644 tests/test_workflow_release.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f77aa9..3ebd86c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,9 @@ jobs: - name: Checkout du dépôt uses: actions/checkout@v7 + - name: Garde-fous de publication sur tag + run: python3 tests/test_workflow_release.py + - name: Dépendances système (GTK4, introspection, Xvfb, D-Bus, GVfs) # libgirepository-2.0-dev + libcairo2-dev + pkg-config : compilation # de PyGObject/pycairo dans le venv ; gvfs + dbus : reproduction réelle @@ -69,7 +72,7 @@ jobs: # la protection de branche. needs: gtk if: ${{ !cancelled() }} - runs-on: ${{ fromJSON(vars.RUNS_ON_LINUX || '{"group":"maison","labels":["self-hosted","linux"]}') }} + runs-on: ${{ fromJSON(vars.RUNS_ON_LINUX || '"ubuntu-latest"') }} timeout-minutes: 30 steps: diff --git a/.github/workflows/guard-main.yml b/.github/workflows/guard-main.yml index f04cb86..08892a7 100644 --- a/.github/workflows/guard-main.yml +++ b/.github/workflows/guard-main.yml @@ -18,7 +18,7 @@ permissions: jobs: garde-dev-vers-main: name: "Garde : PR vers main doit venir de dev" - runs-on: ${{ fromJSON(vars.RUNS_ON_LINUX || '{"group":"maison","labels":["self-hosted","linux"]}') }} + runs-on: ${{ fromJSON(vars.RUNS_ON_LINUX || '"ubuntu-latest"') }} steps: - name: Vérifier la branche source run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e97dbe7..dfcd3df 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,6 +5,12 @@ name: Release "on": + workflow_dispatch: + inputs: + tag: + description: Tag vX.Y.Z déjà validé et livré dans main + required: true + type: string push: tags: ["v*"] @@ -14,14 +20,15 @@ permissions: jobs: release: name: Publication - runs-on: ${{ fromJSON(vars.RUNS_ON_LINUX || '{"group":"maison","labels":["self-hosted","linux"]}') }} + runs-on: ${{ fromJSON(vars.RUNS_ON_LINUX || '"ubuntu-latest"') }} env: - TAG: ${{ github.ref_name }} + TAG: ${{ inputs.tag || github.ref_name }} DEPOT: ${{ github.event.repository.name }} steps: - name: Checkout du dépôt uses: actions/checkout@v7 with: + ref: refs/tags/${{ env.TAG }} fetch-depth: 0 # python3 du runner maison trop ancien pour tomllib (Python ≥ 3.11). @@ -40,7 +47,7 @@ jobs: - name: Tag porté par main run: | git fetch --no-tags origin main - if ! git merge-base --is-ancestor "${GITHUB_SHA}" FETCH_HEAD; then + if ! git merge-base --is-ancestor "refs/tags/${TAG}^{commit}" FETCH_HEAD; then echo "::error::le commit tagué ${TAG} n'est pas sur main (passer par le relais dev → main)" exit 1 fi @@ -54,11 +61,13 @@ jobs: fi - name: Archive des sources - run: git archive --format=tar.gz --prefix="${DEPOT}-${VERSION}/" -o "${DEPOT}-${VERSION}.tar.gz" "${GITHUB_SHA}" + run: git archive --format=tar.gz --prefix="${DEPOT}-${VERSION}/" -o "${DEPOT}-${VERSION}.tar.gz" "refs/tags/${TAG}^{commit}" - name: Release GitHub uses: softprops/action-gh-release@efb35369e0ad2afab669f228072c1b0d510eae64 # v3.0.3 with: + tag_name: ${{ env.TAG }} + draft: false body_path: notes.md files: ${{ github.event.repository.name }}-*.tar.gz fail_on_unmatched_files: true diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 0000000..395caa5 --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,21 @@ +# yamllint : règles du socle Mathilde-Team +extends: default +rules: + line-length: disable # lambdas C++ et templates Jinja sur une ligne + document-start: disable + truthy: + check-keys: false # clé « on: » des workflows + allowed-values: ['true', 'false', 'yes', 'no'] # ESPHome accepte yes/no (restore_value: yes) + comments: + min-spaces-from-content: 1 + comments-indentation: disable + indentation: + spaces: 2 + indent-sequences: whatever + braces: + max-spaces-inside: 1 + brackets: + max-spaces-inside: 1 +ignore: | + .venv/ + node_modules/ diff --git a/CHANGELOG.md b/CHANGELOG.md index c34bf31..233417b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ Format : [Keep a Changelog](https://keepachangelog.com/fr/1.1.0/). Les numéros ## [Non publié] +- CI et publication : repli GitHub autorisé, publication manuelle sur un tag + déjà livré dans main, vérification d’ascendance et archives du tag exact. + + ### Modifié - **Licence** (#105) : le `LICENSE` MIT provisoire est remplacé par le texte officiel de la GPLv3, et le projet passe en GPL-3.0-or-later. Ajouts : `license` dans `pyproject.toml`, en-têtes SPDX, `License: GPL-3.0-or-later` et `%license LICENSE` dans le spec RPM, `copyright` DEP-5 installé par le `.deb`, section Licence du README avec les licences des dépendances, `tests/test_licence.py`. diff --git a/tests/test_workflow_release.py b/tests/test_workflow_release.py new file mode 100644 index 0000000..1ec69ad --- /dev/null +++ b/tests/test_workflow_release.py @@ -0,0 +1,57 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +"""Garde-fous hors réseau de la publication du tag exact depuis GitHub.""" + +import json +import unittest +from pathlib import Path + + +class PublicationSurTag(unittest.TestCase): + def setUp(self): + self.workflows = Path(__file__).resolve().parents[1] / ".github" / "workflows" + + def test_tag_explicite_et_ascendance_main(self): + texte = (self.workflows / "release.yml").read_text(encoding="utf-8") + self.assertIn(" workflow_dispatch:", texte) + self.assertIn(" TAG: ${{ inputs.tag || github.ref_name }}", texte) + self.assertIn(" ref: refs/tags/${{ env.TAG }}", texte) + self.assertIn(" fetch-depth: 0", texte) + self.assertIn("merge-base --is-ancestor", texte) + self.assertIn("refs/tags/${TAG}^{commit}", texte) + self.assertNotIn("${GITHUB_REF_NAME}", texte) + self.assertNotIn("${GITHUB_SHA}", texte) + self.assertIn(" draft: false", texte) + self.assertIn(" tag_name: ${{ env.TAG }}", texte) + self.assertIn(" fail_on_unmatched_files: true", texte) + + def test_repli_github_et_garde_main_conserves(self): + for nom in ("ci.yml", "guard-main.yml", "release.yml"): + texte = (self.workflows / nom).read_text(encoding="utf-8") + repli = "fromJSON(vars.RUNS_ON_LINUX || '\"ubuntu-latest\"')" + direct = any( + ligne.strip() + in ( + "runs-on: ubuntu-latest", + "runs-on: ubuntu-24.04", + "runs-on: ubuntu-26.04", + ) + for ligne in texte.splitlines() + ) + self.assertTrue(repli in texte or direct) + garde = (self.workflows / "guard-main.yml").read_text(encoding="utf-8") + self.assertIn("Garde : PR vers main doit venir de dev", garde) + self.assertIn('!= "dev"', garde) + ci = (self.workflows / "ci.yml").read_text(encoding="utf-8") + regle = json.loads((self.workflows.parent / "branch-protection" / "dev.json").read_text(encoding="utf-8"))[ + "required_status_checks" + ] + contextes = [check["context"] for check in regle.get("checks", [])] + contextes.extend(regle.get("contexts", [])) + self.assertTrue(contextes) + for contexte in contextes: + self.assertIn(contexte, ci + "\n" + garde) + self.assertIn("run: python3 tests/test_workflow_release.py", ci) + + +if __name__ == "__main__": + unittest.main()