diff --git a/docs/configuring/ci-yml.rst b/docs/configuring/ci-yml.rst index e0d903a..7781dbe 100644 --- a/docs/configuring/ci-yml.rst +++ b/docs/configuring/ci-yml.rst @@ -257,8 +257,6 @@ For that, ``ci.yml`` needs three changes: # A fork's own pull_request run does nothing; ci-fork.yml runs this workflow instead. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository runs-on: ubuntu-latest - permissions: - pull-requests: write steps: - uses: ecmwf/ci-infrastructure/actions/require-ci-approval@main diff --git a/src/ci_infrastructure/ci_yml.py b/src/ci_infrastructure/ci_yml.py index 12707ab..85b319f 100644 --- a/src/ci_infrastructure/ci_yml.py +++ b/src/ci_infrastructure/ci_yml.py @@ -209,11 +209,11 @@ def render_ci_workflow(m: Manifest, by_repo: Mapping[str, Manifest]) -> str: # Kinds that wait for their upstream artifacts before taking a build runner. waited = [k for k in kinds if has_deps and not _local_needs(m, k)] - approval: dict[str, Any] = {"runs-on": SLIM_RUNNER, "permissions": {"pull-requests": "write"}} + # No permissions of its own: the workflow's `contents: read` covers the gate and check-workflows. + approval: dict[str, Any] = {"runs-on": SLIM_RUNNER} approval_step: Step = {"uses": f"{_ACTIONS}/require-ci-approval@main"} if m.fork_pull_requests: approval["if"] = _NOT_A_FORKS_OWN_RUN - approval["permissions"]["contents"] = "read" approval_step["with"] = {"check-workflows": "true"} approval["steps"] = [approval_step] jobs: dict[str, Any] = {APPROVAL: approval} diff --git a/src/ci_infrastructure/generate_downstream_ci.py b/src/ci_infrastructure/generate_downstream_ci.py index f4f5e7c..3d1d133 100644 --- a/src/ci_infrastructure/generate_downstream_ci.py +++ b/src/ci_infrastructure/generate_downstream_ci.py @@ -1615,7 +1615,7 @@ def _require_approval(jobs: dict[str, Any]) -> dict[str, Any]: ordered: dict[str, Any] = { _APPROVAL_JOB_ID: { "runs-on": SLIM_RUNNER, - "permissions": {"pull-requests": "write"}, + "permissions": {"contents": "read"}, "steps": [{"uses": "ecmwf/ci-infrastructure/actions/require-ci-approval@main"}], } } @@ -2290,7 +2290,7 @@ def render_fork_workflow(m: Manifest) -> str | None: # pull_request_target: the workflow files are the base branch's, never the fork's. "on": {"pull_request_target": {"types": ["opened", "synchronize", "reopened"]}}, # statuses: ci.yml's ci-result job posts the required `ci-result` onto the fork's commit. - "permissions": {"contents": "read", "pull-requests": "write", "statuses": "write"}, + "permissions": {"contents": "read", "pull-requests": "read", "statuses": "write"}, "jobs": { "ci": { # Fails at ci.yml's gate until a maintainer re-runs it, approving its commit. diff --git a/tests/test_fork_pull_requests.py b/tests/test_fork_pull_requests.py index 4ee24aa..c24cb06 100644 --- a/tests/test_fork_pull_requests.py +++ b/tests/test_fork_pull_requests.py @@ -120,7 +120,7 @@ def test_the_fork_workflow_calls_ci_yml_on_every_push(tmp_path: Path) -> None: # No label: the run fails at the gate until a maintainer re-runs it. assert doc[True] == {"pull_request_target": {"types": ["opened", "synchronize", "reopened"]}} # statuses: ci.yml's ci-result job posts the required check onto the fork's commit. - assert doc["permissions"] == {"contents": "read", "pull-requests": "write", "statuses": "write"} + assert doc["permissions"] == {"contents": "read", "pull-requests": "read", "statuses": "write"} (job,) = doc["jobs"].values() assert job["uses"] == "./.github/workflows/ci.yml" assert job["secrets"] == "inherit" diff --git a/tests/test_generate_downstream_ci.py b/tests/test_generate_downstream_ci.py index 08be4e1..16db8b9 100644 --- a/tests/test_generate_downstream_ci.py +++ b/tests/test_generate_downstream_ci.py @@ -1994,7 +1994,7 @@ def test_ci_approval_gate_fronts_every_job(tmp_path: Path) -> None: assert doc["jobs"]["ci-approval"] == { "runs-on": "ubuntu-slim", - "permissions": {"pull-requests": "write"}, + "permissions": {"contents": "read"}, "steps": [{"uses": "ecmwf/ci-infrastructure/actions/require-ci-approval@main"}], } for jid, job in doc["jobs"].items():