Skip to content

ci: typecheck github-script code#485846

Open
philiptaron wants to merge 9 commits intoNixOS:masterfrom
philiptaron:type-check-ci-code
Open

ci: typecheck github-script code#485846
philiptaron wants to merge 9 commits intoNixOS:masterfrom
philiptaron:type-check-ci-code

Conversation

@philiptaron
Copy link
Contributor

@philiptaron philiptaron commented Feb 1, 2026

Summary

Add TypeScript type checking for ci/github-script/ JavaScript files to catch bugs at development time rather than in production.

Motivation

While reviewing PR #456481, I found several bugs that TypeScript's --checkJs mode catches automatically:

  • Set.length instead of Set.size (silent failure)
  • Undeclared loop variables (implicit globals)
  • Missing required function parameters
  • Incorrect API usage

Changes

Infrastructure (commit 1):

  • Add jsconfig.json with checkJs: true
  • Add typescript and @types/node as devDependencies

Bug fixes (commits 2-8):

  • commits.js: Add missing core parameter, declare loop variable
  • bot.js: Add missing workflowRunId to artifact downloads, fix Date arithmetic
  • reviews.js: Mark optional parameter as optional in JSDoc
  • merge.js: Add default values for optional parameters
  • withRateLimit.js: Suppress errors for untyped bottleneck package
  • supportedBranches.js: Replace deprecated module.parent

CI integration (commit 9):

  • Add typecheck-ci-scripts derivation in ci/github-script/default.nix
  • Expose via nix-build ci -A typecheck-ci-scripts
  • Add typecheck-ci-scripts command to repository's nix-shell
  • Update documentation in both ci/README.md and ci/github-script/README.md

I didn't wire this into any ran-by-CI workflow because I ran out of time. But having it here is a step in that direction.

Testing

Run nix-build ci -A typecheck-ci-scripts or nix-shell --run typecheck-ci-scripts.

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add jsconfig.json with checkJs enabled to catch common JavaScript bugs
like using Set.length instead of Set.size, undeclared variables, and
mismatched function signatures.

Add typescript and @types/node as devDependencies. Document how to run
the type checker in README.md.
The dismissReviews function requires core for logging warnings, but
the call site was missing this parameter. Found by TypeScript.
The for-of loop was using an undeclared variable 'line', which would
create an implicit global. Add const declaration. Found by TypeScript.
Add missing workflowRunId parameter to all downloadArtifact calls.
The @actions/artifact API requires this field in the findBy object.

Also fix Date arithmetic by calling .getTime() - TypeScript correctly
flags that Date objects can't be subtracted from numbers without
explicit conversion.

Found by TypeScript.
The postReview function has a default value for event, so the JSDoc
type should mark it as optional with ?. Found by TypeScript.
The runChecklist function is intentionally called without user and
userIsMaintainer when checking label eligibility (vs actual merging).
Add default values to make this explicit. Found by TypeScript.
The bottleneck npm package doesn't have TypeScript type definitions.
Add @ts-expect-error comments to suppress the "not constructable"
errors while still enabling type checking for the rest of the file.
module.parent has been deprecated since Node.js 14. Use the modern
require.main === module pattern instead. Found by TypeScript.
Add a Nix derivation that runs TypeScript type checking on the
ci/github-script JavaScript files. This ensures type errors are caught
in CI, not just locally.

The check is defined in ci/github-script/default.nix and exposed via:
- `nix-build ci -A typecheck-ci-scripts`
- `typecheck-ci-scripts` command in the development shell (via passthru.driver)
@philiptaron philiptaron requested a review from a team February 1, 2026 05:29
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. 6.topic: continuous integration Affects continuous integration (CI) in Nixpkgs, including Ofborg and GitHub Actions backport release-25.11 Backport PR automatically labels Feb 1, 2026
Copy link
Member

@mdaniels5757 mdaniels5757 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! A couple of minor things:

One issue (which is mostly pre-existing, but made a bit worse here): nodejs is v24 on master (and v24 is used by actions/github-script). But nodejs is v22 on stable, and the @types/node version added in this PR is v22 as well. I think pinning to v24 would be prudent, given that's what is used by actions/github-script.

In addition to the suggestions below, there's one more place to pin nodejs to 24 in: ci/github-script/shell.nix (which is untouched by this PR).

Also in ci/github-script/shell.nix, it would also be nice to add (pkgs.callPackage ./. { }).passthru.driver to packages, so typecheck-ci-scripts can be run directly from the shell without extra nix-shell/nix-build invocations. (The documentation could then be updated accordingly.)

"commander": "14.0.0"
},
"devDependencies": {
"@types/node": "^22.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node 24 is used by the github-script action, and is the current version of nodejs on master.

package-lock.json will also need to be updated, of course.

Suggested change
"@types/node": "^22.0.0",
"@types/node": "^24.0.0",

# Type check the CI scripts in ci/github-script using TypeScript
{
importNpmLock,
nodejs,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nodejs on master is v24, but v22 on stable.

Suggested change
nodejs,
nodejs_24,

let
npmDeps = importNpmLock.buildNodeModules {
npmRoot = ./.;
inherit nodejs;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
inherit nodejs;
nodejs = nodejs_24;

in
runCommand "typecheck-ci-scripts"
{
nativeBuildInputs = [ nodejs ];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
nativeBuildInputs = [ nodejs ];
nativeBuildInputs = [ nodejs_24 ];

@@ -1,3 +1,3 @@
#!/usr/bin/env nix-shell
/*
#!nix-shell -i node -p nodejs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#!nix-shell -i node -p nodejs_24

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this shebang isn't necessary anymore since it's always imported directly from node

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think I should delete this -- but instead of doing the "nix-build to run the tool thing that I have done, instead use nix-shell in the shebang to have the tool be runnable outside of Nix.

"allowJs": true,
"noEmit": true,
"target": "ES2024",
"lib": ["ESNext"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per https://github.com/tsconfig/bases/blob/main/bases/node24.json:

Suggested change
"lib": ["ESNext"],
"lib": [
"es2024",
"ESNext.Array",
"ESNext.Collection",
"ESNext.Error",
"ESNext.Iterator",
"ESNext.Promise"
],

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Feb 1, 2026
Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and tested (the type checks even work with my neovim), thank you!

I agree with @mdaniels5757 that it would be good to pin this to node 24 (even better would be if GitHub actions would use the node version from Nix, but oh well)

@@ -1,3 +1,3 @@
#!/usr/bin/env nix-shell
/*
#!nix-shell -i node -p nodejs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this shebang isn't necessary anymore since it's always imported directly from node

@nixpkgs-ci nixpkgs-ci bot added 12.approvals: 2 This PR was reviewed and approved by two persons. and removed 12.approvals: 1 This PR was reviewed and approved by one person. labels Feb 3, 2026
@philiptaron
Copy link
Contributor Author

Thanks for the reviews @infinisil and @mdaniels5757 -- will push an updated version sometime today hopefully. I plan on including a CI step gated on changes to these files so that it actually will mark the CI red if there are errors in typechecking. 🎉

@nixpkgs-ci nixpkgs-ci bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: continuous integration Affects continuous integration (CI) in Nixpkgs, including Ofborg and GitHub Actions 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. 12.approvals: 2 This PR was reviewed and approved by two persons. backport release-25.11 Backport PR automatically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants