ci/github-script: default to commonjs

Since all github-scripts need to be written in commonjs, we now default
to it by not setting package.json. Support from editors for .js files is
slightly better than .cjs. To still allow using module imports in the
test runner script, we trick node into loading the script itself as a
module again via `--import ./run`.
This commit is contained in:
Wolfgang Walther 2025-07-12 15:56:29 +02:00
parent aaaabe0cb7
commit d11eba1e1d
No known key found for this signature in database
GPG Key ID: B39893FA5F65CAE1
6 changed files with 5 additions and 7 deletions

View File

@ -69,7 +69,7 @@ jobs:
github-token: ${{ steps.app-token.outputs.token || github.token }} github-token: ${{ steps.app-token.outputs.token || github.token }}
retries: 3 retries: 3
script: | script: |
require('./ci/github-script/labels.cjs')({ require('./ci/github-script/labels.js')({
github, github,
context, context,
core, core,

View File

@ -1,4 +1,3 @@
# TODO: Move to <top-level>/.editorconfig, once ci/.editorconfig has made its way through staging. [run]
[*.cjs]
indent_style = space indent_style = space
indent_size = 2 indent_size = 2

View File

@ -10,4 +10,4 @@ To run any of the scripts locally:
## Labeler ## Labeler
Run `./run.js labels OWNER REPO`, where OWNER is your username or "NixOS" and REPO the name of your fork or "nixpkgs". Run `./run labels OWNER REPO`, where OWNER is your username or "NixOS" and REPO the name of your fork or "nixpkgs".

View File

@ -1,6 +1,5 @@
{ {
"private": true, "private": true,
"type": "module",
"dependencies": { "dependencies": {
"@actions/artifact": "2.3.2", "@actions/artifact": "2.3.2",
"@actions/github": "6.0.1", "@actions/github": "6.0.1",

View File

@ -1,4 +1,4 @@
#!/usr/bin/env node #!/usr/bin/env -S node --import ./run
import { execSync } from 'node:child_process' import { execSync } from 'node:child_process'
import { mkdtempSync, rmSync } from 'node:fs' import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os' import { tmpdir } from 'node:os'
@ -48,7 +48,7 @@ program
.argument('<owner>', 'Owner of the GitHub repository to label (Example: NixOS)') .argument('<owner>', 'Owner of the GitHub repository to label (Example: NixOS)')
.argument('<repo>', 'Name of the GitHub repository to label (Example: nixpkgs)') .argument('<repo>', 'Name of the GitHub repository to label (Example: nixpkgs)')
.action(async (owner, repo) => { .action(async (owner, repo) => {
const labels = (await import('./labels.cjs')).default const labels = (await import('./labels.js')).default
run(labels, owner, repo) run(labels, owner, repo)
}) })