Skip to content

Commit cb0d58d

Browse files
committed
feat(workflow): add publish-to-npm workflow for NPM package publishing
1 parent 8a014aa commit cb0d58d

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

.github/workflows/publish-packages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish Packages
1+
name: Publish To Github
22

33
on:
44
release:

.github/workflows/publish-to-npm.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Publish to NPM
2+
3+
on:
4+
release:
5+
types: [created]
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'Version to publish (patch, minor, major, or specific version)'
10+
required: true
11+
default: 'patch'
12+
type: choice
13+
options:
14+
- patch
15+
- minor
16+
- major
17+
- custom
18+
19+
jobs:
20+
publish-to-npm:
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
packages: write
25+
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 0
31+
32+
- name: Setup Node.js for NPM
33+
uses: actions/setup-node@v4
34+
with:
35+
node-version: '20'
36+
registry-url: 'https://registry.npmjs.org/'
37+
38+
- name: Setup PNPM
39+
uses: pnpm/action-setup@v3
40+
with:
41+
version: '10.6.3'
42+
43+
- name: Install dependencies
44+
run: pnpm install --frozen-lockfile
45+
46+
- name: Build packages
47+
run: pnpm build
48+
49+
- name: Configure Git
50+
run: |
51+
git config --global user.name "${GITHUB_ACTOR}"
52+
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
53+
54+
- name: Version packages
55+
if: github.event_name == 'workflow_dispatch'
56+
run: |
57+
if [ "${{ github.event.inputs.version }}" == "custom" ]; then
58+
echo "Please specify the custom version in the next workflow run."
59+
exit 1
60+
else
61+
pnpm -r exec -- npm version ${{ github.event.inputs.version }} --no-git-tag-version
62+
fi
63+
64+
- name: Publish to NPM
65+
run: pnpm -r --filter "[!core]" --filter "[!vite]" --filter "[!apps/**]" publish --access public
66+
env:
67+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)