|
1 | 1 | name: CI |
2 | 2 | on: |
3 | | - pull_request: |
4 | | - branches: |
5 | | - - main |
| 3 | + # We use pull_request_target such that the code owner validation works for PRs from forks, |
| 4 | + # because we need repository secrets for that, which pull_request wouldn't allow from forks. |
| 5 | + # However, it's very important that we don't run code from forks without sandboxing it, |
| 6 | + # because that way anybody could potentially extract repository secrets! |
| 7 | + # Furthermore, using pull_request_target doesn't require manually approving first-time contributors |
| 8 | + pull_request_target: |
6 | 9 |
|
7 | 10 | jobs: |
8 | 11 | xrefcheck: |
9 | 12 | name: Check references |
10 | 13 | runs-on: ubuntu-latest |
11 | 14 | steps: |
12 | 15 | - uses: actions/checkout@v4 |
| 16 | + with: |
| 17 | + ref: refs/pull/${{ github.event.pull_request.number }}/merge |
| 18 | + path: untrusted-pr |
| 19 | + |
13 | 20 | - uses: serokell/xrefcheck-action@v1 |
| 21 | + with: |
| 22 | + xrefcheck-args: "--root untrusted-pr" |
| 23 | + |
| 24 | + codeowners: |
| 25 | + name: Validate codeowners |
| 26 | + runs-on: ubuntu-latest |
| 27 | + steps: |
| 28 | + - uses: cachix/install-nix-action@v26 |
| 29 | + |
| 30 | + - uses: actions/checkout@v4 |
| 31 | + with: |
| 32 | + path: trusted-base |
| 33 | + |
| 34 | + - uses: actions/checkout@v4 |
| 35 | + with: |
| 36 | + ref: refs/pull/${{ github.event.pull_request.number }}/merge |
| 37 | + path: untrusted-pr |
| 38 | + |
| 39 | + - uses: mszostok/[email protected] |
| 40 | + with: |
| 41 | + # GitHub access token is required only if the `owners` check is enabled |
| 42 | + # See https://github.com/mszostok/codeowners-validator/blob/main/docs/gh-auth.md#public-repositories |
| 43 | + github_access_token: "${{ secrets.OWNERS_VALIDATOR_GITHUB_SECRET }}" |
| 44 | + |
| 45 | + # The repository path in which CODEOWNERS file should be validated." |
| 46 | + repository_path: untrusted-pr |
| 47 | + |
| 48 | + # The owner and repository name. For example, gh-codeowners/codeowners-samples. Used to check if GitHub team is in the given organization and has permission to the given repository." |
| 49 | + owner_checker_repository: "${{ github.repository }}" |
| 50 | + |
| 51 | + # "The comma-separated list of experimental checks that should be executed. By default, all experimental checks are turned off. Possible values: notowned,avoid-shadowing" |
| 52 | + experimental_checks: "notowned,avoid-shadowing" |
| 53 | + |
| 54 | + # Specifies whether CODEOWNERS may have unowned files. For example, `/infra/oncall-rotator/oncall-config.yml` doesn't have owner and this is not reported. |
| 55 | + owner_checker_allow_unowned_patterns: "false" |
| 56 | + |
| 57 | + # Specifies whether only teams are allowed as owners of files. |
| 58 | + owner_checker_owners_must_be_teams: "false" |
14 | 59 |
|
15 | | -# TODO: Use https://github.com/marketplace/actions/github-codeowners-validator |
| 60 | + # The above validator doesn't currently ensure that people have write access: https://github.com/mszostok/codeowners-validator/issues/157 |
| 61 | + # So we're doing it manually instead |
| 62 | + - name: Check that codeowners have write access |
| 63 | + # Important that we run the script from the base branch, |
| 64 | + # because otherwise a PR from a fork could change it to extract the secret |
| 65 | + run: trusted-base/scripts/unprivileged-owners.sh untrusted-pr ${{ github.repository }} |
| 66 | + env: |
| 67 | + GH_TOKEN: "${{ secrets.OWNERS_VALIDATOR_GITHUB_SECRET }}" |
0 commit comments