Skip to content

Commit e2d2026

Browse files
committed
ci: Add release workflow
1 parent af29c56 commit e2d2026

File tree

3 files changed

+203
-0
lines changed

3 files changed

+203
-0
lines changed

.github/COMMIT_CONVENTION.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
## Git Commit Message Convention
2+
3+
> This is adapted from [Angular's commit convention](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-angular).
4+
#### TL;DR:
5+
6+
Messages must be matched by the following regex:
7+
8+
``` js
9+
/^(revert: )?(feat|fix|polish|docs|style|refactor|perf|test|workflow|ci|chore|types)(\(.+\))?: .{1,50}/
10+
```
11+
12+
#### Examples
13+
14+
Appears under "Features" header, `compiler` subheader:
15+
16+
```
17+
feat(compiler): add 'comments' option
18+
```
19+
20+
Appears under "Bug Fixes" header, `v-model` subheader, with a link to issue #28:
21+
22+
```
23+
fix(v-model): handle events on blur
24+
close #28
25+
```
26+
27+
Appears under "Performance Improvements" header, and under "Breaking Changes" with the breaking change explanation:
28+
29+
```
30+
perf(core): improve vdom diffing by removing 'foo' option
31+
BREAKING CHANGE: The 'foo' option has been removed.
32+
```
33+
34+
The following commit and commit `667ecc1` do not appear in the changelog if they are under the same release. If not, the revert commit appears under the "Reverts" header.
35+
36+
```
37+
revert: feat(compiler): add 'comments' option
38+
This reverts commit 667ecc1654a317a13331b17617d973392f415f02.
39+
```
40+
41+
### Full Message Format
42+
43+
A commit message consists of a **header**, **body** and **footer**. The header has a **type**, **scope** and **subject**:
44+
45+
```
46+
<type>(<scope>): <subject>
47+
<BLANK LINE>
48+
<body>
49+
<BLANK LINE>
50+
<footer>
51+
```
52+
53+
The **header** is mandatory and the **scope** of the header is optional.
54+
55+
### Revert
56+
57+
If the commit reverts a previous commit, it should begin with `revert: `, followed by the header of the reverted commit. In the body, it should say: `This reverts commit <hash>.`, where the hash is the SHA of the commit being reverted.
58+
59+
### Type
60+
61+
If the prefix is `feat`, `fix` or `perf`, it will appear in the changelog. However, if there is any [BREAKING CHANGE](#footer), the commit will always appear in the changelog.
62+
63+
Other prefixes are up to your discretion. Suggested prefixes are `docs`, `chore`, `style`, `refactor`, and `test` for non-changelog related tasks.
64+
65+
### Scope
66+
67+
The scope could be anything specifying the place of the commit change. For example `core`, `compiler`, `ssr`, `v-model`, `transition` etc...
68+
69+
### Subject
70+
71+
The subject contains a succinct description of the change:
72+
73+
* use the imperative, present tense: "change" not "changed" nor "changes"
74+
* don't capitalize the first letter
75+
* no dot (.) at the end
76+
77+
### Body
78+
79+
Just as in the **subject**, use the imperative, present tense: "change" not "changed" nor "changes".
80+
The body should include the motivation for the change and contrast this with previous behavior.
81+
82+
### Footer
83+
84+
The footer should contain any information about **Breaking Changes** and is also the place to
85+
reference GitHub issues that this commit **Closes**.
86+
87+
**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines. The rest of the commit message is then used for this.

.github/workflows/release.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
env:
9+
LOG_BRANCH: 'main'
10+
LOG_FILE: 'CHANGELOG.md'
11+
LOG_HEADER: "# unity-webgl\n"
12+
13+
jobs:
14+
release:
15+
runs-on: ubuntu-latest
16+
17+
permissions:
18+
contents: write
19+
pull-requests: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
persist-credentials: true
27+
28+
- name: Setup node
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: lts/*
32+
registry-url: https://registry.npmjs.org/
33+
34+
- name: Install pnpm
35+
uses: pnpm/action-setup@v4
36+
with:
37+
version: latest
38+
39+
- name: Install dependencies
40+
run: pnpm install
41+
42+
- name: CI:test
43+
run: |
44+
pnpm run test --coverage
45+
46+
- name: Upload coverage reports to Codecov
47+
uses: codecov/codecov-action@v4
48+
env:
49+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
50+
51+
- name: CI:Build
52+
run: pnpm run build
53+
54+
- name: Publish package to npm
55+
run: pnpm publish -r --filter unity-webgl --access public --no-git-checks
56+
env:
57+
NODE_AUTH_TOKEN: ${{secrets.NPM_ACCESS_TOKEN}}
58+
59+
- name: Release changelog -(0)
60+
run: npx changelogithub
61+
env:
62+
GITHUB_TOKEN: ${{secrets.GH_RELEASE_TOKEN}}
63+
64+
- name: Get tag name -(1)
65+
if: startsWith(github.ref, 'refs/tags/')
66+
run: |
67+
TAG_NAME=${GITHUB_REF#refs/tags/}
68+
echo "Current TAG: ${TAG_NAME}"
69+
# 保存 TAG_NAME 到环境变量
70+
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
71+
72+
- name: Generate changelog -(2)
73+
if: startsWith(github.ref, 'refs/tags/')
74+
run: |
75+
git checkout "$LOG_BRANCH"
76+
# 输出当前 changelog 内容
77+
npx changelogithub --output __LOG.md
78+
TAG_CONTENT=$(cat __LOG.md)
79+
TAG_TITLE="## $TAG_NAME\n"
80+
# 检查日志文件是否存在
81+
if [ ! -f "$LOG_FILE" ]; then
82+
echo "$LOG_HEADER" > "$LOG_FILE"
83+
fi
84+
# 拼接日志顶部内容
85+
LOG_CONTENT="$LOG_HEADER\n$TAG_TITLE\n$TAG_CONTENT\n"
86+
# 使用 echo 插入新内容,然后用 cat 追加剩余的内容(去掉第一行)
87+
(echo -e "$LOG_CONTENT"; tail -n +2 "$LOG_FILE") > __temp_file && mv __temp_file "$LOG_FILE"
88+
89+
- name: Sync changelog -(3)
90+
if: startsWith(github.ref, 'refs/tags/')
91+
run: |
92+
git config --global user.name "github-actions[bot]"
93+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
94+
git add "$LOG_FILE"
95+
git commit -m "chore: update changelog"
96+
git push origin "$LOG_BRANCH"
97+
echo "😍 changelog synced"

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,25 @@
3434
"access": "public",
3535
"registry": "https://registry.npmjs.org/"
3636
},
37+
"changelogithub": {
38+
"types": {
39+
"feat": {
40+
"title": "🎉 Features"
41+
},
42+
"fix": {
43+
"title": "🐞 Bug Fixes"
44+
},
45+
"perf": {
46+
"title": "🚀 Performance"
47+
},
48+
"docs": {
49+
"title": "📝 Documentation"
50+
},
51+
"refactor": {
52+
"title": "♻️ Code Refactoring"
53+
}
54+
}
55+
},
3756
"keywords": [],
3857
"author": "Mariner <mengqing723@gmail.com>",
3958
"license": "Apache-2.0",

0 commit comments

Comments
 (0)