-
Notifications
You must be signed in to change notification settings - Fork 5
54 lines (44 loc) · 1.44 KB
/
publish.yml
File metadata and controls
54 lines (44 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
name: Publish to npm and GitHub Packages
on:
push:
tags:
- '*' # 监听标签推送
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
# 检出代码
- name: Checkout code
uses: actions/checkout@v3
# 设置 Node.js 环境
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'yarn'
# 配置 npm 认证(包括 GitHub 和 npm)
- name: Configure npm registry and authenticate
run: |
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc
# 安装依赖
- name: Install dependencies with yarn
run: yarn install
# 构建项目
- name: Build project
run: yarn build
# 运行测试
- name: Run tests
run: yarn test
# 发布到 GitHub Packages
- name: Publish to GitHub Package
if: startsWith(github.ref, 'refs/tags/')
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: yarn publish --access public --registry=https://npm.pkg.github.com
# 发布到 npm
- name: Publish to npm
if: startsWith(github.ref, 'refs/tags/')
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: yarn publish --access public --registry=https://registry.npmjs.org