Skip to content

Commit 2496d47

Browse files
committed
ci/github-script/check-target-branch: convert to TypeScript
Only doing this one for now as a proof-of-concept.
1 parent 7045e3a commit 2496d47

4 files changed

Lines changed: 49 additions & 37 deletions

File tree

‎.github/workflows/eval.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ jobs:
375375
with:
376376
github-token: ${{ steps.app-token.outputs.token || github.token }}
377377
script: |
378-
require('./nixpkgs/trusted/ci/github-script/check-target-branch.js')({
378+
require('./nixpkgs/trusted/ci/github-script/check-target-branch.ts')({
379379
github,
380380
context,
381381
core,

‎.github/workflows/test.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
'.github/workflows/pull-request-target.yml',
7878
'.github/workflows/test.yml',
7979
'ci/github-script/bot.js',
80-
'ci/github-script/check-target-branch.js',
80+
'ci/github-script/check-target-branch.ts',
8181
'ci/github-script/commits.js',
8282
'ci/github-script/get-pr-commit-details.js',
8383
'ci/github-script/lint-commits.js',
Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import type * as actionsCore from '@actions/core'
2+
import type { context as actionsContext } from '@actions/github'
3+
import type { GitHub } from '@actions/github/lib/utils'
4+
15
// TODO: should this be combined with the branch checks in prepare.js?
26
// They do seem quite similar, but this needs to run after eval,
37
// and prepare.js obviously doesn't.
@@ -7,39 +11,47 @@ const { readFile } = require('node:fs/promises')
711
const { postReview, dismissReviews } = require('./reviews.js')
812

913
const reviewKey = 'check-target-branch'
10-
/**
11-
* @param {{
12-
* github: InstanceType<import('@actions/github/lib/utils').GitHub>,
13-
* context: typeof import('@actions/github').context
14-
* core: import('@actions/core')
15-
* dry: boolean
16-
* }} CheckTargetBranchProps
17-
*/
18-
async function checkTargetBranch({ github, context, core, dry }) {
19-
/**
20-
* @type {{
21-
* attrdiff: {
22-
* added: string[],
23-
* changed: string[],
24-
* removed: string[],
25-
* },
26-
* attrdiffByKernel: Record<string, {
27-
* added: string[],
28-
* changed: string[],
29-
* removed: string[],
30-
* }>,
31-
* attrdiffByPlatform: Record<string, {
32-
* added: string[],
33-
* changed: string[],
34-
* removed: string[],
35-
* }>,
36-
* labels: Record<string, boolean>,
37-
* rebuildCountByKernel: Record<string, number>,
38-
* rebuildsByKernel: Record<string, string[]>,
39-
* rebuildsByPlatform: Record<string, string[]>,
40-
* }}
41-
*/
42-
const changed = JSON.parse(
14+
15+
type ChangedPaths = {
16+
attrdiff: {
17+
added: string[]
18+
changed: string[]
19+
removed: string[]
20+
}
21+
attrdiffByKernel: Record<
22+
string,
23+
{
24+
added: string[]
25+
changed: string[]
26+
removed: string[]
27+
}
28+
>
29+
attrdiffByPlatform: Record<
30+
string,
31+
{
32+
added: string[]
33+
changed: string[]
34+
removed: string[]
35+
}
36+
>
37+
labels: Record<string, boolean>
38+
rebuildCountByKernel: Record<string, number>
39+
rebuildsByKernel: Record<string, string[]>
40+
rebuildsByPlatform: Record<string, string[]>
41+
}
42+
43+
async function checkTargetBranch({
44+
github,
45+
context,
46+
core,
47+
dry,
48+
}: {
49+
github: InstanceType<typeof GitHub>
50+
context: typeof actionsContext
51+
core: typeof actionsCore
52+
dry: boolean
53+
}) {
54+
const changed: ChangedPaths = JSON.parse(
4355
await readFile('comparison/changed-paths.json', 'utf-8'),
4456
)
4557
const pull_number = context.payload.pull_request?.number
@@ -153,7 +165,7 @@ async function checkTargetBranch({ github, context, core, dry }) {
153165
reviewKey,
154166
})
155167
} else if (rebuildsAllTests && !isExemptKernelUpdate) {
156-
let branchText
168+
let branchText: string
157169
if (base === 'master' && maxRebuildCount >= 500) {
158170
branchText = '(probably either `staging-nixos` or `staging`)'
159171
} else if (base === 'master') {

‎ci/github-script/run‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ program
112112
.argument('<repo>', 'Name of the GitHub repository to run on (Example: nixpkgs)')
113113
.argument('<pr>', 'Number of the Pull Request to run on')
114114
.action(async (owner, repo, pr, options) => {
115-
const checkTargetBranch = (await import('./check-target-branch.js')).default
115+
const checkTargetBranch = (await import('./check-target-branch.ts')).default
116116
await run(checkTargetBranch, owner, repo, pr, options)
117117
})
118118

0 commit comments

Comments
 (0)