Skip to content

Commit 31be06a

Browse files
authored
ci/github-script: prep for typescript, convert check-target-branch (#550500)
2 parents fa1cd8e + 2496d47 commit 31be06a

22 files changed

Lines changed: 496 additions & 65 deletions

‎.editorconfig‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ insert_final_newline = false
2323

2424
# see https://nixos.org/nixpkgs/manual/#chap-conventions
2525

26-
[*.{bash,css,js,json,lock,md,nix,pl,pm,py,rb,sh,xml}]
26+
[*.{bash,css,js,json,lock,md,nix,pl,pm,py,rb,sh,ts,xml}]
2727
indent_style = space
2828

2929
# Match docbook files, set indent width of one
3030
[*.xml]
3131
indent_size = 1
3232

33-
# Match json/lockfiles/markdown/nix/ruby files, set indent width of two
34-
[*.{js,json,lock,md,nix,rb}]
33+
# Match js/json/lockfiles/markdown/nix/ruby/ts files, set indent width of two
34+
[*.{js,json,lock,md,nix,rb,ts}]
3535
indent_size = 2
3636

3737
# Match all the Bash code in Nix files, set indent width of two

‎.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',

‎ci/github-script/.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
comparison
2+
comparison.zip
13
node_modules
24
step-summary.md

‎ci/github-script/bot.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-nocheck
12
module.exports = async ({ github, context, core, dry }) => {
23
const path = require('node:path')
34
const { DefaultArtifactClient } = await import('@actions/artifact')
Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
/// @ts-check
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'
24

35
// TODO: should this be combined with the branch checks in prepare.js?
46
// They do seem quite similar, but this needs to run after eval,
@@ -9,39 +11,47 @@ const { readFile } = require('node:fs/promises')
911
const { postReview, dismissReviews } = require('./reviews.js')
1012

1113
const reviewKey = 'check-target-branch'
12-
/**
13-
* @param {{
14-
* github: InstanceType<import('@actions/github/lib/utils').GitHub>,
15-
* context: typeof import('@actions/github').context
16-
* core: import('@actions/core')
17-
* dry: boolean
18-
* }} CheckTargetBranchProps
19-
*/
20-
async function checkTargetBranch({ github, context, core, dry }) {
21-
/**
22-
* @type {{
23-
* attrdiff: {
24-
* added: string[],
25-
* changed: string[],
26-
* removed: string[],
27-
* },
28-
* attrdiffByKernel: Record<string, {
29-
* added: string[],
30-
* changed: string[],
31-
* removed: string[],
32-
* }>,
33-
* attrdiffByPlatform: Record<string, {
34-
* added: string[],
35-
* changed: string[],
36-
* removed: string[],
37-
* }>,
38-
* labels: Record<string, boolean>,
39-
* rebuildCountByKernel: Record<string, number>,
40-
* rebuildsByKernel: Record<string, string[]>,
41-
* rebuildsByPlatform: Record<string, string[]>,
42-
* }}
43-
*/
44-
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(
4555
await readFile('comparison/changed-paths.json', 'utf-8'),
4656
)
4757
const pull_number = context.payload.pull_request?.number
@@ -155,7 +165,7 @@ async function checkTargetBranch({ github, context, core, dry }) {
155165
reviewKey,
156166
})
157167
} else if (rebuildsAllTests && !isExemptKernelUpdate) {
158-
let branchText
168+
let branchText: string
159169
if (base === 'master' && maxRebuildCount >= 500) {
160170
branchText = '(probably either `staging-nixos` or `staging`)'
161171
} else if (base === 'master') {

‎ci/github-script/commits.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-nocheck
12
module.exports = async ({ github, context, core, dry, cherryPicks }) => {
23
const { execFileSync } = require('node:child_process')
34
const { classify } = require('../supportedBranches.js')

‎ci/github-script/get-pr-commit-details.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @ts-check
1+
// @ts-nocheck
22
const { promisify } = require('node:util')
33
const execFile = promisify(require('node:child_process').execFile)
44

@@ -16,7 +16,7 @@ const execFile = promisify(require('node:child_process').execFile)
1616
/**
1717
* @param {{
1818
* args: string[]
19-
* core: import('@actions/core'),
19+
* core: typeof import('@actions/core'),
2020
* quiet?: boolean,
2121
* repoPath?: string,
2222
* }} RunGitProps
@@ -40,7 +40,7 @@ async function runGit({ args, repoPath, core, quiet }) {
4040
* of 250 commits and doesn't return the changed files.
4141
*
4242
* @param {{
43-
* core: import('@actions/core'),
43+
* core: typeof import('@actions/core'),
4444
* pr: Awaited<ReturnType<InstanceType<import('@actions/github/lib/utils').GitHub>["rest"]["pulls"]["get"]>>["data"]
4545
* repoPath?: string,
4646
* }} GetCommitMessagesForPRProps

‎ci/github-script/get-teams.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-nocheck
12
const excludeTeams = [
23
/^voters.*$/,
34
/^nixpkgs-maintainers$/,

‎ci/github-script/lint-commits.js‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
// @ts-check
21
const { classify } = require('../supportedBranches.js')
32
const { getCommitDetailsForPR } = require('./get-pr-commit-details.js')
43

54
/** @typedef {import('./get-pr-commit-details.js').Commit} Commit */
65

76
/**
87
* @param {{
9-
* github: InstanceType<import('@actions/github/lib/utils').GitHub>,
8+
* github: InstanceType<typeof import('@actions/github/lib/utils').GitHub>,
109
* context: typeof import('@actions/github').context,
11-
* core: import('@actions/core'),
10+
* core: typeof import('@actions/core'),
1211
* repoPath?: string,
1312
* }} LintCommitsProps
1413
*/
@@ -57,7 +56,7 @@ async function lintCommits({ github, context, core, repoPath }) {
5756
/**
5857
* @param {{
5958
* commits: Commit[],
60-
* core: import('@actions/core'),
59+
* core: typeof import('@actions/core'),
6160
* }} CheckCommitMessagesProps
6261
*/
6362
async function checkCommitMessages({ commits, core }) {
@@ -170,7 +169,7 @@ async function checkCommitMessages({ commits, core }) {
170169
/**
171170
* @param {{
172171
* commits: Commit[],
173-
* core: import('@actions/core'),
172+
* core: typeof import('@actions/core'),
174173
* }} CheckGitFieldsProps
175174
*/
176175
async function checkCommitMetadata({ commits, core }) {

0 commit comments

Comments
 (0)