From aea772dd509279d375798675841100bf7f91bbb2 Mon Sep 17 00:00:00 2001 From: noiemany <51255434+compnew2006@users.noreply.github.com> Date: Mon, 23 Nov 2026 22:00:12 +0200 Subject: [PATCH 1/2] ci: gate package publication on same-commit checks --- .github/workflows/ci.yml | 5 ++ .github/workflows/packaging-smoke.yml | 5 +- .github/workflows/release.yml | 52 +++++++++++++++++--- tests/test_workflow_gates.py | 71 +++++++++++++++++++++++++++ 4 files changed, 124 insertions(+), 9 deletions(-) create mode 100644 tests/test_workflow_gates.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8e3443..a816eab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,8 @@ name: CI on: + workflow_call: + push: branches: - '**' @@ -22,6 +24,9 @@ on: - '.gitignore' - '.agents/**' +permissions: + contents: read + concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true diff --git a/.github/workflows/packaging-smoke.yml b/.github/workflows/packaging-smoke.yml index 3695ee1..8617f35 100644 --- a/.github/workflows/packaging-smoke.yml +++ b/.github/workflows/packaging-smoke.yml @@ -4,12 +4,13 @@ name: Packaging smoke test on: + workflow_call: workflow_dispatch: pull_request: - paths: ['packaging/**', 'scripts/**', 'quota/updater.py', '.github/workflows/**'] + paths: ['packaging/**', 'scripts/**', 'core/**', 'quota/**', 'api/**', 'web/**', 'run.py', 'bin/**', 'requirements-linux.txt', 'LICENSE', '.github/workflows/**'] push: branches: [main] - paths: ['packaging/**', 'scripts/**', 'quota/updater.py', '.github/workflows/**'] + paths: ['packaging/**', 'scripts/**', 'core/**', 'quota/**', 'api/**', 'web/**', 'run.py', 'bin/**', 'requirements-linux.txt', 'LICENSE', '.github/workflows/**'] permissions: contents: read diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 25d4525..8e00dd5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,10 +18,23 @@ on: - 'v*' permissions: - contents: write # needed to create the Release + attach the .deb asset + contents: read jobs: + ci: + uses: ./.github/workflows/ci.yml + permissions: + contents: read + + packaging-smoke: + uses: ./.github/workflows/packaging-smoke.yml + permissions: + contents: read + build: + needs: [ci, packaging-smoke] + permissions: + contents: read runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -95,12 +108,37 @@ jobs: } > "${RUNNER_TEMP}/release_body.md" echo "body_path=${RUNNER_TEMP}/release_body.md" >> "$GITHUB_OUTPUT" + - name: Stage packages and release notes + run: | + mkdir -p "${RUNNER_TEMP}/release-assets/dist" + cp dist/* "${RUNNER_TEMP}/release-assets/dist/" + cp "${{ steps.release_body.outputs.body_path }}" "${RUNNER_TEMP}/release-assets/release_body.md" + - uses: actions/upload-artifact@v4 + with: + name: release-assets + path: ${{ runner.temp }}/release-assets/ + if-no-files-found: error + retention-days: 1 + + publish: + needs: [ci, packaging-smoke, build] + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: write + steps: + - name: Download packages built and gated in this tag run + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 + with: + name: release-assets + path: release-assets + - name: Upload to GitHub Releases - uses: softprops/action-gh-release@v2 + uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2.6.2 with: files: | - dist/quota-manager_*.deb - dist/quota-manager-*.tar.gz - dist/quota-manager-*.rpm - dist/quota-manager-*.pkg.tar.zst - body_path: ${{ steps.release_body.outputs.body_path }} + release-assets/dist/quota-manager_*.deb + release-assets/dist/quota-manager-*.tar.gz + release-assets/dist/quota-manager-*.rpm + release-assets/dist/quota-manager-*.pkg.tar.zst + body_path: release-assets/release_body.md diff --git a/tests/test_workflow_gates.py b/tests/test_workflow_gates.py new file mode 100644 index 0000000..2221266 --- /dev/null +++ b/tests/test_workflow_gates.py @@ -0,0 +1,71 @@ +"""Release workflow contracts that prevent publishing without same-run gates.""" + +from pathlib import Path + +import yaml + +REPO = Path(__file__).resolve().parent.parent +WORKFLOWS = REPO / ".github" / "workflows" + + +def _workflow(name: str) -> dict: + data = yaml.safe_load((WORKFLOWS / name).read_text(encoding="utf-8")) + assert isinstance(data, dict) + return data + + +def _triggers(workflow: dict) -> dict: + # PyYAML's YAML 1.1 resolver parses the unquoted GitHub key `on` as True. + return workflow.get("on", workflow.get(True, {})) + + +def test_release_waits_for_ci_and_packaging_smoke_in_same_tag_run(): + release = _workflow("release.yml") + triggers = _triggers(release) + assert triggers.get("push", {}).get("tags") == ["v*"] + + jobs = release["jobs"] + gates = {name: job for name, job in jobs.items() if job.get("uses")} + assert {job["uses"] for job in gates.values()} >= { + "./.github/workflows/ci.yml", + "./.github/workflows/packaging-smoke.yml", + } + build_steps = jobs["build"]["steps"] + publish_steps = jobs["publish"]["steps"] + upload = next(step for step in build_steps if step.get("uses") == "actions/upload-artifact@v4") + download = next(step for step in publish_steps if step.get("uses") == "actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093") + assert upload["with"]["name"] == download["with"]["name"] == "release-assets" + assert "softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65" in { + step.get("uses") for step in publish_steps + } + + publishing = jobs["publish"] + assert set(publishing["needs"]) >= set(gates) + assert publishing.get("permissions") == {"contents": "write"} + assert release.get("permissions") == {"contents": "read"} + + +def test_ci_is_reusable_with_read_only_permissions(): + ci = _workflow("ci.yml") + assert "workflow_call" in _triggers(ci) + assert ci.get("permissions") == {"contents": "read"} + + +def test_packaging_smoke_covers_runtime_and_dependency_changes(): + smoke = _workflow("packaging-smoke.yml") + triggers = _triggers(smoke) + expected_paths = { + "core/**", + "quota/**", + "api/**", + "web/**", + "run.py", + "bin/**", + "requirements-linux.txt", + "LICENSE", + } + for event in ("push", "pull_request"): + paths = set(triggers[event]["paths"]) + assert expected_paths <= paths + assert "workflow_call" in triggers + assert smoke.get("permissions") == {"contents": "read"} From da7bc488a1510706efb1169238dfadc391afb3c0 Mon Sep 17 00:00:00 2001 From: Youssef Alkhodary <82382970+UserJoo9@users.noreply.github.com> Date: Tue, 24 Nov 2026 08:12:09 +0200 Subject: [PATCH 2/2] CHANGELOG: release gating from #51 (credit @compnew2006) --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fba4a10..3215d5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ match it. Release notes are composed from a version's section below.)_ Added: - **Internet schedule** (new page). Turn the internet off at set times of the week for chosen people (all their devices) or single devices: bedtime on school nights, study time, meal times. One click starts from a ready plan ("School nights", "Every night", "Study time", "Meal times"); a schedule can have several times, a time can run past midnight, and dates can be marked as days off (holidays, Eid). **Bonus time** gives a few extra minutes without changing the schedule. **Always allowed** sites (a school platform, a study site) keep working during every schedule. While a schedule is on, the device's card shows when the internet comes back, the home network (printer, shared drives, the dashboard) keeps working, and the cut is done by the gateway itself, so it works on any phone, tablet, TV or console with no app. Each device gets its end time in the system kernel, so it comes back online on time even if the gateway service restarts or stops. Sites on the "always allowed" list only open on devices that look names up through the gateway; a phone with Private DNS (or a browser with secure DNS) turned on keeps them blocked during a schedule. Contributed by @amr-elgharip2006. Closes #32. +Changed: +- A new version is now published only after all the tests and the install checks on Debian, Ubuntu, Fedora and Arch pass on exactly that version. Contributed by @compnew2006. + Fixed: - A short hiccup while the gateway updated its list of cut-off devices could switch off counting and blocking for everyone until a restart, or let a cut-off device through for a moment. The list is now changed in one step: if that step fails, the old list stays in force and the gateway simply tries again 15 seconds later. Contributed by @compnew2006. - If saving usage failed for a moment (for example the database was busy), those 15 seconds of usage were lost and the check that cuts off people over their limit was skipped for that round. The usage is now kept and saved on the next round, and the check always runs. Reported by @compnew2006 in #52.