From d11eba1e1d3a899db5d794836baa837e955b652a Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Sat, 12 Jul 2025 15:56:29 +0200 Subject: [PATCH] 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`. --- .github/workflows/labels.yml | 2 +- ci/github-script/.editorconfig | 3 +-- ci/github-script/README.md | 2 +- ci/github-script/{labels.cjs => labels.js} | 0 ci/github-script/package.json | 1 - ci/github-script/{run.js => run} | 4 ++-- 6 files changed, 5 insertions(+), 7 deletions(-) rename ci/github-script/{labels.cjs => labels.js} (100%) rename ci/github-script/{run.js => run} (93%) diff --git a/.github/workflows/labels.yml b/.github/workflows/labels.yml index ff6905d62164..14876ecf6294 100644 --- a/.github/workflows/labels.yml +++ b/.github/workflows/labels.yml @@ -69,7 +69,7 @@ jobs: github-token: ${{ steps.app-token.outputs.token || github.token }} retries: 3 script: | - require('./ci/github-script/labels.cjs')({ + require('./ci/github-script/labels.js')({ github, context, core, diff --git a/ci/github-script/.editorconfig b/ci/github-script/.editorconfig index 08ca1a194873..67d678ef170c 100644 --- a/ci/github-script/.editorconfig +++ b/ci/github-script/.editorconfig @@ -1,4 +1,3 @@ -# TODO: Move to /.editorconfig, once ci/.editorconfig has made its way through staging. -[*.cjs] +[run] indent_style = space indent_size = 2 diff --git a/ci/github-script/README.md b/ci/github-script/README.md index e71a4f173c57..8ffff0c40922 100644 --- a/ci/github-script/README.md +++ b/ci/github-script/README.md @@ -10,4 +10,4 @@ To run any of the scripts locally: ## 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". diff --git a/ci/github-script/labels.cjs b/ci/github-script/labels.js similarity index 100% rename from ci/github-script/labels.cjs rename to ci/github-script/labels.js diff --git a/ci/github-script/package.json b/ci/github-script/package.json index 906f371f0d5d..4671dd41f0cd 100644 --- a/ci/github-script/package.json +++ b/ci/github-script/package.json @@ -1,6 +1,5 @@ { "private": true, - "type": "module", "dependencies": { "@actions/artifact": "2.3.2", "@actions/github": "6.0.1", diff --git a/ci/github-script/run.js b/ci/github-script/run similarity index 93% rename from ci/github-script/run.js rename to ci/github-script/run index 5127a6a0ee95..1b670a8b2875 100755 --- a/ci/github-script/run.js +++ b/ci/github-script/run @@ -1,4 +1,4 @@ -#!/usr/bin/env node +#!/usr/bin/env -S node --import ./run import { execSync } from 'node:child_process' import { mkdtempSync, rmSync } from 'node:fs' import { tmpdir } from 'node:os' @@ -48,7 +48,7 @@ program .argument('', 'Owner of the GitHub repository to label (Example: NixOS)') .argument('', 'Name of the GitHub repository to label (Example: nixpkgs)') .action(async (owner, repo) => { - const labels = (await import('./labels.cjs')).default + const labels = (await import('./labels.js')).default run(labels, owner, repo) })