Skip to content

Commit f50b31f

Browse files
committed
ci: make publish workflow reusable and trigger from CI
- update publish workflow to allow for pre-releases - call publish workflow from CI on release/prerelease commits
1 parent 4b4de11 commit f50b31f

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,17 @@ jobs:
2323
- run: npm run lint
2424
- run: npm run build
2525
- run: npm test
26+
27+
release:
28+
if: startsWith(github.event.head_commit.message, 'release:')
29+
needs: build
30+
uses: ./.github/workflows/publish.yml
31+
with:
32+
release_type: 'release'
33+
34+
prerelease:
35+
if: startsWith(github.event.head_commit.message, 'prerelease:')
36+
needs: build
37+
uses: ./.github/workflows/publish.yml
38+
with:
39+
release_type: 'prerelease'

.github/workflows/publish.yml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
name: Publish Package to npmjs
22
on:
33
workflow_dispatch:
4+
inputs:
5+
release_type:
6+
description: 'Type of release (release or prerelease)'
7+
default: 'release'
8+
type: string
9+
workflow_call:
10+
inputs:
11+
release_type:
12+
default: 'release'
13+
type: string
414

515
jobs:
616
build:
@@ -16,9 +26,22 @@ jobs:
1626
node-version: '22.x'
1727
registry-url: 'https://registry.npmjs.org'
1828
# Install dependencies without modifying package-lock.json file
19-
- run: npm ci
20-
- run: npm run build
21-
- run: npm publish ./dist
29+
- name: Install deps
30+
run: npm ci
31+
32+
- name: Build
33+
run: npm run build
34+
35+
- name: Publish
36+
if: ${{ inputs.release_type == 'release' }}
37+
run: npm publish ./dist
38+
env:
39+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
40+
NPM_CONFIG_PROVENANCE: true
41+
42+
- name: Publish Next
43+
if: ${{ inputs.release_type == 'prerelease' }}
44+
run: npm publish ./dist --tag next
2245
env:
2346
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2447
NPM_CONFIG_PROVENANCE: true

0 commit comments

Comments
 (0)