-
Notifications
You must be signed in to change notification settings - Fork 24
97 lines (81 loc) · 2.7 KB
/
Copy pathrelease.yml
File metadata and controls
97 lines (81 loc) · 2.7 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
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
name: Release
on:
push:
tags:
- 'v*'
env:
LOG_BRANCH: 'main'
LOG_FILE: 'CHANGELOG.md'
LOG_HEADER: "# unity-webgl\n"
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: true
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: lts/*
registry-url: https://registry.npmjs.org/
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: latest
- name: Install dependencies
run: pnpm install
- name: CI:test
run: |
pnpm run test --coverage
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: CI:Build
run: pnpm run build
- name: Publish package to npm
run: pnpm publish -r --filter unity-webgl --access public --no-git-checks
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_ACCESS_TOKEN}}
- name: Release changelog -(0)
run: npx changelogithub
env:
GITHUB_TOKEN: ${{secrets.GH_RELEASE_TOKEN}}
- name: Get tag name -(1)
if: startsWith(github.ref, 'refs/tags/')
run: |
TAG_NAME=${GITHUB_REF#refs/tags/}
echo "Current TAG: ${TAG_NAME}"
# 保存 TAG_NAME 到环境变量
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
- name: Generate changelog -(2)
if: startsWith(github.ref, 'refs/tags/')
run: |
git checkout "$LOG_BRANCH"
# 输出当前 changelog 内容
npx changelogithub --output __LOG.md
TAG_CONTENT=$(cat __LOG.md)
TAG_TITLE="## $TAG_NAME\n"
# 检查日志文件是否存在
if [ ! -f "$LOG_FILE" ]; then
echo "$LOG_HEADER" > "$LOG_FILE"
fi
# 拼接日志顶部内容
LOG_CONTENT="$LOG_HEADER\n$TAG_TITLE\n$TAG_CONTENT\n"
# 使用 echo 插入新内容,然后用 cat 追加剩余的内容(去掉第一行)
(echo -e "$LOG_CONTENT"; tail -n +2 "$LOG_FILE") > __temp_file && mv __temp_file "$LOG_FILE"
- name: Sync changelog -(3)
if: startsWith(github.ref, 'refs/tags/')
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add "$LOG_FILE"
git commit -m "chore: update changelog"
git push origin "$LOG_BRANCH"
echo "😍 changelog synced"