From dd8357185a38ce53d91f1566372710f6fc121228 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Mon, 7 Jul 2025 20:06:12 +0200 Subject: [PATCH] ci/labels: run in dry mode locally To avoid mistakes when developing and testing against the upstream repo. --- .github/workflows/labels.yml | 1 + ci/labels/README.md | 2 +- ci/labels/labels.cjs | 28 ++++++++++++++++------------ ci/labels/run.js | 1 + 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/.github/workflows/labels.yml b/.github/workflows/labels.yml index e4a4205f3eba..f5a04ad073bc 100644 --- a/.github/workflows/labels.yml +++ b/.github/workflows/labels.yml @@ -73,6 +73,7 @@ jobs: github, context, core, + dry: context.eventName == 'pull_request' }) - name: Log current API rate limits diff --git a/ci/labels/README.md b/ci/labels/README.md index 4631437a9654..26cd88763fe6 100644 --- a/ci/labels/README.md +++ b/ci/labels/README.md @@ -1,4 +1,4 @@ To test the labeler locally: - Provide `gh` on `PATH` and make sure it's authenticated. - Enter `nix-shell` in `./ci/labels`. -- Run `./run.js OWNER REPO`, where OWNER is your username and REPO the name of your fork (normally nixpkgs). +- Run `./run.js OWNER REPO`, where OWNER is your username or "NixOS" and REPO the name of your fork or "nixpkgs". diff --git a/ci/labels/labels.cjs b/ci/labels/labels.cjs index ea30e2dc6244..5527059f6e45 100644 --- a/ci/labels/labels.cjs +++ b/ci/labels/labels.cjs @@ -1,4 +1,4 @@ -module.exports = async function ({ github, context, core }) { +module.exports = async function ({ github, context, core, dry }) { const Bottleneck = require('bottleneck') const path = require('node:path') const { DefaultArtifactClient } = require('@actions/artifact') @@ -314,7 +314,7 @@ module.exports = async function ({ github, context, core }) { const labels = Object.entries(after) .filter(([, value]) => value) .map(([name]) => name) - if (log('Set labels', labels, context.eventName == 'pull_request')) return + if (log('Set labels', labels, dry)) return await github.rest.issues.setLabels({ ...context.repo, @@ -422,16 +422,20 @@ module.exports = async function ({ github, context, core }) { cursor = new URL(next).searchParams.get('after') const uploadPath = path.resolve('cursor') await writeFile(uploadPath, cursor, 'utf-8') - // No stats.artifacts++, because this does not allow passing a custom token. - // Thus, the upload will not happen with the app token, but the default github.token. - await artifactClient.uploadArtifact( - 'pagination-cursor', - [uploadPath], - path.resolve('.'), - { - retentionDays: 1, - }, - ) + if (dry) { + core.info(`pagination-cursor: ${cursor} (upload skipped)`) + } else { + // No stats.artifacts++, because this does not allow passing a custom token. + // Thus, the upload will not happen with the app token, but the default github.token. + await artifactClient.uploadArtifact( + 'pagination-cursor', + [uploadPath], + path.resolve('.'), + { + retentionDays: 1, + }, + ) + } } // Some items might be in both search results, so filtering out duplicates as well. diff --git a/ci/labels/run.js b/ci/labels/run.js index 0a89e3d83f45..d7e8e9ff9401 100755 --- a/ci/labels/run.js +++ b/ci/labels/run.js @@ -38,6 +38,7 @@ try { process.exitCode = 1 }, }, + dry: true, }) } finally { rmSync(tmp, { recursive: true })