@@ -2,27 +2,72 @@ name: Publish the shared library to npmjs
22
33on :
44 workflow_dispatch :
5+ inputs :
6+ dry-run :
7+ description : " Run npm publish in --dry-run mode (no upload)"
8+ type : boolean
9+ default : false
510
611permissions :
7- id-token : write # Required for OIDC
12+ id-token : write # required for npm OIDC trusted publisher
813 contents : read
914
1015jobs :
1116 publish :
12- defaults :
13- run :
14- working-directory : lib/packages/docusaurus-shared
1517 runs-on : ubuntu-latest
1618 steps :
19+ - name : Refuse to run from non-main branches
20+ if : github.ref != 'refs/heads/main'
21+ run : |
22+ echo "::error::This workflow may only be dispatched from main (got ${{ github.ref }})."
23+ exit 1
24+
1725 - uses : actions/checkout@v4
1826
1927 - uses : actions/setup-node@v4
2028 with :
2129 node-version : ' 24'
2230 registry-url : ' https://registry.npmjs.org'
2331
24- - run : corepack enable
25- - run : yarn install --immutable
26- - run : yarn build --if-present
27- - run : yarn test
28- - run : npm publish
32+ # Pre-flight: read version from package.json, fail loudly *before*
33+ # spending time on install/build if the version is already on npm.
34+ - name : Verify version is not already published
35+ id : precheck
36+ run : |
37+ set -euo pipefail
38+ name="$(node -p "require('./packages/docusaurus-theme/package.json').name")"
39+ version="$(node -p "require('./packages/docusaurus-theme/package.json').version")"
40+ echo "name=$name" >> "$GITHUB_OUTPUT"
41+ echo "version=$version" >> "$GITHUB_OUTPUT"
42+ echo "Checking $name@$version on npm..."
43+ existing="$(npm view "${name}@${version}" version 2>/dev/null || true)"
44+ if [ -n "$existing" ]; then
45+ echo "::error title=Version already published::${name}@${version} is already on npm. Bump packages/docusaurus-theme/package.json before re-running."
46+ exit 1
47+ fi
48+ echo "OK: ${name}@${version} is not on npm yet."
49+
50+ - name : Install, build, test, publish
51+ run : ./scripts/publish-theme.sh ${{ inputs.dry-run && '--dry-run' || '' }}
52+
53+ - name : Explain npm publish failure
54+ if : failure() && steps.precheck.outcome == 'success'
55+ run : |
56+ cat <<'EOF'
57+ ::error title=Publish failed::npm publish failed after the version pre-check passed.
58+
59+ Most common cause: npm Trusted Publisher (OIDC) is not yet
60+ configured for this package + workflow. To fix:
61+
62+ 1. Log in to npmjs.com as a maintainer of @netfoundry/docusaurus-theme
63+ 2. Go to: package > Settings > Trusted Publishers > Add
64+ 3. Provider: GitHub Actions
65+ Organization: netfoundry
66+ Repository: docusaurus-shared
67+ Workflow file: .github/workflows/pubshared.yml
68+ Environment: (leave blank)
69+ 4. Re-run this workflow.
70+
71+ If trusted publisher is already configured, check the publish step
72+ logs above for the actual npm error.
73+ EOF
0 commit comments