Skip to content
Open
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
2 changes: 0 additions & 2 deletions docs/configuring/ci-yml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/ci_infrastructure/ci_yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions src/ci_infrastructure/generate_downstream_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}],
}
}
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fork_pull_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_generate_downstream_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Loading