-
Notifications
You must be signed in to change notification settings - Fork 0
209 lines (178 loc) · 5.64 KB
/
main.yml
File metadata and controls
209 lines (178 loc) · 5.64 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
name: CI/CD Pipeline
on:
push:
branches: [main, develop]
tags: ['v*']
pull_request:
branches: [main, develop]
env:
CARGO_TERM_COLOR: always
permissions:
contents: write
packages: write
jobs:
# 代码质量检查
quality:
name: Code Quality
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Cache cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Format check
run: |
if ! cargo fmt --all -- --check; then
echo "❌ 代码格式不符合规范!请运行: cargo fmt --all"
exit 1
fi
- name: Clippy check
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Security audit
run: |
cargo install cargo-audit --quiet
cargo audit
# 测试
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
rust: [stable]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- name: Cache cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-${{ matrix.rust }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Run tests
run: cargo test --verbose
- name: Build
run: cargo build --release --verbose
# 发布构建 (仅在标签推送时)
release:
name: Release
if: startsWith(github.ref, 'refs/tags/v')
needs: [quality, test]
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
archive: tar.gz
- os: macos-latest
target: x86_64-apple-darwin
archive: tar.gz
- os: windows-latest
target: x86_64-pc-windows-msvc
archive: zip
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build binary
run: cargo build --release
- name: Get tag name
id: tag_name
run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
shell: bash
- name: Prepare binary (Unix)
if: matrix.archive == 'tar.gz'
run: |
cd target/release
strip plm || true
tar -czf ../../plm-${{ steps.tag_name.outputs.TAG_NAME }}-${{ matrix.target }}.tar.gz plm
- name: Prepare binary (Windows)
if: matrix.archive == 'zip'
run: |
cd target/release
Compress-Archive -Path plm.exe -DestinationPath ../../plm-${{ steps.tag_name.outputs.TAG_NAME }}-${{ matrix.target }}.zip
shell: powershell
- name: Create Release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tag_name.outputs.TAG_NAME }}
name: PLM ${{ steps.tag_name.outputs.TAG_NAME }}
body: |
## PLM ${{ steps.tag_name.outputs.TAG_NAME }}
### 🚀 新功能
- 插件生命周期管理
- 配置管理系统
- CLI 工具
### 📦 一键安装
```bash
curl -fsSL https://raw.githubusercontent.com/${{ github.repository }}/main/scripts/install.sh | sh
```
### 📋 手动下载
- **Linux**: `plm-${{ steps.tag_name.outputs.TAG_NAME }}-x86_64-unknown-linux-gnu.tar.gz`
- **macOS**: `plm-${{ steps.tag_name.outputs.TAG_NAME }}-x86_64-apple-darwin.tar.gz`
- **Windows**: `plm-${{ steps.tag_name.outputs.TAG_NAME }}-x86_64-pc-windows-msvc.zip`
draft: false
prerelease: false
files: |
plm-${{ steps.tag_name.outputs.TAG_NAME }}-${{ matrix.target }}.*
# 自动格式化 (仅 PR)
auto-format:
name: Auto Format
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.head_ref }}
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Format code
run: cargo fmt --all
- name: Check for changes
id: verify-changed-files
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi
- name: Commit formatted code
if: steps.verify-changed-files.outputs.changed == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m "🎨 Auto-format code with rustfmt"
git push