Skip to content

Commit d7069a6

Browse files
committed
oicd
1 parent b9d8388 commit d7069a6

File tree

5 files changed

+253
-12
lines changed

5 files changed

+253
-12
lines changed

.github/workflows/test.yml

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
id: publish
3131
run: npx . publish "./test" --webhook "${{ secrets.DISCORD_WEBHOOK_TEST_RELEASE }}" --access-token "${{ secrets.NPM_TOKEN }}" --version+hash --tag github --version+tag --create-tag "test/" --llm-api-key "${{ secrets.LLM_API_KEY }}"
3232

33-
- name: Print output
33+
- name: Print output
3434
run: |
3535
echo "Package version: ${{ steps.publish.outputs.package-version }}"
3636
@@ -42,3 +42,78 @@ jobs:
4242

4343
- name: Just add a tag
4444
run: npx . publish "./test" --webhook "${{ secrets.DISCORD_WEBHOOK_TEST_RELEASE }}" --access-token "${{ secrets.NPM_TOKEN }}" --tag github-2
45+
46+
# OIDC-based publishing (Trusted Publishing)
47+
# NOTE: First publish of a package MUST use --access-token. OIDC only works for existing packages.
48+
#
49+
# To enable OIDC for this package:
50+
# 1. Ensure the package exists on npmjs.com (publish once with --access-token)
51+
# 2. Go to https://www.npmjs.com/package/publish-helper-test-package/access
52+
# 3. Click "Settings" → "Trusted Publisher" → "GitHub Actions"
53+
# 4. Configure: owner (needle-tools), repository (npm-publish-helper), workflow (test.yml)
54+
publish-oidc:
55+
runs-on: ubuntu-latest
56+
timeout-minutes: 5
57+
permissions:
58+
contents: read
59+
id-token: write # Required for OIDC authentication
60+
defaults:
61+
run:
62+
working-directory: ./
63+
64+
steps:
65+
- uses: actions/checkout@v4
66+
67+
- name: Setup Node.js
68+
uses: actions/setup-node@v4
69+
with:
70+
node-version: '22'
71+
# Note: Do NOT set registry-url here for OIDC - it creates .npmrc expecting NODE_AUTH_TOKEN
72+
# which conflicts with OIDC. Let npm use its default registry.
73+
74+
- name: Update npm to latest (OIDC requires npm >= 11.5)
75+
run: |
76+
echo "Current npm version: $(npm --version)"
77+
npm install -g npm@latest
78+
echo "Updated npm version: $(npm --version)"
79+
80+
- name: Check environment for OIDC
81+
run: |
82+
echo "=== Node/npm versions ==="
83+
echo "npm version: $(npm --version)"
84+
echo "node version: $(node --version)"
85+
echo ""
86+
echo "=== OIDC Environment Variables ==="
87+
echo "GITHUB_ACTIONS: $GITHUB_ACTIONS"
88+
echo "ACTIONS_ID_TOKEN_REQUEST_URL: ${ACTIONS_ID_TOKEN_REQUEST_URL:-(not set)}"
89+
echo "ACTIONS_ID_TOKEN_REQUEST_TOKEN: ${ACTIONS_ID_TOKEN_REQUEST_TOKEN:+****(set)}"
90+
echo ""
91+
echo "=== Token Environment Variables (should be unset for OIDC) ==="
92+
echo "NPM_TOKEN: ${NPM_TOKEN:-(not set)}"
93+
echo "NODE_AUTH_TOKEN: ${NODE_AUTH_TOKEN:-(not set)}"
94+
echo ""
95+
echo "=== npmrc contents (if any) ==="
96+
cat ~/.npmrc 2>/dev/null || echo "(no ~/.npmrc)"
97+
cat .npmrc 2>/dev/null || echo "(no ./.npmrc)"
98+
echo ""
99+
echo "=== npm config list ==="
100+
npm config list
101+
102+
- name: Install dependencies
103+
run: npm install
104+
105+
- name: Test direct npm publish with OIDC (debug)
106+
working-directory: ./test
107+
continue-on-error: true
108+
run: |
109+
echo "Testing direct npm publish with --provenance..."
110+
npm version 2.0.0-oidc-direct-test.$(git rev-parse --short HEAD) --no-git-tag-version
111+
npm publish --access public --provenance --tag oidc-direct --dry-run || echo "Direct test failed"
112+
113+
- name: Run publish with OIDC
114+
id: publish-oidc
115+
run: npx . publish "./test" --webhook "${{ secrets.DISCORD_WEBHOOK_TEST_RELEASE }}" --oidc --version+hash --tag oidc --version+tag
116+
117+
- name: Print output
118+
run: |
119+
echo "Package version: ${{ steps.publish-oidc.outputs.package-version }}"

bin/cli.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ program.command('publish', 'Publish npm package')
6868
.option("--create-tag", "Create a git tag. Default: null. Can be set to e.g. '--create-tag release/'", { required: false, validator: program.STRING })
6969
.option("--webhook <webhook>", "Webhook URL to send notifications", { required: false, validator: program.STRING })
7070
.option("--access-token <access-token>", "NPM access token", { required: false, validator: program.STRING })
71+
.option("--oidc", "Use OIDC (OpenID Connect) for authentication instead of access tokens. Requires npm >= 11.5 and a trusted publisher configured on npmjs.com. Works with GitHub Actions and GitLab CI/CD.", { required: false, validator: program.BOOLEAN, default: false })
7172
.option("--dry-run", "Dry run mode, do not publish", { required: false, validator: program.BOOLEAN, default: false })
7273
.option("--override-name <name>", "Override package name", { required: false, validator: program.STRING })
7374
.option("--override-version <version>", "Override package version", { required: false, validator: program.STRING })
@@ -93,6 +94,7 @@ program.command('publish', 'Publish npm package')
9394

9495
registry: registry,
9596
accessToken: options.accessToken?.toString() || null,
97+
useOidc: options.oidc === true,
9698
useHashInVersion: options.versionHash === true, // default to false
9799
useTagInVersion: options.versionTag === true, // default to false
98100
createGitTag: options.createTag !== undefined, // default to false

0 commit comments

Comments
 (0)