@zairakai/js-dev-tools 3.20.0 → 3.21.0
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.
- package/.editorconfig +6 -72
- package/.gitlab/ci/parts/base.yml +95 -0
- package/.gitlab/ci/parts/publish.yml +156 -0
- package/.gitlab/ci/parts/quality.yml +161 -0
- package/.gitlab/ci/parts/security.yml +40 -0
- package/.gitlab/ci/parts/updates.yml +60 -0
- package/.gitlab/ci/pipeline-js-app.yml +19 -38
- package/.gitlab/ci/pipeline-js-package.yml +23 -528
- package/README.md +51 -6
- package/config/.markdownlintignore +9 -1
- package/config/.prettierignore +8 -0
- package/config/.stylelintignore +7 -0
- package/config/eslint.config.js +7 -1
- package/config/knip.config.js +2 -2
- package/package.json +28 -25
- package/scripts/build.sh +28 -28
- package/scripts/ci-quality.sh +6 -6
- package/scripts/config.sh +164 -148
- package/scripts/doctor.sh +12 -12
- package/scripts/eslint-fix.sh +8 -8
- package/scripts/eslint.sh +15 -15
- package/scripts/install-bats.sh +143 -146
- package/scripts/install-hooks.sh +108 -111
- package/scripts/install-markdownlint.sh +4 -4
- package/scripts/install-shellcheck.sh +135 -138
- package/scripts/knip.sh +7 -7
- package/scripts/markdownlint.sh +38 -38
- package/scripts/outdated.sh +30 -29
- package/scripts/prettier-fix.sh +13 -13
- package/scripts/prettier.sh +13 -13
- package/scripts/setup-project.sh +691 -629
- package/scripts/stylelint-fix.sh +17 -17
- package/scripts/stylelint.sh +18 -18
- package/scripts/test.sh +13 -11
- package/scripts/typecheck.sh +11 -11
- package/scripts/update-dependencies.mjs +68 -68
- package/scripts/validate-shellcheck.sh +18 -18
- package/stubs/githooks/commit-msg +18 -18
- package/stubs/githooks/pre-commit +19 -19
- package/stubs/githooks/pre-push +18 -18
- package/stubs/githooks/prepare-commit-msg +6 -6
- package/stubs/gitlab-ci/gitlab-ci.yml.stub +1 -1
- package/stubs/governance/CONTRIBUTING.md.stub +5 -3
- package/stubs/quality/eslint.config.js.stub +1 -1
- package/stubs/quality/knip.config.js.stub +1 -1
- package/stubs/style/prettier.config.js.stub +3 -3
- package/stubs/style/stylelint.config.js.stub +1 -1
- package/stubs/testing/vitest.config.js.stub +1 -1
|
@@ -100,8 +100,8 @@ export function latestTag(tags) {
|
|
|
100
100
|
export function nextVersion(last, level) {
|
|
101
101
|
const [major, minor, patch] = last.split('.').map(Number)
|
|
102
102
|
|
|
103
|
-
if ('major'
|
|
104
|
-
if ('minor'
|
|
103
|
+
if (level === 'major') return `${major + 1}.0.0`
|
|
104
|
+
if (level === 'minor') return `${major}.${minor + 1}.0`
|
|
105
105
|
|
|
106
106
|
return `${major}.${minor}.${patch + 1}`
|
|
107
107
|
}
|
|
@@ -148,9 +148,9 @@ export function formatChanges(rows) {
|
|
|
148
148
|
export function signerIdentity(env) {
|
|
149
149
|
const missing = ['GPG_PRIVATE_KEY_B64', 'RELEASE_SIGNER_NAME', 'RELEASE_SIGNER_EMAIL'].filter((name) => !env[name])
|
|
150
150
|
|
|
151
|
-
if (
|
|
151
|
+
if (missing.length > 0) {
|
|
152
152
|
throw new Error(
|
|
153
|
-
`${missing.join(', ')} not set: the commits and the tags are signed, see the handbook (versioning)
|
|
153
|
+
`${missing.join(', ')} not set: the commits and the tags are signed, see the handbook (versioning).`,
|
|
154
154
|
)
|
|
155
155
|
}
|
|
156
156
|
|
|
@@ -163,11 +163,11 @@ export function signerIdentity(env) {
|
|
|
163
163
|
|
|
164
164
|
/** What `tag` has to do: the version to create, or null (and why). */
|
|
165
165
|
export function planTag({ config, last, commits, before, after, sections = RUNTIME_SECTIONS }) {
|
|
166
|
-
if (
|
|
166
|
+
if (config.tag.when === 'never') return { version: null, reason: 'the project is never tagged by the update' }
|
|
167
167
|
if (!last) return { version: null, reason: 'there is no tag yet' }
|
|
168
|
-
if (
|
|
168
|
+
if (commits.length === 0) return { version: null, reason: 'no update since the last tag' }
|
|
169
169
|
|
|
170
|
-
if (
|
|
170
|
+
if (config.tag.when === 'runtime' && !runtimeChanged(before, after, sections)) {
|
|
171
171
|
return { version: null, reason: 'only the development dependencies changed: the published archive is the same' }
|
|
172
172
|
}
|
|
173
173
|
|
|
@@ -181,7 +181,7 @@ export function planTag({ config, last, commits, before, after, sections = RUNTI
|
|
|
181
181
|
export function isRefOnlyChange(diff) {
|
|
182
182
|
const changed = diff.split('\n').filter((line) => /^[+-]/.test(line) && !/^(\+\+\+|---)/.test(line))
|
|
183
183
|
|
|
184
|
-
return
|
|
184
|
+
return changed.length === 2 && changed.every((line) => /^[+-]\s*ref:\s*\S+\s*$/.test(line))
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
/** The problems of a policy document, as a list of sentences (empty when it is valid). */
|
|
@@ -193,20 +193,20 @@ export function validatePolicy(doc) {
|
|
|
193
193
|
|
|
194
194
|
doc.entries.forEach((entry, index) => {
|
|
195
195
|
const where = `entries[${index}]`
|
|
196
|
-
const name =
|
|
196
|
+
const name = typeof entry?.package === 'string' ? entry.package : ''
|
|
197
197
|
|
|
198
|
-
if (
|
|
198
|
+
if (name === '') errors.push(`${where}: "package" is missing.`)
|
|
199
199
|
else if (seen.has(name)) errors.push(`${where}: "${name}" is listed twice.`)
|
|
200
200
|
seen.add(name)
|
|
201
201
|
|
|
202
|
-
if (
|
|
202
|
+
if (typeof entry?.reason !== 'string' || entry.reason.trim() === '') errors.push(`${where}: "reason" is missing.`)
|
|
203
203
|
if (!/^\d{4}-\d{2}-\d{2}$/.test(entry?.since ?? '')) errors.push(`${where}: "since" must be a date (YYYY-MM-DD).`)
|
|
204
204
|
|
|
205
205
|
if (undefined !== entry?.unblock) {
|
|
206
206
|
const { version, peers } = entry.unblock ?? {}
|
|
207
207
|
|
|
208
|
-
if (
|
|
209
|
-
if (!Array.isArray(peers) ||
|
|
208
|
+
if (semver.valid(version) === null) errors.push(`${where}: "unblock.version" must be a version (X.Y.Z).`)
|
|
209
|
+
if (!Array.isArray(peers) || peers.length === 0 || !peers.every((peer) => typeof peer === 'string' && peer)) {
|
|
210
210
|
errors.push(`${where}: "unblock.peers" must be a list of packages.`)
|
|
211
211
|
}
|
|
212
212
|
}
|
|
@@ -219,7 +219,7 @@ export function validatePolicy(doc) {
|
|
|
219
219
|
export async function fetchPolicy(
|
|
220
220
|
ecosystem,
|
|
221
221
|
fetchImpl = fetch,
|
|
222
|
-
base = process.env.DEPENDENCY_POLICY_URL || POLICY_URL
|
|
222
|
+
base = process.env.DEPENDENCY_POLICY_URL || POLICY_URL,
|
|
223
223
|
) {
|
|
224
224
|
const url = `${base.replace(/\/$/, '')}/${POLICY_FILES[ecosystem]}`
|
|
225
225
|
let doc
|
|
@@ -233,7 +233,7 @@ export async function fetchPolicy(
|
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
const errors = validatePolicy(doc)
|
|
236
|
-
if (
|
|
236
|
+
if (errors.length > 0) throw new Error(`The dependency policy is not valid (${url}): ${errors.join(' ')}`)
|
|
237
237
|
|
|
238
238
|
return doc
|
|
239
239
|
}
|
|
@@ -251,7 +251,7 @@ export function isLifted(entry, ranges) {
|
|
|
251
251
|
const range = ranges[peer]
|
|
252
252
|
|
|
253
253
|
return (
|
|
254
|
-
|
|
254
|
+
typeof range === 'string' && semver.validRange(range) !== null && semver.satisfies(entry.unblock.version, range)
|
|
255
255
|
)
|
|
256
256
|
})
|
|
257
257
|
}
|
|
@@ -261,7 +261,7 @@ export function lockedVersions(lock) {
|
|
|
261
261
|
const versions = {}
|
|
262
262
|
|
|
263
263
|
for (const [path, info] of Object.entries(lock?.packages ?? {})) {
|
|
264
|
-
if (
|
|
264
|
+
if (path === '' || !info?.version) continue
|
|
265
265
|
|
|
266
266
|
const name = path.slice(path.lastIndexOf('node_modules/') + 'node_modules/'.length)
|
|
267
267
|
versions[name] = [...new Set([...(versions[name] ?? []), info.version])].sort()
|
|
@@ -278,7 +278,7 @@ export function policyViolations({ blocked, beforeManifest, afterManifest, befor
|
|
|
278
278
|
const problems = []
|
|
279
279
|
|
|
280
280
|
for (const row of diffDependencies(beforeManifest, afterManifest)) {
|
|
281
|
-
if (blocked.includes(row.name) &&
|
|
281
|
+
if (blocked.includes(row.name) && row.from !== null && row.to !== null) {
|
|
282
282
|
problems.push(`package.json: ${row.name} moves from ${row.from} to ${row.to}.`)
|
|
283
283
|
}
|
|
284
284
|
}
|
|
@@ -304,15 +304,15 @@ export function syncDependabot(text, names, ecosystem) {
|
|
|
304
304
|
const end = `# END dependency-policy (${ecosystem})`
|
|
305
305
|
const pattern = new RegExp(
|
|
306
306
|
`^([ \\t]*)${begin.replaceAll(/[()]/g, '\\$&')}\\n[\\s\\S]*?^[ \\t]*${end.replaceAll(/[()]/g, '\\$&')}$`,
|
|
307
|
-
'm'
|
|
307
|
+
'm',
|
|
308
308
|
)
|
|
309
309
|
const match = pattern.exec(text)
|
|
310
310
|
|
|
311
|
-
if (
|
|
311
|
+
if (match === null) return null
|
|
312
312
|
|
|
313
313
|
const indent = match[1]
|
|
314
314
|
const rules =
|
|
315
|
-
|
|
315
|
+
names.length === 0 ? [] : [`${indent}ignore:`, ...names.map((name) => `${indent} - dependency-name: '${name}'`)]
|
|
316
316
|
|
|
317
317
|
return text.replace(pattern, () => [`${indent}${begin}`, ...rules, `${indent}${end}`].join('\n'))
|
|
318
318
|
}
|
|
@@ -325,18 +325,18 @@ export function fixedOverrides(overrides, vulnerabilities, versionsOf) {
|
|
|
325
325
|
const fixes = {}
|
|
326
326
|
|
|
327
327
|
for (const [name, pin] of Object.entries(overrides ?? {})) {
|
|
328
|
-
const pinned = 'string'
|
|
328
|
+
const pinned = typeof pin === 'string' ? pin : pin?.['.']
|
|
329
329
|
const range = vulnerabilities?.[name]?.range
|
|
330
330
|
|
|
331
|
-
if (
|
|
331
|
+
if (semver.valid(pinned) === null || typeof range !== 'string' || semver.validRange(range) === null) continue
|
|
332
332
|
if (!semver.satisfies(pinned, range)) continue
|
|
333
333
|
|
|
334
334
|
const candidates = (versionsOf(name) ?? []).filter(
|
|
335
335
|
(version) =>
|
|
336
|
-
|
|
337
|
-
|
|
336
|
+
semver.valid(version) !== null &&
|
|
337
|
+
semver.prerelease(version) === null &&
|
|
338
338
|
semver.major(version) === semver.major(pinned) &&
|
|
339
|
-
!semver.satisfies(version, range)
|
|
339
|
+
!semver.satisfies(version, range),
|
|
340
340
|
)
|
|
341
341
|
const best = semver.maxSatisfying(candidates, '*')
|
|
342
342
|
|
|
@@ -352,7 +352,7 @@ export function fixedOverrides(overrides, vulnerabilities, versionsOf) {
|
|
|
352
352
|
*/
|
|
353
353
|
export function refreshableNames(lock, scopes = TRUSTED_SCOPES) {
|
|
354
354
|
const names = Object.keys(lock?.packages ?? {})
|
|
355
|
-
.filter((path) =>
|
|
355
|
+
.filter((path) => path !== '')
|
|
356
356
|
.map((path) => path.slice(path.lastIndexOf('node_modules/') + 'node_modules/'.length))
|
|
357
357
|
.filter((name) => !scopes.some((scope) => name.startsWith(scope)))
|
|
358
358
|
|
|
@@ -379,7 +379,7 @@ export function isInherited(lock, name, scope = GROUP_SCOPE) {
|
|
|
379
379
|
const edges = new Map()
|
|
380
380
|
|
|
381
381
|
for (const [path, node] of Object.entries(packages)) {
|
|
382
|
-
if (
|
|
382
|
+
if (path === '') continue
|
|
383
383
|
|
|
384
384
|
const key = path.slice(path.lastIndexOf('node_modules/') + 'node_modules/'.length)
|
|
385
385
|
const next = edges.get(key) ?? new Set()
|
|
@@ -392,13 +392,13 @@ export function isInherited(lock, name, scope = GROUP_SCOPE) {
|
|
|
392
392
|
|
|
393
393
|
const root = packages['']
|
|
394
394
|
const direct = ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies'].flatMap((section) =>
|
|
395
|
-
Object.keys(root?.[section] ?? {})
|
|
395
|
+
Object.keys(root?.[section] ?? {}),
|
|
396
396
|
)
|
|
397
397
|
const reaches = (starts) => {
|
|
398
398
|
const seen = new Set(starts)
|
|
399
399
|
const queue = [...starts]
|
|
400
400
|
|
|
401
|
-
while (
|
|
401
|
+
while (queue.length > 0) {
|
|
402
402
|
for (const next of edges.get(queue.shift()) ?? []) {
|
|
403
403
|
if (!seen.has(next)) {
|
|
404
404
|
seen.add(next)
|
|
@@ -418,7 +418,7 @@ export function isInherited(lock, name, scope = GROUP_SCOPE) {
|
|
|
418
418
|
|
|
419
419
|
/** The id of an advisory: the last part of its URL (GHSA-xxxx-xxxx-xxxx), else the number npm gives it. */
|
|
420
420
|
function advisoryId(via) {
|
|
421
|
-
const fromUrl =
|
|
421
|
+
const fromUrl = typeof via.url === 'string' ? via.url.split('/').filter(Boolean).pop() : ''
|
|
422
422
|
|
|
423
423
|
return fromUrl || String(via.source ?? '')
|
|
424
424
|
}
|
|
@@ -430,7 +430,7 @@ export function parseNpmAudit(report) {
|
|
|
430
430
|
for (const entry of Object.values(report?.vulnerabilities ?? {})) {
|
|
431
431
|
for (const via of entry.via ?? []) {
|
|
432
432
|
// A string only names another vulnerable package: the advisory itself is on that one.
|
|
433
|
-
if ('object'
|
|
433
|
+
if (typeof via !== 'object' || via === null) continue
|
|
434
434
|
|
|
435
435
|
const row = {
|
|
436
436
|
id: advisoryId(via),
|
|
@@ -469,11 +469,11 @@ export function isNotable(severity) {
|
|
|
469
469
|
*/
|
|
470
470
|
export function auditAlert(opened, project) {
|
|
471
471
|
const notable = opened.filter(({ row }) => isNotable(row.severity))
|
|
472
|
-
if (
|
|
472
|
+
if (notable.length === 0) return null
|
|
473
473
|
|
|
474
474
|
const silent = opened.length - notable.length
|
|
475
475
|
const lines = notable.map(({ row, url }) => `${row.package} (${row.id}, ${row.severity || 'unknown'}): ${url}`)
|
|
476
|
-
if (
|
|
476
|
+
if (silent > 0) lines.push(`${silent} more of a low severity, issue only.`)
|
|
477
477
|
|
|
478
478
|
return { title: `Security advisories: ${notable.length} new in ${project}`, message: lines.join('\n') }
|
|
479
479
|
}
|
|
@@ -502,7 +502,7 @@ export function advisoryIssueBody(row, pipelineUrl, autoFix) {
|
|
|
502
502
|
].join('\n')
|
|
503
503
|
}
|
|
504
504
|
|
|
505
|
-
//
|
|
505
|
+
// ================
|
|
506
506
|
|
|
507
507
|
const log = (message) => console.info(message)
|
|
508
508
|
|
|
@@ -630,7 +630,7 @@ async function mergeRequestOptions() {
|
|
|
630
630
|
const user = await api('GET', '/user')
|
|
631
631
|
const milestones = await api('GET', `/projects/${projectId()}/milestones?state=active`)
|
|
632
632
|
const milestone = Array.isArray(milestones.data)
|
|
633
|
-
? (milestones.data.find((item) => 'Maintenance'
|
|
633
|
+
? (milestones.data.find((item) => item.title === 'Maintenance') ?? milestones.data[0])
|
|
634
634
|
: null
|
|
635
635
|
|
|
636
636
|
return {
|
|
@@ -643,7 +643,7 @@ async function mergeRequestOptions() {
|
|
|
643
643
|
|
|
644
644
|
/** Merge the request when its pipeline succeeds. GitLab needs a moment to create the pipeline of a new request. */
|
|
645
645
|
async function mergeWhenGreen(iid) {
|
|
646
|
-
for (let attempt = 0;
|
|
646
|
+
for (let attempt = 0; attempt < 18; attempt++) {
|
|
647
647
|
const result = await api('PUT', `/projects/${projectId()}/merge_requests/${iid}/merge`, {
|
|
648
648
|
merge_when_pipeline_succeeds: true,
|
|
649
649
|
should_remove_source_branch: true,
|
|
@@ -672,7 +672,7 @@ function ncu(args) {
|
|
|
672
672
|
return run('npx', ['--yes', 'npm-check-updates', '--target', 'minor', ...args, '-u'])
|
|
673
673
|
}
|
|
674
674
|
|
|
675
|
-
//
|
|
675
|
+
// ================
|
|
676
676
|
|
|
677
677
|
/** Raise the overrides that pin a vulnerable version, then install. Returns the raised ones. */
|
|
678
678
|
function raiseVulnerableOverrides() {
|
|
@@ -681,15 +681,15 @@ function raiseVulnerableOverrides() {
|
|
|
681
681
|
|
|
682
682
|
const report = JSON.parse(capture('npm', ['audit', '--json']) || '{}')
|
|
683
683
|
const fixes = fixedOverrides(manifest.overrides, report.vulnerabilities, (name) =>
|
|
684
|
-
JSON.parse(capture('npm', ['view', name, 'versions', '--json']) || '[]')
|
|
684
|
+
JSON.parse(capture('npm', ['view', name, 'versions', '--json']) || '[]'),
|
|
685
685
|
)
|
|
686
686
|
|
|
687
687
|
for (const [name, version] of Object.entries(fixes)) {
|
|
688
|
-
if (
|
|
688
|
+
if (typeof manifest.overrides[name] === 'string') manifest.overrides[name] = version
|
|
689
689
|
else manifest.overrides[name]['.'] = version
|
|
690
690
|
}
|
|
691
691
|
|
|
692
|
-
if (
|
|
692
|
+
if (Object.keys(fixes).length > 0) {
|
|
693
693
|
writeFileSync('package.json', `${JSON.stringify(manifest, null, 2)}\n`)
|
|
694
694
|
run('npm', ['install', '--no-audit', '--no-fund'])
|
|
695
695
|
}
|
|
@@ -712,12 +712,12 @@ async function update(config) {
|
|
|
712
712
|
run('git', ['switch', '-C', branch])
|
|
713
713
|
|
|
714
714
|
// A PHP project was prepared by the job before this one, in its own image: only npm is updated here.
|
|
715
|
-
if ('package.json'
|
|
715
|
+
if (ecosystem.file === 'package.json') {
|
|
716
716
|
// The new versions wait for the cooling period. The packages of the group are trusted: no waiting for them.
|
|
717
717
|
const rejected = rejectedPackages(config, await readPolicy('npm'))
|
|
718
|
-
const reject =
|
|
718
|
+
const reject = rejected.length > 0 ? ['--reject', rejected.join(',')] : []
|
|
719
719
|
// An update started by the audit (UPDATE_URGENT=true) fixes an advisory: the fix is not made to wait.
|
|
720
|
-
const urgent =
|
|
720
|
+
const urgent = process.env.UPDATE_URGENT === 'true'
|
|
721
721
|
ncu([...(urgent ? [] : ['--cooldown', config.cooldown]), ...reject])
|
|
722
722
|
ncu(['--filter', '@zairakai/*', ...reject])
|
|
723
723
|
run('npm', ['install', '--no-audit', '--no-fund'])
|
|
@@ -730,9 +730,9 @@ async function update(config) {
|
|
|
730
730
|
// The refresh is a bonus: when npm cannot respect the cooling date (a range that starts at a version younger than
|
|
731
731
|
// the period, after an urgent update), it waits for the next run and the update goes on.
|
|
732
732
|
try {
|
|
733
|
-
if (urgent ||
|
|
733
|
+
if (urgent || before === null) {
|
|
734
734
|
run('npm', ['update', '--no-audit', '--no-fund'])
|
|
735
|
-
} else if (
|
|
735
|
+
} else if (names.length > 0) {
|
|
736
736
|
run('npm', ['update', '--no-audit', '--no-fund', `--before=${before.toISOString()}`, ...names])
|
|
737
737
|
}
|
|
738
738
|
} catch (error) {
|
|
@@ -767,7 +767,7 @@ async function update(config) {
|
|
|
767
767
|
files.push(PIPELINE_FILE)
|
|
768
768
|
}
|
|
769
769
|
|
|
770
|
-
if (
|
|
770
|
+
if (run('git', ['status', '--porcelain', '--', ...files]) === '') {
|
|
771
771
|
log('Everything is up to date.')
|
|
772
772
|
return
|
|
773
773
|
}
|
|
@@ -817,7 +817,7 @@ async function release() {
|
|
|
817
817
|
|
|
818
818
|
const existing = await openMergeRequests('&source_branch=develop&target_branch=main')
|
|
819
819
|
|
|
820
|
-
if (
|
|
820
|
+
if (existing.length > 0) {
|
|
821
821
|
await mergeWhenGreen(existing[0].iid)
|
|
822
822
|
return
|
|
823
823
|
}
|
|
@@ -867,7 +867,7 @@ async function tag(config) {
|
|
|
867
867
|
|
|
868
868
|
/** True when the registry of the ecosystem (npm or Packagist) lists the version. */
|
|
869
869
|
async function isAvailable(ecosystem, name, version) {
|
|
870
|
-
if ('npm'
|
|
870
|
+
if (ecosystem === 'npm') {
|
|
871
871
|
return run('npm', ['view', `${name}@${version}`, 'version', '--prefer-online']) === version
|
|
872
872
|
}
|
|
873
873
|
|
|
@@ -897,7 +897,7 @@ async function cascade(config) {
|
|
|
897
897
|
// The registry needs a few minutes to list a new version: wait for it instead of waiting for a fixed hour.
|
|
898
898
|
let available = false
|
|
899
899
|
|
|
900
|
-
for (let attempt = 0;
|
|
900
|
+
for (let attempt = 0; attempt < 60 && !available; attempt++) {
|
|
901
901
|
try {
|
|
902
902
|
available = await isAvailable(ecosystem, name, version)
|
|
903
903
|
} catch {
|
|
@@ -912,7 +912,7 @@ async function cascade(config) {
|
|
|
912
912
|
for (const group of config.cascade.groups ?? []) {
|
|
913
913
|
const projects = await api(
|
|
914
914
|
'GET',
|
|
915
|
-
`/groups/${encodeURIComponent(group)}/projects?include_subgroups=true&archived=false&per_page=100
|
|
915
|
+
`/groups/${encodeURIComponent(group)}/projects?include_subgroups=true&archived=false&per_page=100`,
|
|
916
916
|
)
|
|
917
917
|
|
|
918
918
|
for (const project of Array.isArray(projects.data) ? projects.data : []) {
|
|
@@ -921,7 +921,7 @@ async function cascade(config) {
|
|
|
921
921
|
// Opt-in: a project is updated only if it has the same file.
|
|
922
922
|
const file = await api(
|
|
923
923
|
'GET',
|
|
924
|
-
`/projects/${project.id}/repository/files/${encodeURIComponent(CONFIG_FILE)}?ref=develop
|
|
924
|
+
`/projects/${project.id}/repository/files/${encodeURIComponent(CONFIG_FILE)}?ref=develop`,
|
|
925
925
|
)
|
|
926
926
|
|
|
927
927
|
if (!file.ok) {
|
|
@@ -939,7 +939,7 @@ async function cascade(config) {
|
|
|
939
939
|
}
|
|
940
940
|
}
|
|
941
941
|
|
|
942
|
-
//
|
|
942
|
+
// ================
|
|
943
943
|
|
|
944
944
|
async function issueExists(title, token) {
|
|
945
945
|
const query = new URLSearchParams({ state: 'opened', search: title, in: 'title' })
|
|
@@ -952,13 +952,13 @@ async function createIssue(title, description, labels, token) {
|
|
|
952
952
|
// The assignee is given by the variable ISSUE_ASSIGNEE_ID; without it, the user of the token.
|
|
953
953
|
let assignee = Number(process.env.ISSUE_ASSIGNEE_ID) || 0
|
|
954
954
|
|
|
955
|
-
if (
|
|
955
|
+
if (assignee === 0) assignee = (await api('GET', '/user', undefined, token)).data?.id ?? 0
|
|
956
956
|
|
|
957
957
|
const issue = await api(
|
|
958
958
|
'POST',
|
|
959
959
|
`/projects/${projectId()}/issues`,
|
|
960
|
-
{ title, description, labels, assignee_ids:
|
|
961
|
-
token
|
|
960
|
+
{ title, description, labels, assignee_ids: assignee > 0 ? [assignee] : [] },
|
|
961
|
+
token,
|
|
962
962
|
)
|
|
963
963
|
|
|
964
964
|
if (!issue.ok) throw new Error(`The issue could not be created: ${secret(JSON.stringify(issue.data))}`)
|
|
@@ -985,7 +985,7 @@ async function closeResolved(titles, token) {
|
|
|
985
985
|
'POST',
|
|
986
986
|
`${path}/notes`,
|
|
987
987
|
{ body: `The audit of ${process.env.CI_PIPELINE_URL} no longer finds this advisory.` },
|
|
988
|
-
token
|
|
988
|
+
token,
|
|
989
989
|
)
|
|
990
990
|
const closed = await api('PUT', path, { state_event: 'close' }, token)
|
|
991
991
|
log(closed.ok ? `Issue closed: ${issue.title}` : `Issue not closed (${closed.status}): ${issue.title}`)
|
|
@@ -1027,7 +1027,7 @@ async function audit() {
|
|
|
1027
1027
|
|
|
1028
1028
|
const found = parseNpmAudit(JSON.parse(capture('npm', ['audit', '--json'])))
|
|
1029
1029
|
const lock = existsSync('package-lock.json') ? JSON.parse(readFileSync('package-lock.json', 'utf8')) : null
|
|
1030
|
-
const auto =
|
|
1030
|
+
const auto = process.env.AUTO_FIX === 'true'
|
|
1031
1031
|
const token = process.env.FRESHNESS_TOKEN || process.env.GITLAB_TOKEN
|
|
1032
1032
|
const titles = []
|
|
1033
1033
|
const opened = []
|
|
@@ -1084,7 +1084,7 @@ async function audit() {
|
|
|
1084
1084
|
{ key: 'UPDATE_URGENT', value: 'true' },
|
|
1085
1085
|
],
|
|
1086
1086
|
},
|
|
1087
|
-
token
|
|
1087
|
+
token,
|
|
1088
1088
|
)
|
|
1089
1089
|
log(started.ok ? 'Update started.' : `The update could not be started (${started.status}).`)
|
|
1090
1090
|
}
|
|
@@ -1113,7 +1113,7 @@ async function policyValidate() {
|
|
|
1113
1113
|
}
|
|
1114
1114
|
|
|
1115
1115
|
for (const message of errors) console.error(`${file}: ${message}`)
|
|
1116
|
-
failed ||=
|
|
1116
|
+
failed ||= errors.length > 0
|
|
1117
1117
|
}
|
|
1118
1118
|
|
|
1119
1119
|
if (failed) throw new Error('The dependency policy is not valid.')
|
|
@@ -1127,7 +1127,7 @@ async function policyWatch() {
|
|
|
1127
1127
|
const file = POLICY_FILES.npm
|
|
1128
1128
|
const doc = JSON.parse(readFileSync(file, 'utf8'))
|
|
1129
1129
|
const errors = validatePolicy(doc)
|
|
1130
|
-
if (
|
|
1130
|
+
if (errors.length > 0) throw new Error(`${file} is not valid: ${errors.join(' ')}`)
|
|
1131
1131
|
|
|
1132
1132
|
const lifted = doc.entries.filter((entry) => {
|
|
1133
1133
|
if (!entry.unblock) return false
|
|
@@ -1137,7 +1137,7 @@ async function policyWatch() {
|
|
|
1137
1137
|
return isLifted(entry, ranges)
|
|
1138
1138
|
})
|
|
1139
1139
|
|
|
1140
|
-
if (
|
|
1140
|
+
if (lifted.length === 0) {
|
|
1141
1141
|
log('No entry can be lifted.')
|
|
1142
1142
|
return
|
|
1143
1143
|
}
|
|
@@ -1155,7 +1155,7 @@ async function policyWatch() {
|
|
|
1155
1155
|
run('git', ['switch', '-C', branch])
|
|
1156
1156
|
writeFileSync(
|
|
1157
1157
|
file,
|
|
1158
|
-
`${JSON.stringify({ ...doc, entries: doc.entries.filter((entry) => !lifted.includes(entry)) }, null, 2)}\n
|
|
1158
|
+
`${JSON.stringify({ ...doc, entries: doc.entries.filter((entry) => !lifted.includes(entry)) }, null, 2)}\n`,
|
|
1159
1159
|
)
|
|
1160
1160
|
run('git', ['add', file])
|
|
1161
1161
|
run('git', ['commit', '-m', subject, '-m', 'The peer ranges of the packages that held it back now accept it.'])
|
|
@@ -1200,7 +1200,7 @@ async function policyCheck(_config, base) {
|
|
|
1200
1200
|
})
|
|
1201
1201
|
|
|
1202
1202
|
for (const problem of problems) console.error(problem)
|
|
1203
|
-
if (
|
|
1203
|
+
if (problems.length > 0) throw new Error('The change updates a package that the dependency policy holds back.')
|
|
1204
1204
|
|
|
1205
1205
|
log('No package of the dependency policy is updated.')
|
|
1206
1206
|
}
|
|
@@ -1213,9 +1213,9 @@ async function dependabotSync() {
|
|
|
1213
1213
|
const text = readFileSync(DEPENDABOT_FILE, 'utf8')
|
|
1214
1214
|
const synced = syncDependabot(text, names, 'npm')
|
|
1215
1215
|
|
|
1216
|
-
if (
|
|
1216
|
+
if (synced === null) {
|
|
1217
1217
|
throw new Error(
|
|
1218
|
-
`${DEPENDABOT_FILE} has no block "# BEGIN dependency-policy (npm)" ... "# END dependency-policy (npm)"
|
|
1218
|
+
`${DEPENDABOT_FILE} has no block "# BEGIN dependency-policy (npm)" ... "# END dependency-policy (npm)".`,
|
|
1219
1219
|
)
|
|
1220
1220
|
}
|
|
1221
1221
|
|
|
@@ -1240,10 +1240,10 @@ const modes = {
|
|
|
1240
1240
|
'dependabot-sync': dependabotSync,
|
|
1241
1241
|
}
|
|
1242
1242
|
|
|
1243
|
-
async function main(mode, argument) {
|
|
1243
|
+
export async function main(mode, argument) {
|
|
1244
1244
|
if (!modes[mode]) {
|
|
1245
1245
|
console.error(
|
|
1246
|
-
'Usage: node update-dependencies.mjs update | release | tag | cascade | audit | policy | policy-validate'
|
|
1246
|
+
'Usage: node update-dependencies.mjs update | release | tag | cascade | audit | policy | policy-validate',
|
|
1247
1247
|
)
|
|
1248
1248
|
process.exitCode = 1
|
|
1249
1249
|
return
|
|
@@ -23,11 +23,11 @@ log_info "Severity: ${SEVERITY}"
|
|
|
23
23
|
log_info "Format: ${FORMAT}"
|
|
24
24
|
|
|
25
25
|
if ! command_exists shellcheck; then
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
log_error "ShellCheck not found. Please install shellcheck."
|
|
27
|
+
log_info " Alpine: apk add shellcheck"
|
|
28
|
+
log_info " Debian/Ubuntu: apt-get install shellcheck"
|
|
29
|
+
log_info " macOS: brew install shellcheck"
|
|
30
|
+
exit 1
|
|
31
31
|
fi
|
|
32
32
|
|
|
33
33
|
SHELLCHECK_VERSION="$(shellcheck --version | grep "version:" | awk '{print $2}')"
|
|
@@ -41,8 +41,8 @@ SCRIPT_COUNT=${#SHELL_SCRIPTS[@]}
|
|
|
41
41
|
log_info "Found ${SCRIPT_COUNT} shell scripts"
|
|
42
42
|
|
|
43
43
|
if [[ ${SCRIPT_COUNT} -eq 0 ]]; then
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
log_warning "No shell scripts found"
|
|
45
|
+
exit 0
|
|
46
46
|
fi
|
|
47
47
|
|
|
48
48
|
log_info "→ Running ShellCheck validation…"
|
|
@@ -51,20 +51,20 @@ FAILED=0
|
|
|
51
51
|
TOTAL=0
|
|
52
52
|
|
|
53
53
|
for script in "${SHELL_SCRIPTS[@]}"; do
|
|
54
|
-
|
|
54
|
+
TOTAL=$((TOTAL + 1))
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
if shellcheck --severity="${SEVERITY}" --format="${FORMAT}" "${script}"; then
|
|
57
|
+
:
|
|
58
|
+
else
|
|
59
|
+
log_error " ✗ ${script} - ShellCheck failed"
|
|
60
|
+
FAILED=$((FAILED + 1))
|
|
61
|
+
fi
|
|
62
62
|
done
|
|
63
63
|
|
|
64
64
|
if [[ ${FAILED} -eq 0 ]]; then
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
log_success "All ${TOTAL} scripts passed ShellCheck"
|
|
66
|
+
exit 0
|
|
67
67
|
else
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
log_error "${FAILED}/${TOTAL} scripts failed ShellCheck"
|
|
69
|
+
exit 1
|
|
70
70
|
fi
|
|
@@ -21,38 +21,38 @@ first_line=$(sed -n 1p "$commit_msg_file")
|
|
|
21
21
|
second_line=$(sed -n 2p "$commit_msg_file")
|
|
22
22
|
|
|
23
23
|
case "$first_line" in
|
|
24
|
-
|
|
24
|
+
"Merge "* | "Revert \""* | "fixup! "* | "squash! "* | "amend! "*) exit 0 ;;
|
|
25
25
|
esac
|
|
26
26
|
|
|
27
27
|
PATTERN='^(feat|fix|docs|style|refactor|perf|test|chore|ci|build)(\([a-z0-9][a-z0-9._/-]*\))?: #[0-9]+ [^[:space:]].*$'
|
|
28
28
|
|
|
29
29
|
fail() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
30
|
+
echo ""
|
|
31
|
+
echo "❌ $1"
|
|
32
|
+
echo ""
|
|
33
|
+
echo " Format of the zairakai handbook: <type>(<scope>): #TICKET <subject>"
|
|
34
|
+
echo " Types: feat, fix, docs, style, refactor, perf, test, chore, ci, build"
|
|
35
|
+
echo ""
|
|
36
|
+
echo " Your message: \"$first_line\""
|
|
37
|
+
echo ""
|
|
38
|
+
echo " Examples:"
|
|
39
|
+
echo " feat(auth): #102 add OAuth2 provider support"
|
|
40
|
+
echo " fix(api): #87 handle null response from payment gateway"
|
|
41
|
+
echo " docs: #31 update installation instructions"
|
|
42
|
+
echo ""
|
|
43
|
+
exit 1
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
if ! [[ $first_line =~ $PATTERN ]]; then
|
|
47
|
-
|
|
47
|
+
fail "Invalid commit message format"
|
|
48
48
|
fi
|
|
49
49
|
|
|
50
50
|
if [[ ${#first_line} -gt 72 ]]; then
|
|
51
|
-
|
|
51
|
+
fail "The first line has ${#first_line} characters: the limit is 72"
|
|
52
52
|
fi
|
|
53
53
|
|
|
54
54
|
if [[ -n $second_line ]]; then
|
|
55
|
-
|
|
55
|
+
fail "The second line must be blank"
|
|
56
56
|
fi
|
|
57
57
|
|
|
58
58
|
echo "✅ Commit message OK"
|
|
@@ -28,9 +28,9 @@ cd "$PROJECT_ROOT"
|
|
|
28
28
|
|
|
29
29
|
# Check if make is available
|
|
30
30
|
if ! command -v make &>/dev/null; then
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
echo -e "${RED}❌ make not found - skipping quality checks${NC}"
|
|
32
|
+
echo ""
|
|
33
|
+
exit 0
|
|
34
34
|
fi
|
|
35
35
|
|
|
36
36
|
# Run fast quality checks (eslint + prettier + markdown)
|
|
@@ -38,21 +38,21 @@ echo -e "${BLUE}→${NC} Running: ${CYAN}make quality-fast${NC}"
|
|
|
38
38
|
echo ""
|
|
39
39
|
|
|
40
40
|
if make quality-fast; then
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
echo ""
|
|
42
|
+
echo -e "${GREEN}✅ Quality checks passed - commit allowed${NC}"
|
|
43
|
+
echo ""
|
|
44
|
+
exit 0
|
|
45
45
|
else
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
46
|
+
echo ""
|
|
47
|
+
echo -e "${RED}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
48
|
+
echo -e "${RED} ❌ Quality checks failed!${NC}"
|
|
49
|
+
echo -e "${RED}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
50
|
+
echo ""
|
|
51
|
+
echo -e "${YELLOW}Fix issues with:${NC}"
|
|
52
|
+
echo -e " ${CYAN}make quality-fix${NC} ${YELLOW}# Auto-fix what can be fixed${NC}"
|
|
53
|
+
echo ""
|
|
54
|
+
echo -e "${YELLOW}Or bypass (NOT recommended):${NC}"
|
|
55
|
+
echo -e " ${CYAN}git commit --no-verify${NC}"
|
|
56
|
+
echo ""
|
|
57
|
+
exit 1
|
|
58
58
|
fi
|