Skip to content

Commit 6d9ea11

Browse files
committed
Add npm publish script and GitHub Actions workflow
1 parent 9755e12 commit 6d9ea11

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

.github/workflows/publish.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Publish to npm
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v*'
9+
10+
jobs:
11+
publish:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: '16'
20+
registry-url: 'https://registry.npmjs.org'
21+
22+
- name: Install dependencies
23+
run: npm ci
24+
25+
- name: Publish to npm
26+
run: npm publish --access public
27+
env:
28+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

publish.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# 检查是否提供了NPM令牌
4+
if [ -z "$1" ]; then
5+
echo "请提供NPM令牌作为参数"
6+
echo "用法: ./publish.sh your-npm-token"
7+
exit 1
8+
fi
9+
10+
# 设置NPM令牌
11+
NPM_TOKEN=$1
12+
13+
# 创建临时.npmrc文件
14+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
15+
16+
# 发布包
17+
npm publish --access public
18+
19+
# 删除临时.npmrc文件
20+
rm .npmrc
21+
22+
echo "发布完成!"

0 commit comments

Comments
 (0)