11name : Codeowners
22
3- on :
4- pull_request_target :
5- types : [opened, ready_for_review, synchronize, reopened, edited]
6-
7- env :
8- OWNERS_FILE : .github/OWNERS
9-
103# This workflow depends on a GitHub App with the following permissions:
114# - Repository > Administration: read-only
125# - Organization > Members: read-only
158# the OWNER_APP_ID repository variable needs to be set
169# the OWNER_APP_PRIVATE_KEY repository secret needs to be set
1710
11+ on :
12+ pull_request_target :
13+ types : [opened, ready_for_review, synchronize, reopened, edited]
14+
15+ env :
16+ # TODO: Once confirmed that this works by seeing that the action would request
17+ # reviews from the same people (or refuse for wrong base branches),
18+ # move all entries from CODEOWNERS to OWNERS and change this value here
19+ # OWNERS_FILE: .github/OWNERS
20+ OWNERS_FILE : .github/CODEOWNERS
21+
1822jobs :
19- check-owners :
23+ # Check that code owners is valid
24+ check :
2025 name : Check
2126 runs-on : ubuntu-latest
2227 steps :
23- - uses : cachix/install-nix-action@ba0dd844c9180cbf77aa72a116d6fbc515d0e87b # v27
28+ - uses : cachix/install-nix-action@9f70348d77d0422624097c4b7a75563948901306 # v29
2429
25- - uses : actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
30+ # Important: Because we use pull_request_target, this checks out the base branch of the PR, not the PR itself.
31+ # We later build and run code from the base branch with access to secrets,
32+ # so it's important this is not the PRs code.
33+ - uses : actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
2634 with :
2735 path : base
2836
2937 - name : Build codeowners validator
3038 run : nix-build base/ci -A codeownersValidator
3139
32- - uses : actions/create-github-app-token@v1
40+ - uses : actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1.11.0
3341 id : app-token
3442 with :
3543 app-id : ${{ vars.OWNER_APP_ID }}
3644 private-key : ${{ secrets.OWNER_APP_PRIVATE_KEY }}
3745
38- - uses : actions/checkout@v4
46+ - uses : actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
3947 with :
4048 ref : refs/pull/${{ github.event.number }}/merge
4149 path : pr
@@ -50,26 +58,29 @@ jobs:
5058 # Set this to "notowned,avoid-shadowing" to check that all files are owned by somebody
5159 EXPERIMENTAL_CHECKS : " avoid-shadowing"
5260
61+ # Request reviews from code owners
5362 request :
5463 name : Request
5564 runs-on : ubuntu-latest
5665 # Don't trigger on draft PRs
5766 if : ${{ ! github.event.pull_request.draft }}
5867 steps :
59- - uses : cachix/install-nix-action@ba0dd844c9180cbf77aa72a116d6fbc515d0e87b # v27
68+ - uses : cachix/install-nix-action@9f70348d77d0422624097c4b7a75563948901306 # v29
6069
61- - uses : actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
70+ # Important: Because we use pull_request_target, this checks out the base branch of the PR, not the PR head.
71+ # This is intentional, because we need to request the review of owners as declared in the base branch.
72+ - uses : actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
6273
63- - name : Build review request package
64- run : nix-build ci -A requestReviews
74+ - uses : actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1.11.0
75+ id : app-token
76+ with :
77+ app-id : ${{ vars.OWNER_APP_ID }}
78+ private-key : ${{ secrets.OWNER_APP_PRIVATE_KEY }}
6579
66- - uses : actions/create-github-app-token@v1
67- id : app-token
68- with :
69- app-id : ${{ vars.OWNER_APP_ID }}
70- private-key : ${{ secrets.OWNER_APP_PRIVATE_KEY }}
80+ - name : Build review request package
81+ run : nix-build ci -A requestReviews
7182
72- - name : Request reviews
73- run : ./ result/bin/request-reviews.sh ${{ github.repository }} ${{ github.event.number }} "$OWNERS_FILE"
74- env :
75- GH_TOKEN : ${{ steps.app-token.outputs.token }}
83+ - name : Request reviews
84+ run : result/bin/request-reviews.sh ${{ github.repository }} ${{ github.event.number }} "$OWNERS_FILE"
85+ env :
86+ GH_TOKEN : ${{ steps.app-token.outputs.token }}
0 commit comments