-
Notifications
You must be signed in to change notification settings - Fork 1
128 lines (113 loc) · 4.06 KB
/
Copy pathbuild_release.yml
File metadata and controls
128 lines (113 loc) · 4.06 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: build_release
on:
schedule:
- cron: '0 19 * * *'
workflow_dispatch:
jobs:
check_changes:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.changes.outputs.changed }}
steps:
- name: 检出代码
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 检测 src 目录变更
id: changes
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
else
prev_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "none")
if [ "$prev_tag" == "none" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
else
if git diff --exit-code $prev_tag HEAD -- src; then
echo "No changes detected in 'src' directory between $prev_tag and the latest commit."
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
fi
fi
build_release:
needs: check_changes
if: ${{ needs.check_changes.outputs.changed == 'true' }}
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: 检出代码
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 设置Node.js环境
uses: actions/setup-node@v4
with:
node-version: 25
- name: 设置pnpm环境
uses: pnpm/action-setup@v4
- name: 安装依赖
run: pnpm install
- name: 构建项目
run: pnpm run build
- name: 获取版本号
id: version
run: |
version=$(node -e "import('@gkd-kit/tools').then((m) => m.stdoutGkdVersion());")
echo "version=${version}" >> "$GITHUB_OUTPUT"
- name: 提交代码变更
id: commit
run: |
git config --local user.email github-actions[bot]@users.noreply.github.com
git config --local user.name github-actions[bot]
git status
git add .
git commit -a -m "chore: v${{steps.version.outputs.version}}"
continue-on-error: true
- name: 推送代码到仓库
if: ${{ steps.commit.outcome == 'success' }}
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
tags: true
- name: 创建GitHub Release
id: create_release
if: ${{ steps.commit.outcome == 'success' }}
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.version.outputs.version }}
name: Release ${{ steps.version.outputs.version }}
body_path: ./dist/CHANGELOG.md
#- name: 发布到npm
# env:
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# if: ${{ steps.commit.outcome == 'success' && env.NPM_TOKEN != '' }}
# run: |
# pnpm config set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }}
# node -e "import('@gkd-kit/tools').then((m) => m.updatePkgVersion());"
# pnpm publish --no-git-checks
# node -e "import('@gkd-kit/tools').then((m) => m.syncNpmmirror());"
sync_to_gitee:
needs: build_release
runs-on: ubuntu-latest
steps:
- name: 检出代码(包含构建过程的提交)
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.ref }}
- name: 配置 Git 用户信息
run: |
git config --local user.email github-actions[bot]@users.noreply.github.com
git config --local user.name github-actions[bot]
- name: 同步代码到 Gitee
env:
GITEE_TOKEN: ${{ secrets.GITEE_TOKEN }}
run: |
git remote add gitee https://AliusCode:${GITEE_TOKEN}@gitee.com/AliusCode/GKD-subscription.git || git remote set-url gitee https://AliusCode:${GITEE_TOKEN}@gitee.com/AliusCode/GKD-subscription.git
git push --mirror gitee