Skip to content

Commit 07e771b

Browse files
[Backport release-25.05] workflows/codeowners: move into PR workflow (#435298)
2 parents 97fd412 + 2c86ed7 commit 07e771b

File tree

4 files changed

+117
-156
lines changed

4 files changed

+117
-156
lines changed

.github/workflows/check.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ on:
99
headBranch:
1010
required: true
1111
type: string
12+
mergedSha:
13+
required: true
14+
type: string
15+
targetSha:
16+
required: true
17+
type: string
18+
secrets:
19+
CACHIX_AUTH_TOKEN:
20+
required: true
21+
OWNER_RO_APP_PRIVATE_KEY:
22+
required: true
1223

1324
permissions: {}
1425

@@ -70,3 +81,72 @@ jobs:
7081
env:
7182
GH_TOKEN: ${{ github.token }}
7283
run: gh api /rate_limit | jq
84+
85+
# For checking code owners, this job depends on a GitHub App with the following permissions:
86+
# - Permissions:
87+
# - Repository > Administration: read-only
88+
# - Organization > Members: read-only
89+
# - Install App on this repository, setting these variables:
90+
# - OWNER_RO_APP_ID (variable)
91+
# - OWNER_RO_APP_PRIVATE_KEY (secret)
92+
#
93+
# This should not use the same app as the job to request reviewers, because this job requires
94+
# handling untrusted PR input.
95+
owners:
96+
runs-on: ubuntu-24.04-arm
97+
timeout-minutes: 5
98+
steps:
99+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
100+
with:
101+
sparse-checkout: .github/actions
102+
- name: Check if the PR can be merged and checkout the merge and target commits
103+
uses: ./.github/actions/get-merge-commit
104+
with:
105+
mergedSha: ${{ inputs.mergedSha }}
106+
merged-as-untrusted: true
107+
pinnedFrom: trusted
108+
targetSha: ${{ inputs.targetSha }}
109+
target-as-trusted: true
110+
111+
- uses: cachix/install-nix-action@fc6e360bedc9ee72d75e701397f0bb30dce77568 # v31
112+
113+
- uses: cachix/cachix-action@0fc020193b5a1fa3ac4575aa3a7d3aa6a35435ad # v16
114+
with:
115+
# This cache is for the nixpkgs repo checks and should not be trusted or used elsewhere.
116+
name: nixpkgs-ci
117+
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
118+
119+
- name: Build codeowners validator
120+
run: nix-build trusted/ci --arg nixpkgs ./pinned -A codeownersValidator
121+
122+
- uses: actions/create-github-app-token@0f859bf9e69e887678d5bbfbee594437cb440ffe # v2.1.0
123+
if: github.event_name == 'pull_request_target' && vars.OWNER_RO_APP_ID
124+
id: app-token
125+
with:
126+
app-id: ${{ vars.OWNER_RO_APP_ID }}
127+
private-key: ${{ secrets.OWNER_RO_APP_PRIVATE_KEY }}
128+
permission-administration: read
129+
permission-members: read
130+
131+
- name: Log current API rate limits
132+
if: steps.app-token.outputs.token
133+
env:
134+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
135+
run: gh api /rate_limit | jq
136+
137+
- name: Validate codeowners
138+
if: steps.app-token.outputs.token
139+
env:
140+
OWNERS_FILE: untrusted/ci/OWNERS
141+
GITHUB_ACCESS_TOKEN: ${{ steps.app-token.outputs.token }}
142+
REPOSITORY_PATH: untrusted
143+
OWNER_CHECKER_REPOSITORY: ${{ github.repository }}
144+
# Set this to "notowned,avoid-shadowing" to check that all files are owned by somebody
145+
EXPERIMENTAL_CHECKS: "avoid-shadowing"
146+
run: result/bin/codeowners-validator
147+
148+
- name: Log current API rate limits
149+
if: steps.app-token.outputs.token
150+
env:
151+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
152+
run: gh api /rate_limit | jq

.github/workflows/codeowners-v2.yml

Lines changed: 0 additions & 151 deletions
This file was deleted.

.github/workflows/pr.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,14 @@ jobs:
8787
permissions:
8888
# cherry-picks
8989
pull-requests: write
90+
secrets:
91+
CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }}
92+
OWNER_RO_APP_PRIVATE_KEY: ${{ secrets.OWNER_RO_APP_PRIVATE_KEY }}
9093
with:
9194
baseBranch: ${{ needs.prepare.outputs.baseBranch }}
9295
headBranch: ${{ needs.prepare.outputs.headBranch }}
96+
mergedSha: ${{ needs.prepare.outputs.mergedSha }}
97+
targetSha: ${{ needs.prepare.outputs.targetSha }}
9398

9499
lint:
95100
name: Lint

.github/workflows/reviewers.yml

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
name: Reviewers
55

66
on:
7-
pull_request:
8-
paths:
9-
- .github/workflows/reviewers.yml
107
pull_request_target:
118
types: [ready_for_review]
129
workflow_call:
@@ -41,8 +38,16 @@ jobs:
4138
- name: Build the requestReviews derivation
4239
run: nix-build trusted/ci -A requestReviews
4340

44-
# See ./codeowners-v2.yml, reuse the same App because we need the same permissions
45-
# Can't use the token received from permissions above, because it can't get enough permissions
41+
# For requesting reviewers, this job depends on a GitHub App with the following permissions:
42+
# - Permissions:
43+
# - Repository > Administration: read-only
44+
# - Organization > Members: read-only
45+
# - Repository > Pull Requests: read-write
46+
# - Install App on this repository, setting these variables:
47+
# - OWNER_APP_ID (variable)
48+
# - OWNER_APP_PRIVATE_KEY (secret)
49+
#
50+
# Can't use the token received from permissions above, because it can't get enough permissions.
4651
- uses: actions/create-github-app-token@0f859bf9e69e887678d5bbfbee594437cb440ffe # v2.1.0
4752
if: github.event_name == 'pull_request_target' && vars.OWNER_APP_ID
4853
id: app-token
@@ -53,6 +58,28 @@ jobs:
5358
permission-members: read
5459
permission-pull-requests: write
5560

61+
- name: Log current API rate limits (app-token)
62+
if: ${{ steps.app-token.outputs.token }}
63+
env:
64+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
65+
run: gh api /rate_limit | jq
66+
67+
- name: Requesting code owner reviews
68+
if: steps.app-token.outputs.token
69+
env:
70+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
71+
REPOSITORY: ${{ github.repository }}
72+
NUMBER: ${{ github.event.number }}
73+
# Don't do anything on draft PRs
74+
DRY_MODE: ${{ github.event.pull_request.draft && '1' || '' }}
75+
run: result/bin/request-code-owner-reviews.sh "$REPOSITORY" "$NUMBER" ci/OWNERS
76+
77+
- name: Log current API rate limits (app-token)
78+
if: ${{ steps.app-token.outputs.token }}
79+
env:
80+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
81+
run: gh api /rate_limit | jq
82+
5683
- name: Log current API rate limits (github.token)
5784
env:
5885
GH_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)