diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index e9ea2d7..7ab308a 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,4 +1,4 @@ -# syntax=docker/dockerfile:1.28@sha256:bb22d9815c728170f72750f4e5b0d672e06176142e1d602c7e66c050100b7e5b +# syntax=docker/dockerfile:1.29@sha256:572cebbc2b15e6f84c077742952674889cb63cd5e9b80abdffcbe587b6f19183 # Single-stage build: develop (the devcontainer image). Built with the repo # root as context (see compose.yml). The repo-root Dockerfile is reserved for # an instance's own runtime image -- see docs/TEMPLATE.md's "Contents" and @@ -8,13 +8,13 @@ ARG PREK_VERSION=0.5.10 # renovate: datasource=npm depName=@anthropic-ai/claude-code -ARG CLAUDE_CODE_VERSION=2.1.319 +ARG CLAUDE_CODE_VERSION=2.1.323 # renovate: datasource=github-releases depName=edouard-claude/snip ARG SNIP_VERSION=0.26.0 # renovate: datasource=github-releases depName=cli/cli -ARG GH_VERSION=2.103.3 +ARG GH_VERSION=2.104.0 # uv itself isn't a project dependency manager here -- it's only the # mechanism scripts/develop.sh uses to install an exact, checksum-verified @@ -22,7 +22,7 @@ ARG GH_VERSION=2.103.3 # package. Left on PATH afterward; harmless, and an instance that adds # Python as its own application runtime can reuse it directly. # renovate: datasource=github-releases depName=astral-sh/uv -ARG UV_VERSION=0.13.7 +ARG UV_VERSION=0.13.8 # python3 is infrastructure tooling, not an application runtime this # template assumes: prek needs an interpreter to build the venv for any @@ -35,7 +35,7 @@ ARG PYTHON_VERSION=3.14.8 # (the clear-thought MCP server in .mcp.json) is the only thing that # needs it. # renovate: datasource=node-version depName=node -ARG NODE_VERSION=24.22.2 +ARG NODE_VERSION=24.22.3 ARG SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt ARG SSL_CERT_DIR=/etc/ssl/certs diff --git a/.github/scripts/README.md b/.github/scripts/README.md index bce2a80..aaf9397 100644 --- a/.github/scripts/README.md +++ b/.github/scripts/README.md @@ -6,10 +6,12 @@ bump. - `setup_environments.sh` — creates or updates the `release`, `moderation` and `template-sync` GitHub environments (default-branch-only deployment - rule) and prints the commands that move their secrets in; dry run unless + rule; existing reviewers, wait timer and `can_admins_bypass` are kept) and prints the commands that move their secrets in; dry run unless `--apply` (see `../../docs/TEMPLATE.md`, "Moderation and template-sync environments"). `test_environments.py` runs the workflows' environment - check step against a stub `gh`. + check step (which fails closed on any API error other than a readable answer) + and this script against a stub `gh`. Org secrets are flagged when visible to + `all` or `private` repositories, or `selected` ones that include a repo given. - `template_sync_manifest.py` — parses `../template-sync-manifest.yml` and checks that every git-tracked path matches exactly one tier; backs both the `template-sync-manifest` prek hook and @@ -160,7 +162,9 @@ file only if a regular file under `.moderation-out/`, and writes `meta.json` and `patch.diff` for the `apply` job. A triage patch over the size cap becomes a `failed` result carrying that reason, which - `moderate_apply_triage.sh` includes in its "no usable result" note. + `moderate_apply_triage.sh` includes in its "no usable result" note only + when it is exactly the fixed `size_limit_reason` sentence from + `moderate_lib.sh`; an agent's own `failed` result carries no comment. - `moderate_apply_result.sh` / `moderate_apply_triage.sh` — the `apply` jobs' scripts (fix/build, and triage): validate the artifact, then push, open the PR or comment, and label. The only scripts that write; they diff --git a/.github/scripts/moderate_apply_triage.sh b/.github/scripts/moderate_apply_triage.sh index 66c8dd6..a6a8788 100755 --- a/.github/scripts/moderate_apply_triage.sh +++ b/.github/scripts/moderate_apply_triage.sh @@ -83,9 +83,10 @@ if ! [[ "$action" =~ ^[a-z-]{1,30}$ ]] || [ -z "${label_for[$action]+set}" ] || # Includes "failed" (no usable result), an action not in the table and an # empty comment: nothing from the result is acted on. # A "failed" result may carry the packaging step's own reason (a patch over - # the size cap); any other unusable result is not echoed. + # the size cap), posted only when it is exactly that fixed sentence: the + # comment is otherwise the agent's free text, which is never echoed here. note="" - if [ "$action" = failed ] && [ -n "$comment" ]; then + if [ "$action" = failed ] && [ "$comment" = "$(size_limit_reason)" ]; then note=" $comment" fi gh issue edit "$issue_number" --add-label "needs-human" || true diff --git a/.github/scripts/moderate_lib.sh b/.github/scripts/moderate_lib.sh index f40ede9..e697fe8 100755 --- a/.github/scripts/moderate_lib.sh +++ b/.github/scripts/moderate_lib.sh @@ -12,6 +12,13 @@ MAX_PATCH_BYTES=2097152 MAX_TEXT_CHARS=10000 MAX_TITLE_CHARS=200 +# size_limit_reason: the one fixed sentence a packaged `failed` triage result may +# carry. The apply step posts a failed result's comment only when it equals this +# text, so nothing the agent wrote ever reaches the issue through that path. +size_limit_reason() { + echo "The automated change is larger than the ${MAX_PATCH_BYTES}-byte limit for an unattended run." +} + # is_sha : a full 40-character lowercase hex object name, nothing else # (so it can never be read as a git option). is_sha() { diff --git a/.github/scripts/moderate_package_result.sh b/.github/scripts/moderate_package_result.sh index 6f46d1a..92d09a8 100755 --- a/.github/scripts/moderate_package_result.sh +++ b/.github/scripts/moderate_package_result.sh @@ -97,13 +97,18 @@ else # failed result's comment, so the maintainer learns why instead of seeing the # generic "no usable result" note. if [ "$too_large" = 1 ]; then - comment="The automated change is larger than the ${MAX_PATCH_BYTES}-byte limit for an unattended run." + comment="$(size_limit_reason)" fi result="$workspace/.moderation-out/triage.json" if [ "$too_large" = 0 ] && agent_file "$result" "$workspace" \ && jq -e '(.action | type == "string") and (.comment | type == "string")' "$result" > /dev/null 2>&1; then action="$(jq -r '.action' "$result")" comment="$(jq -r '.comment[0:20000]' "$result")" + # `failed` is the packager's own word for "no usable result": an agent that + # reports it carries no comment, so only the reason above is ever posted. + if [ "$action" = failed ]; then + comment="" + fi fi jq -n \ --arg issue "$GITHUB_ISSUE_NUMBER" \ diff --git a/.github/scripts/setup_environments.sh b/.github/scripts/setup_environments.sh index bc9055f..2f939ae 100755 --- a/.github/scripts/setup_environments.sh +++ b/.github/scripts/setup_environments.sh @@ -12,9 +12,11 @@ # environment and POST its branch policy. Secrets are never moved or deleted # (values can't be read back): the script prints the `gh secret set --env` / # `gh secret delete` commands for a human to run. Organization secrets are -# listed by name and visibility, and the ones visible to every repository are +# listed by name and visibility, and the ones visible to every repository, +# every private one, or shared with a repository named here are # flagged (a branch workflow can read them; an environment can't stop that). -# Existing reviewers and wait timers on an environment are kept. +# Existing reviewers, wait timers and the admin-bypass setting on an +# environment are kept (a new environment gets GitHub's default: admins bypass). # # Usage: # setup_environments.sh [--apply] [--env NAME]... [--org ORG] REPO... @@ -97,8 +99,24 @@ else done [ -n "$owner_env" ] || continue echo " $name: visibility=$vis ($owner_env secret)" - if [ "$vis" = all ]; then - echo " FLAG: visible to every repository, from any branch. Remediate (not run by this script):" + flag= + case "$vis" in + all) flag="visible to every repository" ;; + private) flag="visible to every private repository" ;; + selected) + # Only a problem for the repositories it is shared with: name the ones given here. + shared=$(get "orgs/$ORG/actions/secrets/$name/repositories" | jq -r '.repositories[]?.full_name') + for r in "${repos[@]}"; do + case "$r" in */*) full="$r" ;; *) full="$ORG/$r" ;; esac + if grep -qxF "$full" <<< "$shared"; then + flag="shared with selected repositories, including $full" + break + fi + done + ;; + esac + if [ -n "$flag" ]; then + echo " FLAG: $flag, readable from any branch. Remediate (not run by this script):" echo " per repo that needs it: gh secret set $name --env $owner_env -R $ORG/" echo " then: gh secret delete $name --org $ORG" fi @@ -129,11 +147,14 @@ for r in "${repos[@]}"; do have_flags=null [ -z "$env_json" ] || have_flags=$(jq -c '.deployment_branch_policy // null' <<< "$env_json") if [ -z "$env_json" ] || [ "$have_flags" != "$want_flags" ]; then - # A PUT replaces what it omits, so carry over existing protection rules. + # A PUT replaces what it omits, so carry over existing protection rules + # and can_admins_bypass (read back by GET, accepted by PUT, though absent + # from GitHub's published OpenAPI schema). body=$(jq -c --argjson flags "$want_flags" ' {deployment_branch_policy: $flags} + (if . == null then {} else - ([.protection_rules[]? | select(.type == "wait_timer") | .wait_timer][0] + (if .can_admins_bypass == null then {} else {can_admins_bypass: .can_admins_bypass} end) + + ([.protection_rules[]? | select(.type == "wait_timer") | .wait_timer][0] // null | if . == null then {} else {wait_timer: .} end) + ([.protection_rules[]? | select(.type == "required_reviewers")][0] // null | if . == null then {} else @@ -177,8 +198,10 @@ for r in "${repos[@]}"; do env_secrets=$(get "repos/$repo/environments/$env_name/secrets" | jq -r '.secrets[]?.name') wf=$(workflow_of "$env_name") ready=no - if get "repos/$repo/contents/.github/workflows/$wf" -H "Accept: application/vnd.github.raw" \ - | grep -q "environment: $env_name"; then + # Into a variable, not `| grep -q`: grep -q exits on its first match, the + # producer can then die of SIGPIPE, and pipefail would report that as "no". + wf_text=$(get "repos/$repo/contents/.github/workflows/$wf" -H "Accept: application/vnd.github.raw") + if grep -q "environment: $env_name" <<< "$wf_text"; then ready=yes fi echo " $wf on $default declares 'environment: $env_name': $ready" diff --git a/.github/scripts/test_environments.py b/.github/scripts/test_environments.py index 73e607d..ae7504b 100644 --- a/.github/scripts/test_environments.py +++ b/.github/scripts/test_environments.py @@ -230,13 +230,159 @@ def test_rejects_extra_or_wrong_rules(self) -> None: with self.subTest(rules=rules): self.assertEqual(self.run_check(self.GOOD, rules).returncode, 1) - def test_an_unreadable_environment_warns_and_continues(self) -> None: - proc = self.run_check( - None, env_error="gh: Resource not accessible by integration (HTTP 403)" - ) - self.assertEqual(proc.returncode, 0) - self.assertIn("::warning::", proc.stdout) - self.assertIn("unverified", proc.stdout) + def test_an_unreadable_environment_fails_closed(self) -> None: + """A 401/403/5xx is not a pass: a policy that cannot be read is unverified.""" + for error in ( + "gh: Resource not accessible by integration (HTTP 403)", + "gh: Bad credentials (HTTP 401)", + "gh: Server Error (HTTP 502)", + "error connecting to api.github.com", + ): + with self.subTest(error=error): + proc = self.run_check(None, env_error=error) + self.assertEqual(proc.returncode, 1) + self.assertIn("::error::", proc.stdout) + self.assertIn("fails closed", proc.stdout) + self.assertNotIn("does not exist", proc.stdout) + + def test_no_workflow_check_step_exits_zero_on_an_api_error(self) -> None: + for name in CHECKED: + with self.subTest(workflow=name): + self.assertNotIn( + "::warning::Cannot read environment", (WORKFLOWS / name).read_text() + ) + + +class SetupEnvironmentsScriptTest(unittest.TestCase): + """Run ``setup_environments.sh`` (dry run) against a stub ``gh``.""" + + STUB = """#!/usr/bin/env bash +if [ "$2" = --method ]; then + # gh api --method PUT --input - : record the body, accept it. + echo "$3 $4" > "$DATA/call.txt" + cat > "$DATA/body.json" + exit 0 +fi +url="$2" +case "$url" in + orgs/o/actions/secrets) cat "$DATA/org.json" ;; + orgs/o/actions/secrets/*/repositories) cat "$DATA/shared.json" ;; + repos/o/r) echo main ;; + repos/o/r/actions/secrets) echo '{"secrets":[]}' ;; + repos/o/r/environments/*/deployment-branch-policies) + echo '{"branch_policies":[{"type":"branch","name":"main"}]}' ;; + repos/o/r/environments/*/secrets) echo '{"secrets":[]}' ;; + repos/o/r/environments/*) + cat "$DATA/env.json" ;; + repos/o/r/contents/*) cat "$DATA/workflow.txt" ;; + *) echo "unexpected $*" >&2; exit 1 ;; +esac +""" + + OK_ENV = { + "deployment_branch_policy": {"protected_branches": False, "custom_branch_policies": True} + } + + def run_setup( + self, + secrets: list[dict], + shared: list[str], + workflow: str, + env: dict | None = None, + apply: bool = False, + put: dict | None = None, + ) -> str: + """Run the script; if ``put`` is a dict, fill it with the PUT body sent (if any).""" + with tempfile.TemporaryDirectory() as tmp: + tmp_path = Path(tmp) + (tmp_path / "env.json").write_text(json.dumps(env or self.OK_ENV)) + bindir = tmp_path / "bin" + bindir.mkdir() + (tmp_path / "org.json").write_text(json.dumps({"secrets": secrets})) + (tmp_path / "shared.json").write_text( + json.dumps({"repositories": [{"full_name": n} for n in shared]}) + ) + (tmp_path / "workflow.txt").write_text(workflow) + stub = bindir / "gh" + stub.write_text(self.STUB) + stub.chmod(stub.stat().st_mode | stat.S_IEXEC) + proc = subprocess.run( # noqa: S603 -- fixed argv, local stub + [ + str(SCRIPTS / "setup_environments.sh"), + *(["--apply"] if apply else []), + "--env", + "moderation", + "--org", + "o", + "r", + ], + env={"PATH": f"{bindir}:{os.environ['PATH']}", "DATA": tmp}, + capture_output=True, + text=True, + check=False, + ) + self.assertEqual(proc.returncode, 0, proc.stderr + proc.stdout) + body = tmp_path / "body.json" + if put is not None and body.exists(): + put.update(json.loads(body.read_text())) + return proc.stdout + + def test_org_secret_flagged_for_all_private_and_selected_sharing_the_repo(self) -> None: + for vis, shared, flagged in ( + ("all", [], True), + ("private", [], True), + ("selected", ["o/r"], True), + ("selected", ["o/other"], False), + ): + with self.subTest(visibility=vis, shared=shared): + secrets = [{"name": "ANTHROPIC_API_KEY", "visibility": vis}] + out = self.run_setup(secrets, shared, "environment: moderation\n") + self.assertEqual("FLAG:" in out, flagged, out) + + def test_ready_detected_when_the_workflow_text_is_large(self) -> None: + """A match near the start of a big file must not turn into "no" through SIGPIPE.""" + workflow = "environment: moderation\n" + "x" * 4_000_000 + "\n" + for _ in range(3): + out = self.run_setup([], [], workflow) + self.assertIn("declares 'environment: moderation': yes", out) + + def test_apply_keeps_can_admins_bypass_and_other_protection_rules(self) -> None: + """A PUT replaces what it omits: every existing setting must be sent back.""" + for bypass in (False, True): + with self.subTest(can_admins_bypass=bypass): + env = { + "can_admins_bypass": bypass, + "deployment_branch_policy": None, + "protection_rules": [ + {"type": "wait_timer", "wait_timer": 15}, + { + "type": "required_reviewers", + "prevent_self_review": True, + "reviewers": [{"type": "User", "reviewer": {"id": 7, "login": "x"}}], + }, + ], + } + put: dict = {} + self.run_setup([], [], "", env=env, apply=True, put=put) + self.assertEqual( + put, + { + "deployment_branch_policy": { + "protected_branches": False, + "custom_branch_policies": True, + }, + "can_admins_bypass": bypass, + "wait_timer": 15, + "prevent_self_review": True, + "reviewers": [{"type": "User", "id": 7}], + }, + ) + + def test_apply_omits_can_admins_bypass_when_the_environment_reports_none(self) -> None: + """Nothing to preserve (a missing environment reads as 404): GitHub's default applies.""" + put: dict = {} + self.run_setup([], [], "", env={"deployment_branch_policy": None}, apply=True, put=put) + self.assertNotIn("can_admins_bypass", put) if __name__ == "__main__": diff --git a/.github/scripts/test_moderate_apply_triage.py b/.github/scripts/test_moderate_apply_triage.py index 210859a..a8cdb13 100644 --- a/.github/scripts/test_moderate_apply_triage.py +++ b/.github/scripts/test_moderate_apply_triage.py @@ -150,8 +150,8 @@ def test_unknown_action_acts_on_nothing_from_the_result(self) -> None: ) def test_failed_result_reason_is_posted(self) -> None: - """A `failed` result's own reason (the size cap) reaches the note; other unusable ones stay generic.""" - reason = "The automated change is larger than the limit." + """Only the packager's fixed size-cap sentence reaches the note, not a lookalike.""" + reason = "The automated change is larger than the 2097152-byte limit for an unattended run." proc = self.run_script("failed", comment=reason) self.assertEqual(proc.returncode, 0, proc.stderr) self.assertEqual( @@ -163,6 +163,23 @@ def test_failed_result_reason_is_posted(self) -> None: self.run_script("bogus", comment=reason) self.assertNotIn(reason, "\n".join(self.log())) + def test_failed_result_with_agent_text_is_not_echoed(self) -> None: + """An agent that reports `failed` with its own text must not get that text posted.""" + for text in ( + "see https://evil.example/phish @maintainer", + "The automated change is larger than the limit.", + "x" * 5000, + ): + with self.subTest(text=text[:30]): + (self.tmp / "log.txt").unlink(missing_ok=True) + proc = self.run_script("failed", comment=text) + self.assertEqual(proc.returncode, 0, proc.stderr) + self.assertEqual( + self.log()[1], + "gh issue comment 7 --body Automated triage ended without a usable result. " + "A maintainer needs to look at this issue.", + ) + def test_result_labels_are_ignored(self) -> None: """Only the fixed table decides the label; a label field in the result is never read.""" self.run_script("needs-info", meta_extra={"label": "claude:ok", "labels": "x"}) diff --git a/.github/scripts/test_moderate_tools.py b/.github/scripts/test_moderate_tools.py index f9166ed..5402b93 100644 --- a/.github/scripts/test_moderate_tools.py +++ b/.github/scripts/test_moderate_tools.py @@ -318,6 +318,14 @@ def test_triage_patch_over_the_cap_keeps_its_reason(self) -> None: self.assertIn("larger than", meta["comment"]) self.assertFalse((self.out / "patch.diff").exists()) + def test_triage_agent_reported_failed_carries_no_comment(self) -> None: + """`failed` is the packager's word: an agent's own text under it is dropped.""" + (self.ws / ".moderation-out" / "triage.json").write_text( + json.dumps({"action": "failed", "comment": "ping @everyone http://x.example"}) + ) + meta = self.package("triage") + self.assertEqual((meta["action"], meta["comment"]), ("failed", "")) + def test_triage_result_bad_shapes(self) -> None: """Invalid JSON, wrong types and a symlinked file all become `failed`.""" target = self.ws / ".moderation-out" / "triage.json" diff --git a/.github/template-sync-state.json b/.github/template-sync-state.json index 02d22d1..ab09fc9 100644 --- a/.github/template-sync-state.json +++ b/.github/template-sync-state.json @@ -1,4 +1,4 @@ { "template_repo": "craftainer/template-base", - "synced_tag": "v1.15.6" + "synced_tag": "v1.15.7" } diff --git a/.github/workflows/moderate-bug-fix.yml b/.github/workflows/moderate-bug-fix.yml index 085800e..67a731c 100644 --- a/.github/workflows/moderate-bug-fix.yml +++ b/.github/workflows/moderate-bug-fix.yml @@ -75,8 +75,8 @@ jobs: echo "::error::Environment '$ENVIRONMENT_NAME' does not exist or is not readable. Create it with the setup in docs/TEMPLATE.md before running this workflow." exit 1 fi - echo "::warning::Cannot read environment '$ENVIRONMENT_NAME' with this token ($(head -c 200 "$err")); its branch policy is unverified." - exit 0 + echo "::error::Cannot read environment '$ENVIRONMENT_NAME' with this token ($(head -c 200 "$err")); its branch policy is unverified, so this run fails closed. Re-run if the error looks transient." + exit 1 fi default_branch=$(gh api "repos/$GITHUB_REPOSITORY" --jq .default_branch) flags=$(jq -r '.deployment_branch_policy | if . == null then "none" else "\(.custom_branch_policies)/\(.protected_branches)" end' <<< "$env_json") diff --git a/.github/workflows/moderate-bug-triage.yml b/.github/workflows/moderate-bug-triage.yml index 8b36ff3..86fadaf 100644 --- a/.github/workflows/moderate-bug-triage.yml +++ b/.github/workflows/moderate-bug-triage.yml @@ -48,8 +48,8 @@ jobs: echo "::error::Environment '$ENVIRONMENT_NAME' does not exist or is not readable. Create it with the setup in docs/TEMPLATE.md before running this workflow." exit 1 fi - echo "::warning::Cannot read environment '$ENVIRONMENT_NAME' with this token ($(head -c 200 "$err")); its branch policy is unverified." - exit 0 + echo "::error::Cannot read environment '$ENVIRONMENT_NAME' with this token ($(head -c 200 "$err")); its branch policy is unverified, so this run fails closed. Re-run if the error looks transient." + exit 1 fi default_branch=$(gh api "repos/$GITHUB_REPOSITORY" --jq .default_branch) flags=$(jq -r '.deployment_branch_policy | if . == null then "none" else "\(.custom_branch_policies)/\(.protected_branches)" end' <<< "$env_json") diff --git a/.github/workflows/moderate-feature-build.yml b/.github/workflows/moderate-feature-build.yml index 45b0243..47dcb52 100644 --- a/.github/workflows/moderate-feature-build.yml +++ b/.github/workflows/moderate-feature-build.yml @@ -75,8 +75,8 @@ jobs: echo "::error::Environment '$ENVIRONMENT_NAME' does not exist or is not readable. Create it with the setup in docs/TEMPLATE.md before running this workflow." exit 1 fi - echo "::warning::Cannot read environment '$ENVIRONMENT_NAME' with this token ($(head -c 200 "$err")); its branch policy is unverified." - exit 0 + echo "::error::Cannot read environment '$ENVIRONMENT_NAME' with this token ($(head -c 200 "$err")); its branch policy is unverified, so this run fails closed. Re-run if the error looks transient." + exit 1 fi default_branch=$(gh api "repos/$GITHUB_REPOSITORY" --jq .default_branch) flags=$(jq -r '.deployment_branch_policy | if . == null then "none" else "\(.custom_branch_policies)/\(.protected_branches)" end' <<< "$env_json") diff --git a/.github/workflows/moderate-feature-triage.yml b/.github/workflows/moderate-feature-triage.yml index 68659a0..d09d283 100644 --- a/.github/workflows/moderate-feature-triage.yml +++ b/.github/workflows/moderate-feature-triage.yml @@ -48,8 +48,8 @@ jobs: echo "::error::Environment '$ENVIRONMENT_NAME' does not exist or is not readable. Create it with the setup in docs/TEMPLATE.md before running this workflow." exit 1 fi - echo "::warning::Cannot read environment '$ENVIRONMENT_NAME' with this token ($(head -c 200 "$err")); its branch policy is unverified." - exit 0 + echo "::error::Cannot read environment '$ENVIRONMENT_NAME' with this token ($(head -c 200 "$err")); its branch policy is unverified, so this run fails closed. Re-run if the error looks transient." + exit 1 fi default_branch=$(gh api "repos/$GITHUB_REPOSITORY" --jq .default_branch) flags=$(jq -r '.deployment_branch_policy | if . == null then "none" else "\(.custom_branch_policies)/\(.protected_branches)" end' <<< "$env_json") diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f3c3141..e96b14a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -102,8 +102,8 @@ jobs: echo "::error::Environment '$ENVIRONMENT_NAME' does not exist or is not readable. Create it with the setup in docs/TEMPLATE.md before running this workflow." exit 1 fi - echo "::warning::Cannot read environment '$ENVIRONMENT_NAME' with this token ($(head -c 200 "$err")); its branch policy is unverified." - exit 0 + echo "::error::Cannot read environment '$ENVIRONMENT_NAME' with this token ($(head -c 200 "$err")); its branch policy is unverified, so this run fails closed. Re-run if the error looks transient." + exit 1 fi default_branch=$(gh api "repos/$GITHUB_REPOSITORY" --jq .default_branch) flags=$(jq -r '.deployment_branch_policy | if . == null then "none" else "\(.custom_branch_policies)/\(.protected_branches)" end' <<< "$env_json") diff --git a/.github/workflows/template-sync.yml b/.github/workflows/template-sync.yml index 00fe447..1792eda 100644 --- a/.github/workflows/template-sync.yml +++ b/.github/workflows/template-sync.yml @@ -52,8 +52,8 @@ jobs: echo "::error::Environment '$ENVIRONMENT_NAME' does not exist or is not readable. Create it with the setup in docs/TEMPLATE.md before running this workflow." exit 1 fi - echo "::warning::Cannot read environment '$ENVIRONMENT_NAME' with this token ($(head -c 200 "$err")); its branch policy is unverified." - exit 0 + echo "::error::Cannot read environment '$ENVIRONMENT_NAME' with this token ($(head -c 200 "$err")); its branch policy is unverified, so this run fails closed. Re-run if the error looks transient." + exit 1 fi default_branch=$(gh api "repos/$GITHUB_REPOSITORY" --jq .default_branch) flags=$(jq -r '.deployment_branch_policy | if . == null then "none" else "\(.custom_branch_policies)/\(.protected_branches)" end' <<< "$env_json") diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index aa20d05..d566bab 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -123,7 +123,7 @@ repos: # that directory only. Keep the rev equal to the ruff the Python # templates pin in pyproject.toml. - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.17.4 + rev: v0.17.5 hooks: - id: ruff-check name: ruff check (.github/scripts) @@ -190,7 +190,7 @@ repos: stages: [manual] - repo: https://github.com/google/osv-scanner - rev: v2.7.0 + rev: v2.7.1 hooks: # Online (queries osv.dev). Only runs when a supported lockfile is # in the file set: with none, osv-scanner exits 128 ("no packages diff --git a/Makefile b/Makefile index c37ed9c..4f4692b 100644 --- a/Makefile +++ b/Makefile @@ -33,10 +33,10 @@ SYFT_IMAGE := anchore/syft:v1.57.1@sha256:03215d0e98b661d0ecbc8575dbc14d65be1743 # stay the source the devcontainer test compares, and the guard below fails the # Makefile if the image tag drifts from them. # renovate: datasource=github-releases depName=astral-sh/uv -UV_VERSION := 0.13.7 +UV_VERSION := 0.13.8 # renovate: datasource=python-version depName=python versioning=docker PYTHON_VERSION := 3.14 -UV_IMAGE := ghcr.io/astral-sh/uv:0.13.7-python3.14-trixie-slim@sha256:e80c05a310400cfc90af00b5b7271ef9ad24816e3265e1162af8a678e1aad099 +UV_IMAGE := ghcr.io/astral-sh/uv:0.13.8-python3.14-trixie-slim@sha256:81a1340fea1e72ad4a8e9a016128b0c61041cf182ea49fd788023e52842bc147 ifeq ($(findstring :$(UV_VERSION)-python$(PYTHON_VERSION)-,$(UV_IMAGE)),) $(error UV_IMAGE ($(UV_IMAGE)) does not match UV_VERSION $(UV_VERSION) and PYTHON_VERSION $(PYTHON_VERSION); update the three together) endif diff --git a/docs/TEMPLATE.md b/docs/TEMPLATE.md index 476f4e9..d71bd40 100644 --- a/docs/TEMPLATE.md +++ b/docs/TEMPLATE.md @@ -251,8 +251,8 @@ Findings from the OWASP review (A03/A08), and what each now does: syncing the workflows that carry the `environment:` lines**: `setup_environments.sh OWNER/REPO` is a dry run that prints what it would do; `--apply` creates each environment with *Selected branches* - and one rule, the default branch, and keeps any reviewers or wait timer - already set; `--env NAME` limits it. It never touches secrets (values + and one rule, the default branch, and keeps any reviewers, wait timer or + `can_admins_bypass` setting already set; `--env NAME` limits it. It never touches secrets (values can't be read back): it prints `gh secret set NAME --env ` and `gh secret delete NAME` for you to run, and flags an organization secret visible to all repositories, which any branch workflow can read @@ -279,9 +279,10 @@ Findings from the OWASP review (A03/A08), and what each now does: `actions: read` permission those endpoints need) and **fail** with a message when the environment is missing or has no custom branch policy, or its rules aren't exactly one `branch:`. If the token - cannot read the environment (a 401/403), the step only warns that the - policy is unverified, so a token or plan difference never blocks a - release or a moderation run. The check is a fail-fast diagnostic only: a + cannot read the environment for any other reason (a 401/403 or a 5xx), + the step fails closed too: a policy it cannot verify is not assumed to + hold, so re-run once the API answers, or fix the token's `actions: read`. + The check is a fail-fast diagnostic only: a writer can delete it on their own branch. What enforces the rule is the environment itself. - **Renovate waits 3 days before automerging.** The "patch and minor