-
Notifications
You must be signed in to change notification settings - Fork 2
112 lines (98 loc) · 3.82 KB
/
release.yml
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: Release
on:
push:
branches:
- main
env:
CI: true
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
PNPM_CACHE_FOLDER: .pnpm-store
PKG_RELEASE_KEY: lastReleaseCommit
jobs:
release:
# prevents this action from running on forks
if: github.repository == 'Marinerer/jotter'
name: Release
runs-on: ubuntu-latest
steps:
- name: checkout code repository
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: true
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 8
run_install: false
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: pnpm install --no-frozen-lockfile
- name: CI:test
run: |
pnpm test domEmit emitter -- --coverage
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
##################### 以下是执行发布流程工作
# 从 package.json 中读取最后发布 commit
- name: 📝 Get release commit from package.json 🔑
id: get_pkg_release
run: |
#使用 jq 工具解析json, 默认已内置.
PKG_RELEASE=$(jq -r '.lastReleaseCommit' package.json)
echo "Package Release: $PKG_RELEASE"
echo "PKG_RELEASE_COMMIT=$PKG_RELEASE" >> $GITHUB_ENV
# 获取最后一条以'release:'开头的提交记录的哈希值
- name: 📝 Get last release commit 🔒
id: get_last_release
run: |
# 获取最后一条以 'release: ' 开头的提交记录的哈希值
LAST_RELEASE=$(git log --grep='^release: ' --format='%H' -n 1)
if [ -z "$LAST_RELEASE" ]; then
echo "No release commit found."
exit 1 # 可以根据需要修改为跳过或失败
fi
echo "Last release commit: $LAST_RELEASE"
echo "LAST_RELEASE_COMMIT=$LAST_RELEASE" >> $GITHUB_ENV
- name: CI:build
if: env.LAST_RELEASE_COMMIT != env.PKG_RELEASE_COMMIT
run: pnpm build --clean
- name: Create Release Pull Request or Publish to npm 🔐
# 如果有新的 `release: ` 提交记录, 则执行发布
if: env.LAST_RELEASE_COMMIT != env.PKG_RELEASE_COMMIT
id: changesets
uses: changesets/action@v1
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
# Custom versioning script in package.json
# version: pnpm changeset:version
# Custom publish script in package.json
publish: pnpm changeset:release
# Messages
commit: 'chore(deploy): Release'
title: 'chore(deploy): Release'
env:
GITHUB_TOKEN: ${{ secrets.GH_RELEASE_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
- name: 🚦(Package.json) - Change 👷
if: steps.changesets.outputs.published == 'true'
run: |
echo "Update package.json..."
echo "LAST_RELEASE_COMMIT: $LAST_RELEASE_COMMIT"
#使用 jq 替换最后发布commit值
jq ".lastReleaseCommit = \"$LAST_RELEASE_COMMIT\"" package.json > _temp_.json && mv _temp_.json package.json
- name: 🚦(Package.json) - Commit 🚀
if: steps.changesets.outputs.published == 'true'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add package.json
git commit -m "chore: Update last_release_commit(package.json)"
git push