Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: CI

on:
workflow_call:

push:
branches:
- '**'
Expand All @@ -22,6 +24,9 @@ on:
- '.gitignore'
- '.agents/**'

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/packaging-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 45 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
71 changes: 71 additions & 0 deletions tests/test_workflow_gates.py
Original file line number Diff line number Diff line change
@@ -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"}
Loading