From e23bb18fa9e376dc42d0b9be9a84e6af08eed868 Mon Sep 17 00:00:00 2001 From: Michael Daniels Date: Sat, 8 Aug 2026 10:22:59 -0400 Subject: [PATCH] ci/github-script/check-target-branch: convert to TypeScript Only doing this one for now as a proof-of-concept. (cherry picked from commit 2496d47b76de79baeed8543a9a9b22d3a45807e9) --- .github/workflows/eval.yml | 2 +- .github/workflows/test.yml | 2 +- ...arget-branch.js => check-target-branch.ts} | 80 +++++++++++-------- ci/github-script/run | 2 +- 4 files changed, 49 insertions(+), 37 deletions(-) rename ci/github-script/{check-target-branch.js => check-target-branch.ts} (87%) diff --git a/.github/workflows/eval.yml b/.github/workflows/eval.yml index eee506a87165..4bed665957f5 100644 --- a/.github/workflows/eval.yml +++ b/.github/workflows/eval.yml @@ -375,7 +375,7 @@ jobs: with: github-token: ${{ steps.app-token.outputs.token || github.token }} script: | - require('./nixpkgs/trusted/ci/github-script/check-target-branch.js')({ + require('./nixpkgs/trusted/ci/github-script/check-target-branch.ts')({ github, context, core, diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 46a399cb7752..fac0be466bb8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -77,7 +77,7 @@ jobs: '.github/workflows/pull-request-target.yml', '.github/workflows/test.yml', 'ci/github-script/bot.js', - 'ci/github-script/check-target-branch.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', diff --git a/ci/github-script/check-target-branch.js b/ci/github-script/check-target-branch.ts similarity index 87% rename from ci/github-script/check-target-branch.js rename to ci/github-script/check-target-branch.ts index 6e2e449eb6ea..1b1f2c4e8b03 100644 --- a/ci/github-script/check-target-branch.js +++ b/ci/github-script/check-target-branch.ts @@ -1,3 +1,7 @@ +import type * as actionsCore from '@actions/core' +import type { context as actionsContext } from '@actions/github' +import type { GitHub } from '@actions/github/lib/utils' + // TODO: should this be combined with the branch checks in prepare.js? // They do seem quite similar, but this needs to run after eval, // and prepare.js obviously doesn't. @@ -7,39 +11,47 @@ const { readFile } = require('node:fs/promises') const { postReview, dismissReviews } = require('./reviews.js') const reviewKey = 'check-target-branch' -/** - * @param {{ - * github: InstanceType, - * context: typeof import('@actions/github').context - * core: import('@actions/core') - * dry: boolean - * }} CheckTargetBranchProps - */ -async function checkTargetBranch({ github, context, core, dry }) { - /** - * @type {{ - * attrdiff: { - * added: string[], - * changed: string[], - * removed: string[], - * }, - * attrdiffByKernel: Record, - * attrdiffByPlatform: Record, - * labels: Record, - * rebuildCountByKernel: Record, - * rebuildsByKernel: Record, - * rebuildsByPlatform: Record, - * }} - */ - const changed = JSON.parse( + +type ChangedPaths = { + attrdiff: { + added: string[] + changed: string[] + removed: string[] + } + attrdiffByKernel: Record< + string, + { + added: string[] + changed: string[] + removed: string[] + } + > + attrdiffByPlatform: Record< + string, + { + added: string[] + changed: string[] + removed: string[] + } + > + labels: Record + rebuildCountByKernel: Record + rebuildsByKernel: Record + rebuildsByPlatform: Record +} + +async function checkTargetBranch({ + github, + context, + core, + dry, +}: { + github: InstanceType + context: typeof actionsContext + core: typeof actionsCore + dry: boolean +}) { + const changed: ChangedPaths = JSON.parse( await readFile('comparison/changed-paths.json', 'utf-8'), ) const pull_number = context.payload.pull_request?.number @@ -153,7 +165,7 @@ async function checkTargetBranch({ github, context, core, dry }) { reviewKey, }) } else if (rebuildsAllTests && !isExemptKernelUpdate) { - let branchText + let branchText: string if (base === 'master' && maxRebuildCount >= 500) { branchText = '(probably either `staging-nixos` or `staging`)' } else if (base === 'master') { diff --git a/ci/github-script/run b/ci/github-script/run index 522a4dbebbdd..51ba00cc0d39 100755 --- a/ci/github-script/run +++ b/ci/github-script/run @@ -112,7 +112,7 @@ program .argument('', 'Name of the GitHub repository to run on (Example: nixpkgs)') .argument('', 'Number of the Pull Request to run on') .action(async (owner, repo, pr, options) => { - const checkTargetBranch = (await import('./check-target-branch.js')).default + const checkTargetBranch = (await import('./check-target-branch.ts')).default await run(checkTargetBranch, owner, repo, pr, options) })