summaryrefslogtreecommitdiffstats
path: root/.github/workflows/check.yml
blob: fd3404f07a3bcabb6c156b865bb8987e8ef8c0f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
name: Check

on:
  workflow_call:
    inputs:
      baseBranch:
        required: false
        type: string
      headBranch:
        required: false
        type: string
      mergedSha:
        required: true
        type: string
      targetSha:
        required: true
        type: string
    secrets:
      # Can be provided in pull requests because the job it is used in does
      # not evaluate untrusted code.
      NIXPKGS_COMMIT_CHECK_APP_PRIVATE_KEY:
        required: false
      # Can be provided in pull requests because the job it is used in does
      # not evaluate untrusted code.
      NIXPKGS_MANUAL_EDIT_CHECK_APP_PRIVATE_KEY:
        required: false
      # Should only be provided in the merge queue, not in pull requests,
      # where we're evaluating untrusted code.
      CACHIX_AUTH_TOKEN_GHA:
        required: false

permissions: {}

defaults:
  run:
    shell: bash

jobs:
  commits:
    if: inputs.baseBranch && inputs.headBranch
    permissions:
      pull-requests: write # submitting PR reviews
    runs-on: ubuntu-slim
    timeout-minutes: 3
    steps:
      - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
        with:
          persist-credentials: false
          path: trusted
          sparse-checkout: |
            ci/github-script

      - name: Install dependencies
        run: npm ci --package-lock-only=false --no-audit bottleneck
        working-directory: trusted/ci/github-script

      - uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
        if: github.event_name != 'pull_request' && vars.NIXPKGS_COMMIT_CHECK_CLIENT_ID
        id: app-token
        with:
          client-id: ${{ vars.NIXPKGS_COMMIT_CHECK_CLIENT_ID }}
          private-key: ${{ secrets.NIXPKGS_COMMIT_CHECK_APP_PRIVATE_KEY }}
          permission-pull-requests: write

      - name: Log current API rate limits
        env:
          GH_TOKEN: ${{ steps.app-token.outputs.token || github.token }}
        run: gh api /rate_limit | jq

      - name: Check commits
        id: check
        uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
        env:
          TARGETS_STABLE: ${{ fromJSON(inputs.baseBranch).stable && !contains(fromJSON(inputs.headBranch).type, 'development') }}
        with:
          github-token: ${{ steps.app-token.outputs.token || github.token }}
          script: |
            const targetsStable = JSON.parse(process.env.TARGETS_STABLE)
            const { default: commits } = await import('${{ github.workspace }}/trusted/ci/github-script/commits.js')
            await commits({
              github,
              context,
              core,
              dry: context.eventName == 'pull_request',
              cherryPicks: context.eventName == 'pull_request' || targetsStable,
            })

      - name: Log current API rate limits
        env:
          GH_TOKEN: ${{ steps.app-token.outputs.token || github.token }}
        run: gh api /rate_limit | jq

  manual-file-edits:
    if: inputs.baseBranch && inputs.headBranch
    permissions:
      pull-requests: write
    runs-on: ubuntu-24.04-arm
    timeout-minutes: 8
    steps:
      - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
        with:
          persist-credentials: false
          path: trusted
          sparse-checkout: |
            ci/github-script

      - uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
        if: github.event_name != 'pull_request' && vars.NIXPKGS_MANUAL_EDIT_CHECK_CLIENT_ID
        id: app-token
        with:
          client-id: ${{ vars.NIXPKGS_MANUAL_EDIT_CHECK_CLIENT_ID }}
          private-key: ${{ secrets.NIXPKGS_MANUAL_EDIT_CHECK_APP_PRIVATE_KEY }}
          permission-pull-requests: write

      - name: Log current API rate limits
        env:
          GH_TOKEN: ${{ steps.app-token.outputs.token || github.token }}
        run: gh api /rate_limit | jq

      - name: Discourage manual edits to certain files
        uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
        with:
          github-token: ${{ steps.app-token.outputs.token || github.token }}
          script: |
            const { default: checkManualFileEdits } = await import('${{ github.workspace }}/trusted/ci/github-script/manual-file-edits.js')
            await checkManualFileEdits({
              github,
              context,
              core,
              dry: context.eventName == 'pull_request',
              repoPath: 'trusted',
            })

      - name: Log current API rate limits
        env:
          GH_TOKEN: ${{ steps.app-token.outputs.token || github.token }}
        run: gh api /rate_limit | jq

  github-script:
    runs-on: ubuntu-24.04-arm
    timeout-minutes: 5
    steps:
      - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
        with:
          persist-credentials: false
          sparse-checkout: .github/actions

      - name: Checkout merge and target commits
        uses: ./.github/actions/checkout
        with:
          merged-as-untrusted-at: ${{ inputs.mergedSha }}
          target-as-trusted-at: ${{ inputs.targetSha }}

      - name: Install dependencies to trusted/
        run: |
          npm ci --package-lock-only=false --no-audit
          echo "$PWD/node_modules/.bin" >> "$GITHUB_PATH"
        working-directory: nixpkgs/trusted/ci/github-script

      - name: Link trusted/ dependencies to untrusted/
        run: ln -s "$PWD/trusted/ci/github-script/node_modules" untrusted/ci/github-script/node_modules
        working-directory: nixpkgs

      - name: Check ci/github-script
        run: npm test
        working-directory: nixpkgs/untrusted/ci/github-script

  owners:
    runs-on: ubuntu-24.04-arm
    timeout-minutes: 5
    steps:
      - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
        with:
          persist-credentials: false
          sparse-checkout: .github/actions

      - name: Checkout merge and target commits
        uses: ./.github/actions/checkout
        with:
          merged-as-untrusted-at: ${{ inputs.mergedSha }}
          target-as-trusted-at: ${{ inputs.targetSha }}

      - uses: cachix/install-nix-action@13d8dd58da0234aa297dedd986986ccb8e7f3e24 # v31.11.1

      - uses: cachix/cachix-action@5f2d7c5294214f71b873db4b969586b980625e71 # v17
        continue-on-error: true
        with:
          # The nixpkgs-gha cache should not be trusted or used outside of Nixpkgs and its forks' CI.
          name: ${{ vars.CACHIX_NAME || 'nixpkgs-gha' }}
          extraPullNames: nixpkgs-gha
          authToken: ${{ secrets.CACHIX_AUTH_TOKEN_GHA }}
          pushFilter: -source$

      - name: Build codeowners validator
        run: nix-build nixpkgs/trusted/ci --arg nixpkgs ./nixpkgs/trusted-pinned -A codeownersValidator

      - name: Validate codeowners
        env:
          OWNERS_FILE: nixpkgs/untrusted/ci/OWNERS
          REPOSITORY_PATH: nixpkgs/untrusted
          # Omits "owners", which checks whether GitHub handles exist, but fails with nested team
          # structures.
          CHECKS: "duppatterns,files,syntax"
          # Set this to "notowned,avoid-shadowing" to check that all files are owned by somebody
          EXPERIMENTAL_CHECKS: "avoid-shadowing"
        run: result/bin/codeowners-validator