Skip to content

Commit 542fb9b

Browse files
authored
ci: Set up OIDC npm publishing (#770)
- closes #732 - see discussion in #768
1 parent 5aae606 commit 542fb9b

File tree

3 files changed

+54
-45
lines changed

3 files changed

+54
-45
lines changed

.github/workflows/pre_release.yaml

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,8 @@ jobs:
8080
needs: [update_changelog, wait_for_checks]
8181
runs-on: ubuntu-latest
8282
steps:
83-
- uses: actions/checkout@v5
83+
- name: Execute publish workflow
84+
uses: apify/workflows/execute-workflow@execute-workflow-action
8485
with:
85-
ref: ${{ needs.update_changelog.outputs.changelog_commitish }}
86-
- name: Use Node.js 22
87-
uses: actions/setup-node@v6
88-
with:
89-
node-version: 22
90-
cache: 'npm'
91-
cache-dependency-path: 'package-lock.json'
92-
- name: Install dependencies
93-
run: |
94-
echo "access=public" >> .npmrc
95-
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
96-
npm ci
97-
- # Check version consistency and increment pre-release version number for beta only.
98-
name: Bump pre-release version
99-
run: node ./.github/scripts/before-beta-release.js
100-
- name: Build module
101-
run: npm run build
102-
- name: Publish to NPM
103-
run: npm publish --tag beta
104-
105-
env:
106-
NODE_AUTH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}
107-
NPM_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}
86+
workflow: publish_to_npm.yaml
87+
inputs: '{ "ref": "${{ needs.update_changelog.outputs.changelog_commitish }}", "tag": "beta" }'
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Publish to NPM
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
ref:
7+
description: Git ref to publish (branch, tag, or commit SHA)
8+
required: true
9+
type: string
10+
tag:
11+
description: NPM dist-tag
12+
required: true
13+
type: choice
14+
default: latest
15+
options:
16+
- latest
17+
- beta
18+
19+
permissions:
20+
id-token: write # Required for OIDC
21+
contents: read
22+
23+
jobs:
24+
publish_to_npm:
25+
name: Publish to NPM
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v5
29+
with:
30+
ref: ${{ inputs.ref }}
31+
- name: Use Node.js 22
32+
uses: actions/setup-node@v6
33+
with:
34+
node-version: 22
35+
cache: 'npm'
36+
cache-dependency-path: 'package-lock.json'
37+
- name: Install dependencies
38+
run: |
39+
npm ci
40+
- name: Check version consistency and bump pre-release version (beta only)
41+
if: ${{ inputs.tag == 'beta' }}
42+
run: node ./.github/scripts/before-beta-release.js
43+
- name: Build module
44+
run: npm run build
45+
- name: Publish to NPM
46+
run: npm publish --tag ${{ inputs.tag }}

.github/workflows/release.yaml

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -102,24 +102,11 @@ jobs:
102102
needs: [update_changelog]
103103
runs-on: ubuntu-latest
104104
steps:
105-
- uses: actions/checkout@v5
105+
- name: Execute publish workflow
106+
uses: apify/workflows/execute-workflow@execute-workflow-action
106107
with:
107-
ref: ${{ needs.update_changelog.outputs.changelog_commitish }}
108-
- name: Use Node.js 22
109-
uses: actions/setup-node@v6
110-
with:
111-
node-version: 22
112-
cache: 'npm'
113-
cache-dependency-path: 'package-lock.json'
114-
- name: Install dependencies
115-
run: |
116-
echo "access=public" >> .npmrc
117-
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
118-
npm ci
119-
- name: Build module
120-
run: npm run build
121-
- name: Publish to NPM
122-
run: npm publish --tag latest
108+
workflow: publish_to_npm.yaml
109+
inputs: '{ "ref": "${{ needs.update_changelog.outputs.changelog_commitish }}", "tag": "latest" }'
123110

124111
version-docs:
125112
needs: publish_to_npm
@@ -167,7 +154,3 @@ jobs:
167154
author_name: Apify Release Bot
168155
author_email: [email protected]
169156
message: 'docs: update docs for ${{ inputs.version }} version'
170-
171-
env:
172-
NODE_AUTH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}
173-
NPM_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}

0 commit comments

Comments
 (0)