@zairakai/js-dev-tools 3.6.0 → 3.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -60,6 +60,15 @@ stages:
60
60
  - publish
61
61
  - release
62
62
 
63
+ # ================================
64
+ # RUNNERS
65
+ # ================================
66
+ # Every job runs on the self-hosted runner of the group, whatever the shared runners enabled on the project.
67
+ # Only js:publish leaves it: npm trusted publishing does not accept a self-hosted runner.
68
+ default:
69
+ tags:
70
+ - zairakai-ci
71
+
63
72
  # ================================
64
73
  # DEFAULT VARIABLES
65
74
  # ================================
@@ -376,18 +385,22 @@ js:publish:
376
385
  <<: [*base_job, *cache_node]
377
386
  stage: publish
378
387
  image: ${NODE_IMAGE}
388
+ # Trusted publishing: npm trusts this project and this job, and the OIDC token below authenticates the publication.
389
+ # No npm token is stored anywhere. npm accepts only the shared runners of GitLab.com (not a self-hosted runner),
390
+ # so this job is the only one that uses them. The tag is the one of GitLab, it cannot be renamed.
391
+ tags:
392
+ - saas-linux-small-amd64
393
+ id_tokens:
394
+ NPM_ID_TOKEN:
395
+ aud: "npm:registry.npmjs.org"
396
+ # Lets npm sign the provenance: the package page shows it was built on GitLab from this project.
397
+ SIGSTORE_ID_TOKEN:
398
+ aud: sigstore
379
399
  rules:
380
400
  - if: $UPDATE_DEPENDENCIES == "true"
381
401
  when: never
382
402
  - if: $CI_COMMIT_TAG =~ $VERSION_TAG_REGEX
383
403
  script:
384
- - |
385
- if [[ -z "${NPM_TOKEN:-}" ]]; then
386
- echo "ERROR: NPM_TOKEN is not set or empty"
387
- echo "Go to: GitLab → Settings → CI/CD → Variables → add NPM_TOKEN (type: Variable, protected, masked)"
388
- exit 1
389
- fi
390
- - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > "${CI_PROJECT_DIR}/.npmrc"
391
404
  - |
392
405
  # A pre-release (2.3.0-rc.1) goes to the npm tag "next", so it never becomes "latest"
393
406
  npm_tag="latest"
@@ -396,7 +409,7 @@ js:publish:
396
409
  fi
397
410
  echo "Publishing ${NPM_PACKAGE_NAME}@${CI_COMMIT_TAG} to npm (tag ${npm_tag})..."
398
411
  npm version "${CI_COMMIT_TAG}" --no-git-tag-version --allow-same-version
399
- npm publish --access public --tag "${npm_tag}"
412
+ npm publish --provenance --access public --tag "${npm_tag}"
400
413
  environment:
401
414
  name: production
402
415
  url: https://www.npmjs.com/package/${NPM_PACKAGE_NAME}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zairakai/js-dev-tools",
3
- "version": "3.6.0",
3
+ "version": "3.7.1",
4
4
  "description": "The unified and centralized development toolkit for JavaScript/TypeScript projects - ESLint, Prettier, Stylelint, Knip, Vitest, Git Hooks, and GitLab CI pipeline templates",
5
5
  "keywords": [
6
6
  "dev-tools",
@@ -26,6 +26,7 @@ import { existsSync, readFileSync } from 'node:fs'
26
26
  import { pathToFileURL } from 'node:url'
27
27
 
28
28
  const CONFIG_FILE = '.dependency-update.json'
29
+ const PIPELINE_FILE = '.gitlab-ci.yml'
29
30
  const COMMIT_SUBJECT = 'chore(deps): update the dependencies'
30
31
  const BRANCH_PREFIX = 'chore/update-dependencies'
31
32
 
@@ -152,6 +153,16 @@ export function planTag({ config, last, commits, before, after, sections = RUNTI
152
153
  return { version: nextVersion(last, config.tag.level), reason: 'a published range changed' }
153
154
  }
154
155
 
156
+ /**
157
+ * True when a diff changes one `ref:` line and nothing else. The install of the tools moves the `ref:` of the shared
158
+ * pipeline to the installed version: that is the only change of the pipeline file an update may commit.
159
+ */
160
+ export function isRefOnlyChange(diff) {
161
+ const changed = diff.split('\n').filter((line) => /^[+-]/.test(line) && !/^(\+\+\+|---)/.test(line))
162
+
163
+ return 2 === changed.length && changed.every((line) => /^[+-]\s*ref:\s*\S+\s*$/.test(line))
164
+ }
165
+
155
166
  // ---------------------------------------------------------------------------------------------------------------------
156
167
 
157
168
  const log = (message) => console.info(message)
@@ -336,6 +347,11 @@ async function update(config) {
336
347
  // Only the manifest and the lock file: the postinstall of the tools can rewrite other files of the project in CI.
337
348
  const files = [ecosystem.file, ...['package-lock.json', 'composer.lock'].filter((file) => existsSync(file))]
338
349
 
350
+ // The one exception: the `ref:` of the shared pipeline follows the installed version of the tools.
351
+ if (existsSync(PIPELINE_FILE) && isRefOnlyChange(run('git', ['diff', '-U0', '--', PIPELINE_FILE]))) {
352
+ files.push(PIPELINE_FILE)
353
+ }
354
+
339
355
  if ('' === run('git', ['status', '--porcelain', '--', ...files])) {
340
356
  log('Everything is up to date.')
341
357
  return