Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
ci(release): tags carry a frontend bundle built from their own sources (#939)
Ruben Lütke759b5227ae70
diff --git a/.github/workflows/release-cut.yml b/.github/workflows/release-cut.ymlindex 1b006c393d..9afb218c43 100644--- a/.github/workflows/release-cut.yml+++ b/.github/workflows/release-cut.yml@@ -9,7 +9,10 @@# Conventional Commits since the last tag),# 3. checks the version commit through a candidate PR, then lands it through# main's merge queue and waits for the landed commit,-# 4. pushes the annotated tag; the three publishing workflows (PyPI, desktop+# 4. builds the frontend bundle from that commit (a job without secrets),+# commits it on top as the tag's only extra commit, so the tag carries a+# bundle built from its own sources while main need not track one, and+# pushes the annotated tag; the three publishing workflows (PyPI, desktop# installers, signed installer) run on it. Each of them starts with# release-gate.yml, which waits for CI on the release commit.# 5. publishes the GitHub Release with the notes and the resumable@@ -19,7 +22,7 @@# users.# 6. runs release-smoke.yml against the published release (read-only).#-# Release bot. The `cut` job runs in the `release-cut` environment, which only+# Release bot. The `cut` and `tag` jobs run in the `release-cut` environment, which only# main may deploy to. That environment holds the private key of the release# bot GitHub App (secret RELEASE_APP_PRIVATE_KEY, variable RELEASE_APP_ID). The# job mints short-lived installation tokens from it to push the candidate@@ -75,8 +78,7 @@ jobs:checks: readoutputs:version: ${{ steps.bump.outputs.version || steps.resume.outputs.version }}- # The public v* tag exists from here on (pushed now or by an earlier run).- tagged: ${{ steps.tag.outcome == 'success' }}+ sha: ${{ steps.admit.outputs.sha }}env:# Reads and dispatches use GITHUB_TOKEN. Each write step overrides# GH_TOKEN with a bot token minted right before it: an installation@@ -239,6 +241,7 @@ jobs:# main drops it while it still waits for a runner.GH_TOKEN="$DISPATCH_TOKEN" gh workflow run ci.yml --ref main -f full=true -f include_macos=true- name: Admit the release commit+ id: admitenv:V: ${{ steps.bump.outputs.version || steps.resume.outputs.version }}run: |@@ -247,6 +250,98 @@ jobs:actual="$(python -c 'from scripts.ci.release_admit import versions; print(versions()[0])')"[ "$actual" = "$V" ] || { echo "::error::Merged package version changed."; exit 1; }python scripts/ci/release_admit.py --ci-only --sha "$sha" --repo "$GITHUB_REPOSITORY"+ echo "sha=$sha" >> "$GITHUB_OUTPUT"++ # The frontend bundle the release ships, built from the admitted commit.+ # No secrets and a read-only token: npm runs here and nowhere near the+ # release bot key. The tag job below commits the result on top of the+ # release commit, so the tag (what the updater, the installers and PyPI+ # read) always carries a bundle built from its own sources, while main does+ # not have to track one.+ bundle:+ name: build the release frontend bundle+ needs: cut+ runs-on: ubuntu-latest+ timeout-minutes: 20+ permissions:+ contents: read+ steps:+ - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0+ with:+ fetch-depth: 0+ persist-credentials: false+ - name: Move to the admitted commit, which must be on main+ env:+ SHA: ${{ needs.cut.outputs.sha }}+ run: |+ set -euo pipefail+ [[ "$SHA" =~ ^[0-9a-f]{40}$ ]] || { echo "::error::Not a commit SHA."; exit 1; }+ # Only reviewed code that landed on main gets built here.+ git fetch --quiet --no-tags origin main:refs/remotes/origin/main+ git merge-base --is-ancestor "$SHA" origin/main+ git checkout --quiet --detach "$SHA"+ - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0+ with:+ node-version: "22"+ # No dependency cache: a release build must not read or seed a+ # cache other runs share (CodeQL actions/cache-poisoning).+ package-manager-cache: false+ - name: Build+ working-directory: dodaios/ui/web/frontend+ # `npm run build` empties dist/ first, so it holds exactly this build.+ run: |+ npm ci+ npm run build+ - name: Startup bundle budget+ run: python3 scripts/ci/check_frontend_bundle_budget.py+ - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2+ with:+ name: release-frontend-bundle+ path: dodaios/ui/web/dist+ include-hidden-files: true+ if-no-files-found: error+ retention-days: 7++ tag:+ name: tag release+ needs: [cut, bundle]+ # Holds the release bot key; its deployment policy admits main only.+ environment: release-cut+ runs-on: ubuntu-latest+ timeout-minutes: 30+ permissions:+ contents: write+ actions: write+ outputs:+ # The public v* tag exists from here on (pushed now or by an earlier run).+ tagged: ${{ steps.tag.outcome == 'success' }}+ env:+ GH_TOKEN: ${{ github.token }}+ TOKEN_IS_BOT: ${{ vars.RELEASE_APP_ID == '' }}+ V: ${{ needs.cut.outputs.version }}+ SHA: ${{ needs.cut.outputs.sha }}+ DIST: dodaios/ui/web/dist+ steps:+ - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0+ with:+ fetch-depth: 0+ ref: ${{ needs.cut.outputs.sha }}+ persist-credentials: false+ - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0+ with:+ python-version: "3.11"+ - name: Let git push with the step's token+ run: gh auth setup-git --hostname github.com+ - name: Put the release bundle in place+ run: |+ set -euo pipefail+ [ "$(git rev-parse HEAD)" = "$SHA" ] || { echo "::error::Checkout is not the admitted commit."; exit 1; }+ rm -rf "$DIST"+ mkdir -p "$DIST"+ - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2+ with:+ name: release-frontend-bundle+ path: dodaios/ui/web/dist- name: Mint a release bot token for the tagid: tag-tokenif: vars.RELEASE_APP_ID != ''@@ -258,25 +353,49 @@ jobs:- name: Tag the admitted releaseid: tagenv:- V: ${{ steps.bump.outputs.version || steps.resume.outputs.version }}# The "release tags" ruleset lets only the release bot and admins# create v* tags.GH_TOKEN: ${{ steps.tag-token.outputs.token || github.token }}run: |- sha="$(git rev-parse HEAD)"+ set -euo pipefailgit config user.name "jarvis-release[bot]"git config user.email "41898282+github-actions[bot]@users.noreply.github.com"if git show-ref --verify --quiet "refs/tags/v$V"; then- [ "$(git rev-parse "v$V^{}")" = "$sha" ] || { echo "::error::The tag already names another commit."; exit 1; }+ # A resumed cut: the tag names the admitted commit itself (older+ # releases) or its one bundle commit.+ tagged="$(git rev-parse "v$V^{}")"+ if [ "$tagged" != "$SHA" ] && [ "$(git rev-parse "$tagged^")" != "$SHA" ]; then+ echo "::error::The tag already names another commit."+ exit 1+ fiecho 'pushed=false' >> "$GITHUB_OUTPUT"- else- git tag -a "v$V" -m "v$V"- git push origin "v$V"- echo 'pushed=true' >> "$GITHUB_OUTPUT"+ exit 0fi+ # -f: main may ignore dist/; the tag still has to carry it.+ git add -f -A -- "$DIST"+ outside=""+ while IFS= read -r path; do+ case "$path" in+ "" | "$DIST"/*) ;;+ *) outside="$outside$path"$'\n' ;;+ esac+ done < <(git diff --cached --name-only)+ if [ -n "$outside" ]; then+ echo "::error::The bundle touched files outside $DIST:"+ echo "$outside"+ exit 1+ fi+ if ! git diff --cached --quiet; then+ python3 scripts/ci/check_dist_consistency.py --staged --prune+ python3 scripts/ci/check_dist_consistency.py --staged+ git diff --cached --shortstat+ git commit -q -m "chore(release): frontend bundle for v$V"+ fi+ git tag -a "v$V" -m "v$V"+ git push origin "v$V"+ echo 'pushed=true' >> "$GITHUB_OUTPUT"- name: Dispatch the publishing workflows on the tagenv:- V: ${{ steps.bump.outputs.version || steps.resume.outputs.version }}TAG_PUSHED: ${{ steps.tag.outputs.pushed }}run: |# ci.yml has no tag trigger; dispatch full CI on the immutable tag.@@ -290,7 +409,7 @@ jobs:publish:name: publish GitHub Release- needs: cut+ needs: [cut, tag]concurrency:group: release-finalize-v${{ needs.cut.outputs.version }}cancel-in-progress: false@@ -329,8 +448,8 @@ jobs:# with the recovery steps.stranded:name: report a stranded tag- needs: [cut, publish]- if: always() && needs.cut.outputs.tagged == 'true' && needs.publish.result != 'success'+ needs: [cut, tag, publish]+ if: always() && needs.tag.outputs.tagged == 'true' && needs.publish.result != 'success'runs-on: ubuntu-latesttimeout-minutes: 5permissions:diff --git a/docs/ci-pipeline.md b/docs/ci-pipeline.mdindex 3d0c8042b0..d73014c932 100644--- a/docs/ci-pipeline.md+++ b/docs/ci-pipeline.md@@ -427,7 +427,14 @@ A release happens **only** when the maintainer asks for one.the Conventional Commits since the last tag) into a dated CHANGELOG section(`scripts/ci/cut_release.py`), lands the candidate through a CI-checked PRand the merge queue, tags the landed commit, and dispatches full CI with macOS on that- immutable tag. Its `cut` job runs in the `release-cut` environment, which+ immutable tag. The tag carries the frontend bundle built from its own+ sources: the `bundle` job (no secrets, read-only token) runs `npm ci && npm+ run build` on the landed commit, and the `tag` job commits that+ `dodaios/ui/web/dist` on top as the tag's one extra commit (no commit when+ main's copy is already identical). `release_admit.py` admits a tag on main+ or exactly that shape: one parent on main, changes only under+ `dodaios/ui/web/dist/`. So installs and updates always get a matching UI, and+ main does not have to track the bundle. Its `cut` and `tag` jobs run in the `release-cut` environment, whichonly `main` may deploy to and which holds the private key of the releasebot GitHub App (secret `RELEASE_APP_PRIVATE_KEY`, variable`RELEASE_APP_ID`). Right before each write (candidate push and PR, merge,diff --git a/scripts/ci/check_workflow_policy.py b/scripts/ci/check_workflow_policy.pyindex 40d6afd914..5745cb29af 100644--- a/scripts/ci/check_workflow_policy.py+++ b/scripts/ci/check_workflow_policy.py@@ -57,18 +57,31 @@ def audit(workflows: dict[str, dict]) -> list[str]:def _release_bot_findings(workflows: dict[str, dict]) -> list[str]:- """Only release-cut's main-only job may hold the key that creates v* tags."""+ """Only release-cut's main-only jobs may hold the key that creates v* tags."""findings = []+ key_jobs = {"cut", "tag"}for filename, workflow in workflows.items():for name, job in workflow.get("jobs", {}).items():- if filename == "release-cut.yml" and name == "cut":+ if filename == "release-cut.yml" and name in key_jobs:continueif "RELEASE_APP_PRIVATE_KEY" in yaml.safe_dump(job):findings.append(f"{filename}/{name}: only release-cut may use the release bot key")- cut = workflows["release-cut.yml"]["jobs"]["cut"]- if cut.get("environment") != "release-cut":- findings.append("release-cut.yml: the cut job must run in the release-cut environment")- tag = next((s for s in cut["steps"] if s.get("name") == "Tag the admitted release"), {})+ jobs = workflows["release-cut.yml"]["jobs"]+ for name in sorted(key_jobs):+ if jobs.get(name, {}).get("environment") != "release-cut":+ findings.append(+ f"release-cut.yml: the {name} job must run in the release-cut environment"+ )+ # npm runs in the bundle job; it must never see a secret or a write token.+ bundle = jobs.get("bundle", {})+ if bundle.get("environment") or bundle.get("permissions") != {"contents": "read"}:+ findings.append(+ "release-cut.yml: the bundle job must have no environment and read-only contents"+ )+ if "secrets." in yaml.safe_dump(bundle):+ findings.append("release-cut.yml: the bundle job must not read secrets")+ tag_steps = jobs.get("tag", {}).get("steps", [])+ tag = next((s for s in tag_steps if s.get("name") == "Tag the admitted release"), {})if "steps.tag-token.outputs.token" not in str(tag.get("env", {}).get("GH_TOKEN", "")):findings.append("release-cut.yml: push the release tag with the release bot token")return findingsdiff --git a/scripts/ci/release_admit.py b/scripts/ci/release_admit.pyindex 5e67fdd51b..2a26667e47 100644--- a/scripts/ci/release_admit.py+++ b/scripts/ci/release_admit.py@@ -8,7 +8,9 @@ runs this first through ``.github/workflows/release-gate.yml``. It checks:``dodaios.__version__``;2. ``CHANGELOG.md`` has a ``## [X.Y.Z]`` section;3. the tagged commit is reachable from ``origin/main`` (no release from an- unmerged branch);+ unmerged branch), or is the one bundle commit release-cut puts on top of+ such a commit: a single parent on main and changes only under+ ``dodaios/ui/web/dist/``;4. the latest trusted CI workflow run on that exact commit concluded success,including ``CI gate`` and release-only qualification. Release-cut dispatchesfull CI on the immutable tag and admission waits while it is still running.@@ -37,6 +39,8 @@ from dodaios.core.process_utils import NO_WINDOW_CREATIONFLAGS # noqa: E402GATE_CHECK = "CI gate"QUALIFICATION_CHECK = "release qualification"CI_WORKFLOW = ".github/workflows/ci.yml"+#: The only path the release bundle commit on top of a main commit may touch.+BUNDLE_PREFIX = "dodaios/ui/web/dist/"def versions(root: Path = REPO_ROOT) -> tuple[str, str]:@@ -161,12 +165,38 @@ def check_commit(tag: str, sha: str) -> list[str]:tagged = run_command(["git", "rev-parse", f"refs/tags/{tag}^{{commit}}"]).stdout.strip()if head != sha or tagged != sha:return ["checkout, release tag and requested SHA do not identify the same commit"]- run_command(["git", "merge-base", "--is-ancestor", sha, "origin/main"])+ if not on_main_or_bundle(sha):+ return ["release commit is neither on origin/main nor its one bundle commit"]except (subprocess.SubprocessError, OSError):return ["cannot verify release ancestry against freshly fetched origin/main"]return []+def on_main_or_bundle(sha: str, main: str = "origin/main") -> bool:+ """True for a commit on ``main``, or for release-cut's bundle commit on one.++ The bundle commit has exactly one parent, that parent is on ``main``, and+ every path it changes sits under :data:`BUNDLE_PREFIX`. Anything else+ could smuggle code into a release that main's CI never saw.+ """+ if _is_ancestor(sha, main):+ return True+ parents = run_command(["git", "rev-list", "--parents", "-n", "1", sha]).stdout.split()[1:]+ if len(parents) != 1 or not _is_ancestor(parents[0], main):+ return False+ changed = run_command(+ ["git", "diff-tree", "-r", "--no-commit-id", "--name-only", "--no-renames", parents[0], sha]+ ).stdout.splitlines()+ return bool(changed) and all(path.startswith(BUNDLE_PREFIX) for path in changed)+++def _is_ancestor(sha: str, main: str) -> bool:+ proc = run_command(["git", "merge-base", "--is-ancestor", sha, main], check=False)+ if proc.returncode not in (0, 1):+ raise subprocess.CalledProcessError(proc.returncode, proc.args, proc.stdout, proc.stderr)+ return proc.returncode == 0++def wait_for_ci(repo: str,sha: str,diff --git a/scripts/ci/release_assets.py b/scripts/ci/release_assets.pyindex 8c507f4ebc..cf0a0aa0da 100644--- a/scripts/ci/release_assets.py+++ b/scripts/ci/release_assets.py@@ -17,7 +17,12 @@ ROOT = Path(__file__).resolve().parents[2]if str(ROOT) not in sys.path:sys.path.insert(0, str(ROOT))-from scripts.ci.release_admit import api_pages, gate_state, run_command # noqa: E402+from scripts.ci.release_admit import ( # noqa: E402+ api_pages,+ gate_state,+ on_main_or_bundle,+ run_command,+)PUBLISHERS = ("release.yml", "desktop-installers.yml", "sign-installer.yml")PUBLISHER_JOBS = {@@ -675,7 +680,8 @@ def main(argv: list[str] | None = None) -> int:sha = run_command(["git", "rev-parse", f"refs/tags/{args.tag}^{{commit}}"]).stdout.strip()if args.sha and sha != args.sha:raise ValueError("release tag moved away from the publisher's commit")- run_command(["git", "merge-base", "--is-ancestor", sha, "origin/main"])+ if not on_main_or_bundle(sha):+ raise ValueError("release tag is neither on main nor its one bundle commit")if args.command == "dispatch":dispatch_missing_publishers(args.repo, args.tag, sha)return 0diff --git a/tests/unit/ci/test_pipeline_audit.py b/tests/unit/ci/test_pipeline_audit.pyindex 36f71ec00e..6ba749bb7a 100644--- a/tests/unit/ci/test_pipeline_audit.py+++ b/tests/unit/ci/test_pipeline_audit.py@@ -915,6 +915,14 @@ def test_workflow_security_policy_and_mutation_regressions():{"uses": "actions/checkout@v4"}),lambda w: w["release-cut.yml"]["jobs"]["cut"].pop("environment"),+ lambda w: w["release-cut.yml"]["jobs"]["tag"].pop("environment"),+ lambda w: w["release-cut.yml"]["jobs"]["bundle"].update({"environment": "release-cut"}),+ lambda w: w["release-cut.yml"]["jobs"]["bundle"]["permissions"].update(+ {"contents": "write"}+ ),+ lambda w: w["release-cut.yml"]["jobs"]["bundle"]["steps"][0].update(+ {"env": {"KEY": "${{ secrets.MERGE_APP_PRIVATE_KEY }}"}}+ ),lambda w: _release_cut_step(w, "Tag the admitted release")["env"].update({"GH_TOKEN": "${{ github.token }}"}),@@ -928,30 +936,38 @@ def test_workflow_security_policy_and_mutation_regressions():def _release_cut_step(definitions: dict, name: str) -> dict:- steps = definitions["release-cut.yml"]["jobs"]["cut"]["steps"]+ jobs = definitions["release-cut.yml"]["jobs"]+ steps = [step for job in jobs.values() for step in job.get("steps", [])]return next(step for step in steps if step.get("name") == name)def test_release_cut_writes_with_fresh_bot_tokens_and_reads_with_github_token():definitions = workflows()- cut = definitions["release-cut.yml"]["jobs"]["cut"]- assert cut["environment"] == "release-cut"- assert cut["env"]["GH_TOKEN"] == "${{ github.token }}" # noqa: S105 - expression- assert cut["env"]["TOKEN_IS_BOT"] == "${{ vars.RELEASE_APP_ID == '' }}" # noqa: S105- checkout = cut["steps"][0]- assert checkout["uses"].startswith("actions/checkout@")- assert checkout["with"]["persist-credentials"] is False+ jobs = definitions["release-cut.yml"]["jobs"]+ for job in (jobs["cut"], jobs["tag"]):+ assert job["environment"] == "release-cut"+ assert job["env"]["GH_TOKEN"] == "${{ github.token }}" # noqa: S105 - expression+ assert job["env"]["TOKEN_IS_BOT"] == "${{ vars.RELEASE_APP_ID == '' }}" # noqa: S105+ checkout = job["steps"][0]+ assert checkout["uses"].startswith("actions/checkout@")+ assert checkout["with"]["persist-credentials"] is False# Every write step mints its own token right before it (one-hour lifetime).- for writer, minter in (- ("Open the candidate PR", "candidate-token"),- ("Land the candidate", "land-token"),- ("Tag the admitted release", "tag-token"),+ for job, writer, minter in (+ ("cut", "Open the candidate PR", "candidate-token"),+ ("cut", "Land the candidate", "land-token"),+ ("tag", "Tag the admitted release", "tag-token"),):- names = [step.get("name") for step in cut["steps"]]- assert cut["steps"][names.index(writer) - 1].get("id") == minter+ steps = jobs[job]["steps"]+ names = [step.get("name") for step in steps]+ assert steps[names.index(writer) - 1].get("id") == mintertoken = _release_cut_step(definitions, writer)["env"]["GH_TOKEN"]assert token == f"${{{{ steps.{minter}.outputs.token || github.token }}}}"- minters = [s for s in cut["steps"] if s.get("id", "").endswith("-token")]+ minters = [+ s+ for job in (jobs["cut"], jobs["tag"])+ for s in job["steps"]+ if s.get("id", "").endswith("-token")+ ]assert len(minters) == 3for step in minters:assert step["uses"].startswith("actions/create-github-app-token@")@@ -989,8 +1005,10 @@ def test_release_tag_ci_is_excluded_from_branch_cancellation():def test_release_cut_lands_through_protection_and_tags_the_merge_commit():- cut = workflows()["release-cut.yml"]["jobs"]["cut"]- commands = "\n".join(step.get("run", "") for step in cut["steps"])+ jobs = workflows()["release-cut.yml"]["jobs"]+ commands = "\n".join(+ step.get("run", "") for job in jobs.values() for step in job.get("steps", [])+ )assert "git push origin HEAD:main" not in commandsmerge = 'gh pr merge "$CANDIDATE" --merge --match-head-commit "$CANDIDATE_SHA"'assert merge in commands@@ -1407,3 +1425,55 @@ def test_producers_cannot_edit_visibility_or_replace_assets():upload = next(s for s in steps if "release_assets.py upload" in s.get("run", ""))assert "--clobber" not in upload["run"]assert definitions["sign-installer.yml"]["jobs"]["provenance"]["with"]["upload-assets"] is False+++def _git_history(tmp_path, *, extra_path: str | None = None):+ """main with one commit, plus a bundle commit on top that only touches dist."""+ import shutil++ if shutil.which("git") is None:+ pytest.skip("git is required")++ def git(*args):+ return subprocess.run(+ ["git", "-c", "user.name=t", "-c", "[email protected]", *args],+ cwd=tmp_path,+ check=True,+ capture_output=True,+ text=True,+ ).stdout.strip()++ git("init", "-q", "-b", "main")+ (tmp_path / "app.py").write_text("x = 1\n", encoding="utf-8")+ git("add", "-A")+ git("commit", "-q", "-m", "base")+ base = git("rev-parse", "HEAD")+ dist = tmp_path / "dodaios" / "ui" / "web" / "dist"+ dist.mkdir(parents=True)+ (dist / "index.html").write_text("<html></html>\n", encoding="utf-8")+ if extra_path:+ (tmp_path / extra_path).write_text("smuggled\n", encoding="utf-8")+ git("checkout", "-q", "--detach")+ git("add", "-A")+ git("commit", "-q", "-m", "bundle")+ return base, git("rev-parse", "HEAD")+++def _run_in(tmp_path):+ def command(args, *, check=True):+ return subprocess.run(args, cwd=tmp_path, capture_output=True, text=True, check=check)++ return command+++def test_bundle_commit_on_main_is_admitted(monkeypatch, tmp_path):+ base, bundle = _git_history(tmp_path)+ monkeypatch.setattr(release_admit, "run_command", _run_in(tmp_path))+ assert release_admit.on_main_or_bundle(base, "main")+ assert release_admit.on_main_or_bundle(bundle, "main")+++def test_bundle_commit_that_touches_code_is_refused(monkeypatch, tmp_path):+ _base, bundle = _git_history(tmp_path, extra_path="app.py")+ monkeypatch.setattr(release_admit, "run_command", _run_in(tmp_path))+ assert not release_admit.on_main_or_bundle(bundle, "main")diff --git a/tests/unit/ci/test_release_cut_workflow.py b/tests/unit/ci/test_release_cut_workflow.pyindex 58fbeaf47d..46f4be7398 100644--- a/tests/unit/ci/test_release_cut_workflow.py+++ b/tests/unit/ci/test_release_cut_workflow.py@@ -21,6 +21,11 @@ git() {if [ "$2" = HEAD ]; then printf '%s\n' "$FAKE_SHA";else printf '%s\n' "$TAG_SHA"; fi ;;merge-base) return "$ANCESTOR_EXIT" ;;+ diff)+ case "$*" in+ *--quiet*) return "$BUNDLE_DIFF_EXIT" ;;+ *--name-only*) printf "$STAGED_PATHS" ;;+ esac ;;show-ref) return "$TAG_EXISTS" ;;show) printf '[project]\n' ;;checkout) : > checked-out ;;@@ -44,6 +49,9 @@ gh() {*) return 2 ;;esac}+python3() {+ printf 'python3 %s\n' "$*" >> "$TRACE_FILE"+}python() {printf 'python %s\n' "$*" >> "$TRACE_FILE"if [ "$1" = -c ]; then@@ -78,7 +86,11 @@ def _exercise(pytest.skip("the workflow shell requires Bash")root = Path(__file__).resolve().parents[3]workflow = yaml.safe_load((root / ".github/workflows" / workflow_name).read_text("utf-8"))+ # Steps of the named job first; a release spans several jobs (cut, tag).steps = {step.get("name"): step for step in workflow["jobs"][job_id]["steps"]}+ for job in workflow["jobs"].values():+ for step in job.get("steps", []):+ steps.setdefault(step.get("name"), step)trace = tmp_path / "commands.txt"script = tmp_path / "release-test.sh"script.write_text(@@ -118,6 +130,10 @@ def _exercise("TAG_PUSHED": "true","CANDIDATE": "release-cut/v1.2.3-77-2","CANDIDATE_SHA": _SHA,+ "SHA": _SHA,+ "DIST": "dodaios/ui/web/dist",+ "BUNDLE_DIFF_EXIT": "0",+ "STAGED_PATHS": "",**overrides,},capture_output=True,@@ -181,13 +197,13 @@ def _release_cut_jobs() -> dict:def test_a_tag_that_does_not_get_published_is_reported():# v3.1.0, v4.0.0 and v4.1.0 stayed drafts behind a pushed tag, unnoticed (#522).jobs = _release_cut_jobs()- assert jobs["cut"]["outputs"]["tagged"] == "${{ steps.tag.outcome == 'success' }}"+ assert jobs["tag"]["outputs"]["tagged"] == "${{ steps.tag.outcome == 'success' }}"stranded = jobs["stranded"]- assert stranded["needs"] == ["cut", "publish"]+ assert stranded["needs"] == ["cut", "tag", "publish"]condition = stranded["if"]# always(): the report must run when publish failed, was skipped or cancelled.assert condition.startswith("always()")- assert "needs.cut.outputs.tagged == 'true'" in condition+ assert "needs.tag.outputs.tagged == 'true'" in conditionassert "needs.publish.result != 'success'" in conditionassert stranded["permissions"] == {"issues": "write"}@@ -316,7 +332,9 @@ def test_resume_requires_merged_current_version_and_admission(tmp_path, overrideassert not any(command.startswith("git checkout ") for command in commands)if success:assert commands[-1] == "git push origin v1.2.3"- assert (tmp_path / "outputs.txt").read_text("utf-8") == "version=1.2.3\npushed=true\n"+ assert (tmp_path / "outputs.txt").read_text("utf-8") == (+ f"version=1.2.3\nsha={_SHA}\npushed=true\n"+ )else:assert not any(command.startswith("git tag ") for command in commands)assert "git push origin v1.2.3" not in commands@@ -330,3 +348,54 @@ def test_resume_names_the_version_commit_when_given_a_later_one(tmp_path):assert "does not introduce v1.2.3" in result.stdoutassert f"git log --format=%H %s -S## [1.2.3] {_SHA} -- CHANGELOG.md" in commandsassert not (tmp_path / "outputs.txt").exists()+++_TAG = "Tag the admitted release"+_ADD = "git add -f -A -- dodaios/ui/web/dist"+_COMMIT = "git commit -q -m chore(release): frontend bundle for v1.2.3"+++def test_tag_carries_a_bundle_commit_on_the_admitted_commit(tmp_path):+ result, commands = _exercise(+ tmp_path,+ [_TAG],+ job_id="tag",+ BUNDLE_DIFF_EXIT="1",+ STAGED_PATHS="dodaios/ui/web/dist/index.html\\n",+ )+ assert result.returncode == 0, result.stdout + result.stderr+ prune = "python3 scripts/ci/check_dist_consistency.py --staged --prune"+ assert commands.index(_ADD) < commands.index(prune) < commands.index(_COMMIT)+ assert commands.index(_COMMIT) < commands.index("git tag -a v1.2.3 -m v1.2.3")+ assert commands[-1] == "git push origin v1.2.3"+++def test_tag_refuses_a_bundle_that_touches_anything_else(tmp_path):+ result, commands = _exercise(+ tmp_path,+ [_TAG],+ job_id="tag",+ BUNDLE_DIFF_EXIT="1",+ STAGED_PATHS="dodaios/ui/web/dist/index.html\\ndodaios/core/config.py\\n",+ )+ assert result.returncode != 0+ assert not any(command.startswith("git tag ") for command in commands)+ assert _COMMIT not in commands+++def test_an_unchanged_bundle_tags_the_admitted_commit_itself(tmp_path):+ result, commands = _exercise(tmp_path, [_TAG], job_id="tag")+ assert result.returncode == 0, result.stdout + result.stderr+ assert _COMMIT not in commands+ assert commands[-1] == "git push origin v1.2.3"+++def test_bundle_job_builds_without_secrets():+ root = Path(__file__).resolve().parents[3]+ jobs = yaml.safe_load((root / ".github/workflows/release-cut.yml").read_text("utf-8"))["jobs"]+ bundle = jobs["bundle"]+ assert bundle["permissions"] == {"contents": "read"}+ assert "environment" not in bundle+ assert "secrets." not in yaml.safe_dump(bundle)+ assert jobs["tag"]["needs"] == ["cut", "bundle"]+ assert "npm" not in yaml.safe_dump(jobs["tag"])