Skip to content

Commit 55ca606

Browse files
committed
feat: 添加 GitHub Actions 工作流以支持构建和测试
1 parent a238afa commit 55ca606

1 file changed

Lines changed: 140 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
name: Build & Test
2+
3+
on:
4+
push:
5+
branches: ["main", "dev"]
6+
pull_request:
7+
branches: ["main"]
8+
workflow_dispatch:
9+
inputs:
10+
publish:
11+
description: 'Publish to crates.io'
12+
required: false
13+
default: 'false'
14+
type: boolean
15+
16+
env:
17+
CARGO_TERM_COLOR: always
18+
19+
jobs:
20+
test:
21+
name: Test on ${{ matrix.os }}
22+
runs-on: ${{ matrix.os }}
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
os: [ubuntu-latest, windows-latest, macos-latest]
27+
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- name: Setup Rust
32+
uses: dtolnay/rust-toolchain@stable
33+
34+
- name: Cache Rust dependencies
35+
uses: actions/cache@v4
36+
with:
37+
path: |
38+
~/.cargo/registry
39+
~/.cargo/git
40+
target
41+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
42+
restore-keys: ${{ runner.os }}-cargo-
43+
44+
- name: Check formatting
45+
run: cargo fmt --check
46+
47+
- name: Run clippy
48+
run: cargo clippy -- -D warnings
49+
continue-on-error: true
50+
51+
- name: Run tests
52+
run: cargo test --verbose
53+
54+
- name: Build release
55+
run: cargo build --release
56+
57+
# Cross-compile for multiple targets
58+
build-cross:
59+
name: Build ${{ matrix.target.name }}
60+
needs: test
61+
runs-on: ${{ matrix.target.os }}
62+
strategy:
63+
fail-fast: false
64+
matrix:
65+
target:
66+
- name: Linux x86_64
67+
os: ubuntu-latest
68+
target: x86_64-unknown-linux-gnu
69+
- name: Linux ARM64
70+
os: ubuntu-latest
71+
target: aarch64-unknown-linux-gnu
72+
- name: Windows x86_64
73+
os: windows-latest
74+
target: x86_64-pc-windows-msvc
75+
- name: macOS x86_64
76+
os: macos-latest
77+
target: x86_64-apple-darwin
78+
- name: macOS ARM64
79+
os: macos-latest
80+
target: aarch64-apple-darwin
81+
82+
steps:
83+
- uses: actions/checkout@v4
84+
85+
- name: Setup Rust
86+
uses: dtolnay/rust-toolchain@stable
87+
with:
88+
targets: ${{ matrix.target.target }}
89+
90+
- name: Install cross compile tools (Linux ARM64)
91+
if: matrix.target.target == 'aarch64-unknown-linux-gnu'
92+
run: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu
93+
94+
- name: Cache Rust dependencies
95+
uses: actions/cache@v4
96+
with:
97+
path: |
98+
~/.cargo/registry
99+
~/.cargo/git
100+
target
101+
key: ${{ runner.os }}-${{ matrix.target.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
102+
restore-keys: ${{ runner.os }}-${{ matrix.target.target }}-cargo-
103+
104+
- name: Build release
105+
run: cargo build --release --target ${{ matrix.target.target }}
106+
env:
107+
CC_aarch64_unknown_linux_gnu: aarch64-linux-gnu-gcc
108+
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
109+
110+
- name: Package library
111+
shell: bash
112+
run: |
113+
mkdir -p artifacts
114+
# Copy compiled library files
115+
find target/${{ matrix.target.target }}/release -maxdepth 1 \( -name "*.rlib" -o -name "*.so" -o -name "*.dylib" -o -name "*.dll" -o -name "*.a" \) -exec cp {} artifacts/ \; 2>/dev/null || true
116+
ls -la artifacts/
117+
118+
- name: Upload artifacts
119+
uses: actions/upload-artifact@v4
120+
with:
121+
name: wechat-oa-sdk-${{ matrix.target.target }}
122+
path: artifacts/
123+
if-no-files-found: warn
124+
125+
# Publish to crates.io (manual trigger only)
126+
publish:
127+
name: Publish to crates.io
128+
needs: [test, build-cross]
129+
runs-on: ubuntu-latest
130+
if: github.event.inputs.publish == 'true'
131+
steps:
132+
- uses: actions/checkout@v4
133+
134+
- name: Setup Rust
135+
uses: dtolnay/rust-toolchain@stable
136+
137+
- name: Publish
138+
run: cargo publish --dry-run
139+
env:
140+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

0 commit comments

Comments
 (0)