forked from creazyboyone/FastGithub
-
Notifications
You must be signed in to change notification settings - Fork 0
185 lines (157 loc) · 5.72 KB
/
release.yml
File metadata and controls
185 lines (157 loc) · 5.72 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
name: Create Release
on:
workflow_dispatch:
inputs:
version:
description: '版本号 (例如: v1.0.0)'
required: true
type: string
prerelease:
description: '是否为预发布版本'
required: false
type: boolean
default: false
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7.0.x'
- name: Validate version format
run: |
if [[ ! "${{ github.event.inputs.version }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?$ ]]; then
echo "错误: 版本号格式不正确。请使用格式: v1.0.0 或 v1.0.0-beta"
exit 1
fi
- name: Check if tag exists
run: |
if git rev-parse "${{ github.event.inputs.version }}" >/dev/null 2>&1; then
echo "错误: 标签 ${{ github.event.inputs.version }} 已存在"
exit 1
fi
- name: Create and push tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "${{ github.event.inputs.version }}" -m "Release ${{ github.event.inputs.version }}"
git push origin "${{ github.event.inputs.version }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-artifacts:
needs: build-and-release
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
include:
- os: ubuntu-latest
runtime: linux-x64
artifact-name: fastgithub-linux-x64
- os: windows-latest
runtime: win-x64
artifact-name: fastgithub-win-x64
- os: macos-latest
runtime: osx-x64
artifact-name: fastgithub-osx-x64
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.version }}
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7.0.x'
- name: Restore dependencies
run: dotnet restore FastGithub.sln
- name: Build and publish
shell: bash
run: |
# 发布主程序
dotnet publish FastGithub/FastGithub.csproj \
-c Release \
-r ${{ matrix.runtime }} \
--self-contained true \
-p:PublishSingleFile=true \
-p:PublishTrimmed=true \
-o ./publish/${{ matrix.runtime }}
# 发布 UI (仅 Windows)
if [ "${{ matrix.runtime }}" == "win-x64" ]; then
dotnet publish FastGithub.UI/FastGithub.UI.csproj \
-c Release \
-o ./publish/${{ matrix.runtime }}
fi
- name: Create archive
shell: bash
run: |
cd ./publish/${{ matrix.runtime }}
if [ "${{ matrix.os }}" == "windows-latest" ]; then
7z a -tzip ../../${{ matrix.artifact-name }}.zip *
else
tar -czf ../../${{ matrix.artifact-name }}.tar.gz *
fi
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact-name }}
path: |
${{ matrix.artifact-name }}.zip
${{ matrix.artifact-name }}.tar.gz
create-github-release:
needs: build-artifacts
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.version }}
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Prepare release assets
run: |
mkdir -p ./release-assets
find ./artifacts -name "*.zip" -o -name "*.tar.gz" | while read file; do
cp "$file" ./release-assets/
done
ls -la ./release-assets/
- name: Generate release notes
id: release_notes
run: |
cat > release_notes.md << 'EOF'
## FastGithub Release ${{ github.event.inputs.version }}
🚀 **新版本发布**
### 📦 下载说明
- **Windows 用户**: 下载 `fastgithub-win-x64.zip`
- **Linux 用户**: 下载 `fastgithub-linux-x64.tar.gz`
- **macOS 用户**: 下载 `fastgithub-osx-x64.tar.gz`
### 🔧 安装说明
请参考 [README.md](https://github.com/${{ github.repository }}/blob/main/README.md) 中的部署方式。
### ⚠️ 注意事项
- Windows版本包含UI界面程序
- 首次使用需要安装并信任CA证书
- 详细配置请查看项目文档
---
**完整更新日志**: https://github.com/${{ github.repository }}/compare/$(git describe --tags --abbrev=0 HEAD^)...${{ github.event.inputs.version }}
EOF
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.event.inputs.version }}
name: FastGithub ${{ github.event.inputs.version }}
body_path: release_notes.md
files: ./release-assets/*
draft: false
prerelease: ${{ github.event.inputs.prerelease }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Cleanup artifacts
run: rm -rf ./artifacts ./release-assets release_notes.md