summaryrefslogtreecommitdiffstats
path: root/.github/workflows/test.yml
blob: d8ea1194f879f1008d9f2c42ac0cac680eafa250 (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
name: Test

on:
  pull_request:

concurrency:
  group: test-${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.run_id }}
  cancel-in-progress: true

permissions: {}

jobs:
  prepare:
    runs-on: ubuntu-slim
    outputs:
      merge-group: ${{ steps.files.outputs.merge-group }}
      mergedSha: ${{ steps.prepare.outputs.mergedSha }}
      pr: ${{ steps.files.outputs.pr }}
      push: ${{ steps.files.outputs.push }}
      targetSha: ${{ steps.prepare.outputs.targetSha }}
    steps:
      - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
        with:
          persist-credentials: false
          sparse-checkout-cone-mode: true # default, for clarity
          sparse-checkout: |
            ci/github-script
      - id: prepare
        uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
        with:
          retries: 10
          # The default for this includes code 422, which happens regularly for us when comparing commits:
          #   422 - Server Error: Sorry, this diff is taking too long to generate.
          # Listing all other values from here to effectively remove 422:
          #   https://github.com/octokit/plugin-retry.js/blob/9a2443746c350b3beedec35cf26e197ea318a261/src/index.ts#L14
          retry-exempt-status-codes: 400,401,403,404
          script: |
            const { default: prepare } = await import('${{ github.workspace }}/ci/github-script/prepare.js')
            await prepare({
              github,
              context,
              core,
              // Review comments will be posted by the main PR workflow on the pull_request_target event.
              dry: true,
            })

      - name: Determine changed files
        id: files
        uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
        with:
          script: |
            const files = (await github.paginate(github.rest.pulls.listFiles, {
              ...context.repo,
              pull_number: context.payload.pull_request.number,
              per_page: 100,
            })).map(file => file.filename)

            if (files.some(file => [
              '.github/workflows/build.yml',
              '.github/workflows/check.yml',
              '.github/workflows/eval.yml',
              '.github/workflows/lint.yml',
              '.github/workflows/merge-group.yml',
              '.github/workflows/test.yml',
              'ci/github-script/package.json',
              'ci/github-script/package-lock.json',
              'ci/github-script/supportedBranches.js',
              'ci/github-script/supportedSystems.js',
              'ci/pinned.json',
              'pkgs/top-level/release-supported-systems.json',
            ].includes(file))) core.setOutput('merge-group', true)

            if (files.some(file => [
              '.github/actions/checkout/action.yml',
              '.github/workflows/bot.yml',
              '.github/workflows/build.yml',
              '.github/workflows/check.yml',
              '.github/workflows/eval.yml',
              '.github/workflows/lint.yml',
              '.github/workflows/pull-request-target.yml',
              '.github/workflows/test.yml',
              'ci/github-script/bot.js',
              'ci/github-script/check-target-branch.ts',
              'ci/github-script/commits.js',
              'ci/github-script/get-pr-commit-details.js',
              'ci/github-script/lint-commits.js',
              'ci/github-script/merge.js',
              'ci/github-script/package.json',
              'ci/github-script/package-lock.json',
              'ci/github-script/prepare.js',
              'ci/github-script/reviewers.js',
              'ci/github-script/reviews.js',
              'ci/github-script/supportedBranches.js',
              'ci/github-script/supportedSystems.js',
              'ci/github-script/withRateLimit.js',
              'ci/pinned.json',
              'pkgs/top-level/release-supported-systems.json',
            ].includes(file))) core.setOutput('pr', true)

  merge-group:
    if: needs.prepare.outputs.merge-group
    name: Merge Group
    needs: [prepare]
    uses: ./.github/workflows/merge-group.yml
    # Those are actually only used on the merge_group event, but will throw an error if not set.
    permissions:
      pull-requests: write # unused on pull_request, required by merge-group workflow
      statuses: write # unused on pull_request, required by merge-group workflow
    with:
      artifact-prefix: mg-
      mergedSha: ${{ needs.prepare.outputs.mergedSha }}
      targetSha: ${{ needs.prepare.outputs.targetSha }}

  pr:
    if: needs.prepare.outputs.pr
    name: PR
    needs: [prepare]
    uses: ./.github/workflows/pull-request-target.yml
    # Those are actually only used on the pull_request_target event, but will throw an error if not set.
    permissions:
      issues: write # unused on pull_request, required by bot workflow
      pull-requests: write # unused on pull_request, required by PR workflow
      statuses: write # unused on pull_request, required by PR workflow
    secrets:
      NIXPKGS_CI_APP_PRIVATE_KEY: ${{ secrets.NIXPKGS_CI_APP_PRIVATE_KEY }}
      NIXPKGS_BRANCH_CHECK_APP_PRIVATE_KEY: ${{ secrets.NIXPKGS_BRANCH_CHECK_APP_PRIVATE_KEY }}
      NIXPKGS_COMMIT_CHECK_APP_PRIVATE_KEY: ${{ secrets.NIXPKGS_COMMIT_CHECK_APP_PRIVATE_KEY }}
      NIXPKGS_MANUAL_EDIT_CHECK_APP_PRIVATE_KEY: ${{ secrets.NIXPKGS_MANUAL_EDIT_CHECK_APP_PRIVATE_KEY }}
    with:
      artifact-prefix: pr-