Skip to content

Commit 3383065

Browse files
committed
add release and build workflow
1 parent d57abb9 commit 3383065

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

.github/workflows/build.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: Build Rust Binaries
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
release:
9+
types: [published]
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
name: Build for ${{ matrix.target }}
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
matrix:
18+
include:
19+
- os: ubuntu-latest
20+
target: x86_64-unknown-linux-gnu
21+
artifact_name: externkit
22+
asset_name: externkit-linux-x86_64
23+
- os: windows-latest
24+
target: x86_64-pc-windows-msvc
25+
artifact_name: externkit.exe
26+
asset_name: externkit-windows-x86_64.exe
27+
- os: macos-latest
28+
target: x86_64-apple-darwin
29+
artifact_name: externkit
30+
asset_name: externkit-macos-x86_64
31+
- os: macos-latest
32+
target: aarch64-apple-darwin
33+
artifact_name: externkit
34+
asset_name: externkit-macos-aarch64
35+
36+
steps:
37+
- name: Checkout code
38+
uses: actions/checkout@v4
39+
40+
- name: Install Rust
41+
uses: dtolnay/rust-toolchain@stable
42+
with:
43+
targets: ${{ matrix.target }}
44+
45+
- name: Cache cargo registry
46+
uses: actions/cache@v4
47+
with:
48+
path: |
49+
~/.cargo/registry
50+
~/.cargo/git
51+
target
52+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
53+
restore-keys: |
54+
${{ runner.os }}-cargo-
55+
56+
- name: Build binary
57+
run: cargo build --release --target ${{ matrix.target }}
58+
59+
- name: Strip binary (Linux and macOS)
60+
if: matrix.os != 'windows-latest'
61+
run: strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
62+
63+
- name: Upload artifact
64+
uses: actions/upload-artifact@v4
65+
with:
66+
name: ${{ matrix.asset_name }}
67+
path: target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
68+
69+
release:
70+
name: Create Release
71+
needs: build
72+
runs-on: ubuntu-latest
73+
if: github.event_name == 'release'
74+
75+
steps:
76+
- name: Download all artifacts
77+
uses: actions/download-artifact@v4
78+
with:
79+
path: artifacts
80+
81+
- name: Display structure of downloaded files
82+
run: ls -R artifacts
83+
84+
- name: Create compressed archives
85+
run: |
86+
cd artifacts
87+
for dir in */; do
88+
cd "$dir"
89+
if [[ "$dir" == *"windows"* ]]; then
90+
zip "../${dir%/}.zip" *
91+
else
92+
tar -czf "../${dir%/}.tar.gz" *
93+
fi
94+
cd ..
95+
done
96+
97+
- name: Upload release assets
98+
uses: softprops/action-gh-release@v1
99+
with:
100+
files: |
101+
artifacts/*.zip
102+
artifacts/*.tar.gz
103+
env:
104+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)