-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (128 loc) · 4.4 KB
/
release.yml
File metadata and controls
153 lines (128 loc) · 4.4 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
name: Release
on:
push:
tags:
- 'v*.*.*' # 匹配 vX.Y.Z 格式的标签
# 添加权限配置,适用于所有 jobs
permissions:
contents: write
issues: write
pull-requests: write
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
# Windows
- target: x86_64-pc-windows-msvc
os: windows-latest
archive-name: fishpi-client-windows-x64.zip
# Linux
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive-name: fishpi-client-linux-x64.tar.gz
# macOS
- target: x86_64-apple-darwin
os: macos-latest
archive-name: fishpi-client-macos-x64.tar.gz
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Build client
run: cargo build --release --target ${{ matrix.target }} --bin client
- name: Package Windows
if: matrix.os == 'windows-latest'
run: |
New-Item -ItemType Directory -Path "release" -Force
Copy-Item "target\${{ matrix.target }}\release\client.exe" "release\client-windows.exe"
- name: Package Linux
if: matrix.os == 'ubuntu-latest'
run: |
mkdir -p release
cp target/${{ matrix.target }}/release/client release/client-linux
- name: Package macOS
if: matrix.os == 'macos-latest'
run: |
mkdir -p release
cp target/${{ matrix.target }}/release/client release/client-macos
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: release/*
create-release:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Get current tag version
id: version
run: echo "VERSION=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT
- name: Get previous tag
id: prev_tag
run: |
CURRENT_TAG="${GITHUB_REF_NAME}"
git fetch --tags
PREV_TAG=$(git tag --sort=-creatordate | grep -v "$CURRENT_TAG" | head -n 1)
if [ -z "$PREV_TAG" ]; then
echo "No previous tag found. This might be the first release."
echo "PREV_TAG=" >> $GITHUB_OUTPUT
else
echo "Previous tag found: $PREV_TAG"
echo "PREV_TAG=$PREV_TAG" >> $GITHUB_OUTPUT
fi
- name: Generate changelog
id: changelog
run: |
CURRENT_TAG="${GITHUB_REF_NAME}"
PREV_TAG="${{ steps.prev_tag.outputs.PREV_TAG }}"
echo "Generating changelog from $PREV_TAG to $CURRENT_TAG"
CHANGELOG_CONTENT=""
if [ -z "$PREV_TAG" ]; then
CHANGELOG_CONTENT=$(git log --pretty=format:"* %s (%an)")
else
CHANGELOG_CONTENT=$(git log "$PREV_TAG..$CURRENT_TAG" --pretty=format:"* %s (%an)")
fi
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG_CONTENT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
shell: bash
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.version.outputs.VERSION }}
name: FishPi Client ${{ steps.version.outputs.VERSION }}
body: |
## FishPi 聊天室Rust命令行客户端 ${{ steps.version.outputs.VERSION }}
### 更新内容
${{ steps.changelog.outputs.CHANGELOG }}
### 下载
- **Windows**: `client-windows.exe`
- **Linux**: `client-linux`
- **macOS**: `client-macos`
### 使用方法
1. 下载对应平台的文件
2. 运行 `client` 程序
files: |
artifacts/*/client-windows.exe
artifacts/*/client-linux
artifacts/*/client-macos
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}