Skip to content

Commit a05c375

Browse files
committed
📌 发布第一版
1 parent 35b7f9f commit a05c375

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

.github/workflows/npm-publish.yml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: npm publish # 定义工作流名称
2+
3+
on:
4+
workflow_dispatch: # 允许手动触发工作流,默认是不开启的
5+
push: # 当有代码推送到仓库时触发
6+
tags:
7+
- 'v*.*.*' # 监听所有以 v 开头的标签,比如 v1.0.0
8+
9+
jobs:
10+
build: # 工作流程中的一个作业
11+
runs-on: ubuntu-latest # 指定运行作业的虚拟环境
12+
steps:
13+
- name: Checkout repository # 步骤名称
14+
uses: actions/checkout@v4 # 使用 GitHub 官方提供的 Checkout 动作,拷贝最新的代码到虚拟机上
15+
- name: Set up Node.js # 步骤名称
16+
uses: actions/setup-node@v4 # 使用官方的 actions/setup-node@v4 来设置 Node.js 环境
17+
with:
18+
node-version: 20 # 使用 Node.js 20 版本
19+
- name: enable pnpm # 步骤名称
20+
run: corepack enable
21+
- name: install Dependencies # 步骤名称
22+
run: pnpm i
23+
- name: Run Test
24+
run: npm test
25+
- name: Build Project
26+
run: pnpm build
27+
- name: Upload Build Artifacts
28+
uses: actions/upload-artifact@v4
29+
with:
30+
name: build-artifacts # 构建产物名称
31+
path: ./dist # 构建产物路径
32+
33+
publish-npm:
34+
needs: build # 依赖 build 作业,确保在 build 成功后再执行
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v4
39+
- name: Set up Node.js
40+
uses: actions/setup-node@v4
41+
with:
42+
node-version: 20
43+
registry-url: https://registry.npmjs.org/
44+
- name: Download Build Artifacts
45+
uses: actions/download-artifact@v4
46+
with:
47+
name: build-artifacts # 构建产物名称,需与上传时的名称一致
48+
path: ./dist # 下载后存放路径
49+
- name: List Build Directory # 列出构建目录中的文件
50+
run: ls -al ./dist
51+
- name: List Publish Directory # 列出发布目录中的文件
52+
run: ls -al ./
53+
- name: Publish to NPM # 步骤名称
54+
run: npm publish
55+
env:
56+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # 使用 GitHub Secrets 中配置的 NPM 认证 token

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coderlzw/utils",
3-
"version": "1.0.1-0",
3+
"version": "1.0.0-0",
44
"description": "一个实用的 JavaScript 工具库,提供常用的函数和辅助方法",
55
"main": "./dist/cjs/index.cjs",
66
"module": "./dist/esm/index.mjs",

0 commit comments

Comments
 (0)