Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/publish-license-categories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ run-name: Publish License Categories - ${{ github.sha }}

on:
workflow_dispatch:
inputs:
force_publish:
description: Publish without comparing generated data
type: boolean
default: false
release:
types: [released]

Expand Down Expand Up @@ -83,6 +88,7 @@ jobs:

- name: Compare published generated data
id: comparison
if: github.event_name != 'workflow_dispatch' || !inputs.force_publish
run: |
node --input-type=module <<'NODE'
import {appendFileSync} from 'node:fs'
Expand All @@ -93,7 +99,7 @@ jobs:
NODE

- name: Publish to npm using OIDC
if: steps.comparison.outputs.changed == 'true'
if: steps.comparison.outputs.changed == 'true' || (github.event_name == 'workflow_dispatch' && inputs.force_publish)
run: npm publish --access public --registry=https://registry.npmjs.org
working-directory: packages/license-categories
env:
Expand Down
15 changes: 10 additions & 5 deletions packages/license-categories/docs/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,29 @@ For an initial local bootstrap publication, manually set this provenance line to
the source revision before packing; subsequent dispatches stamp it automatically.
No local-build detection is performed.

After testing, both triggers compare `dist/generated.js`, compiled from
After testing, both triggers normally compare `dist/generated.js`, compiled from
`src/generated.ts`, with that same file from the most recently published npm
version, selected by publication timestamp rather than a dist-tag or version
ordering. The comparison ignores the entire leading comment header, including
the generated-file warning and all provenance lines. All remaining text must match.
TypeScript-only or source formatting changes that compile identically do not
trigger publication. No other package files affect this decision.

Manual dispatches can select `force_publish` to skip this comparison and
publish even when the generated data is unchanged. The option defaults to
false and does not bypass the publication enablement variable, default branch
requirement, verification, or tests.

Unchanged generated data skips publication with a log message. A package not
found in npm is eligible for its initial publication; other registry or tarball
errors fail the workflow. Downloaded JavaScript is read, never executed, and the
package contents are unchanged.

npm provenance attestations remain explicitly disabled, independently of this
source header. When generated data changes, the workflow publishes the version
in the manifest without automatically bumping it. npm rejects a version that
has already been published. Bump both `package.json` and `package-lock.json`
before subsequent publication attempts that change generated data.
source header. When publishing, the workflow uses the version in the manifest
without automatically bumping it. npm rejects a version that has already been
published, even when `force_publish` is selected. Bump both `package.json` and
`package-lock.json` before subsequent publication attempts.

## Publishing permissions and versioning

Expand Down
6 changes: 4 additions & 2 deletions packages/license-categories/test/comparison.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import {join} from 'node:path'
import test from 'node:test'
import {generatedDataChanged} from '../../../script/compare-license-categories.mjs'

test('publication uses the comparison output after testing for either trigger', () => {
test('publication compares after testing unless a manual dispatch forces publishing', () => {
const workflow = readFileSync(new URL('../../../.github/workflows/publish-license-categories.yaml', import.meta.url), 'utf8')
const comparison = workflow.indexOf(' - name: Compare published generated data\n')
const publish = workflow.indexOf(' - name: Publish to npm using OIDC\n')
assert.match(workflow, /workflow_dispatch:\n inputs:\n force_publish:\n description: .+\n type: boolean\n default: false\n/)
assert.ok(comparison > workflow.indexOf(' - name: Test package tarball\n'))
assert.ok(publish > comparison)
assert.match(workflow.slice(comparison, publish), /if: github\.event_name != 'workflow_dispatch' \|\| !inputs\.force_publish/)
assert.match(workflow.slice(comparison, publish), /appendFileSync\(process\.env\.GITHUB_OUTPUT, `changed=\$\{changed\}\\n`\)/)
assert.match(workflow.slice(publish), /if: steps\.comparison\.outputs\.changed == 'true'/)
assert.match(workflow.slice(publish), /if: steps\.comparison\.outputs\.changed == 'true' \|\| \(github\.event_name == 'workflow_dispatch' && inputs\.force_publish\)/)
})

test('compares only compiled generated data against the last publication', async t => {
Expand Down
Loading