ci/labels: run in dry mode locally

To avoid mistakes when developing and testing against the upstream repo.
This commit is contained in:
Wolfgang Walther 2025-07-07 20:06:12 +02:00
parent 9936e7d751
commit dd8357185a
No known key found for this signature in database
GPG Key ID: B39893FA5F65CAE1
4 changed files with 19 additions and 13 deletions

View File

@ -73,6 +73,7 @@ jobs:
github,
context,
core,
dry: context.eventName == 'pull_request'
})
- name: Log current API rate limits

View File

@ -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".

View File

@ -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.

View File

@ -38,6 +38,7 @@ try {
process.exitCode = 1
},
},
dry: true,
})
} finally {
rmSync(tmp, { recursive: true })