Skip to content

Commit 5e6931f

Browse files
committed
feat: release 1.0.1
1 parent eb20b3a commit 5e6931f

2 files changed

Lines changed: 94 additions & 1 deletion

File tree

.github/workflows/release.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0 # 获取完整的 Git 历史,用于生成 commit log
20+
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: '18'
25+
registry-url: 'https://registry.npmjs.org'
26+
27+
- name: Install dependencies
28+
run: npm ci
29+
30+
- name: Build project
31+
run: npm run build
32+
33+
- name: Run tests
34+
run: npm test
35+
continue-on-error: true
36+
37+
- name: Get version from tag
38+
id: get_version
39+
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
40+
41+
- name: Create tarball
42+
id: tarball
43+
run: |
44+
# npm pack 会输出生成的文件名
45+
TARBALL=$(npm pack)
46+
echo "TARBALL=$TARBALL" >> $GITHUB_OUTPUT
47+
48+
- name: Generate commit log
49+
id: commits
50+
run: |
51+
CURRENT_TAG="${GITHUB_REF#refs/tags/}"
52+
echo "Current tag: $CURRENT_TAG"
53+
54+
# 获取所有 tag 并按版本排序,找到上一个 tag
55+
PREV_TAG=$(git tag -l 'v*' --sort=-v:refname | grep -A 1 "^${CURRENT_TAG}$" | tail -n 1)
56+
57+
# 如果 PREV_TAG 等于 CURRENT_TAG,说明没有找到上一个 tag
58+
if [ "$PREV_TAG" = "$CURRENT_TAG" ] || [ -z "$PREV_TAG" ]; then
59+
echo "No previous tag found, using recent commits"
60+
COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges -20)
61+
else
62+
echo "Previous tag: $PREV_TAG"
63+
# 获取从上一个 tag 到当前 tag 的所有 commit(不包含上一个 tag 的 commit)
64+
COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges ${PREV_TAG}..${CURRENT_TAG})
65+
fi
66+
67+
echo "Commits:"
68+
echo "$COMMITS"
69+
70+
echo "COMMITS<<EOF" >> $GITHUB_OUTPUT
71+
echo "$COMMITS" >> $GITHUB_OUTPUT
72+
echo "EOF" >> $GITHUB_OUTPUT
73+
74+
- name: Create GitHub Release
75+
uses: softprops/action-gh-release@v2
76+
with:
77+
name: v${{ steps.get_version.outputs.VERSION }}
78+
body: |
79+
## 更新内容
80+
81+
${{ steps.commits.outputs.COMMITS }}
82+
files: |
83+
${{ steps.tarball.outputs.TARBALL }}
84+
draft: false
85+
prerelease: false
86+
env:
87+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
89+
- name: Publish to npm
90+
run: npm publish
91+
env:
92+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
93+
continue-on-error: true

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "code996",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "统计 Git commit 的时间分布,进而推导出项目的编码工作强度",
55
"main": "dist/index.js",
66
"bin": {

0 commit comments

Comments
 (0)