Skip to content

Commit be853ad

Browse files
committed
add ci workflow
Signed-off-by: Ray Lee <hburaylee@gmail.com>
1 parent d70a849 commit be853ad

1 file changed

Lines changed: 132 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: CI and Release
2+
3+
on:
4+
push:
5+
branches: [ main, ci ]
6+
pull_request:
7+
branches: [ main ]
8+
release:
9+
types: [ published ]
10+
11+
env:
12+
CARGO_TERM_COLOR: always
13+
14+
jobs:
15+
build:
16+
name: Build on ${{ matrix.os }}
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
matrix:
20+
include:
21+
- os: ubuntu-22.04
22+
target: x86_64-unknown-linux-musl
23+
artifact_name: mwget
24+
artifact_name_windows: mwget.exe
25+
asset_name: mwget-linux-x64
26+
- os: ubuntu-22.04-arm
27+
target: aarch64-unknown-linux-musl
28+
artifact_name: mwget
29+
artifact_name_windows: mwget.exe
30+
asset_name: mwget-linux-arm64
31+
- os: macos-15
32+
target: aarch64-apple-darwin
33+
artifact_name: mwget
34+
artifact_name_windows: mwget.exe
35+
asset_name: mwget-macos-arm64
36+
- os: macos-13
37+
target: x86_64-apple-darwin
38+
artifact_name: mwget
39+
artifact_name_windows: mwget.exe
40+
asset_name: mwget-macos-x64
41+
- os: windows-2022
42+
target: x86_64-pc-windows-msvc
43+
artifact_name: mwget.exe
44+
artifact_name_windows: mwget.exe
45+
asset_name: mwget-windows-x64
46+
47+
steps:
48+
- uses: actions/checkout@v4
49+
50+
- name: Install musl target (Linux)
51+
if: contains(matrix.target, 'linux')
52+
run: rustup target add ${{ matrix.target }}
53+
54+
- name: Install Rust target
55+
run: rustup target add ${{ matrix.target }}
56+
57+
- name: Build binary
58+
run: cargo build --release --target ${{ matrix.target }}
59+
60+
- name: Strip binary (Unix)
61+
if: runner.os != 'Windows'
62+
run: strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
63+
64+
- name: Upload artifact
65+
uses: actions/upload-artifact@v4
66+
with:
67+
name: ${{ matrix.asset_name }}
68+
path: target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
69+
70+
release:
71+
name: Create Release
72+
needs: build
73+
runs-on: ubuntu-latest
74+
if: github.event_name == 'release'
75+
76+
steps:
77+
- name: Download all artifacts
78+
uses: actions/download-artifact@v4
79+
with:
80+
path: artifacts
81+
82+
- name: Display structure of downloaded files
83+
run: ls -la artifacts/
84+
85+
- name: Create release archives
86+
run: |
87+
mkdir -p release
88+
cd artifacts
89+
90+
# Linux x64
91+
tar -czf ../release/mwget-linux-x64.tar.gz mwget-linux-x64/mwget
92+
93+
# Linux ARM64
94+
tar -czf ../release/mwget-linux-arm64.tar.gz mwget-linux-arm64/mwget
95+
96+
# macOS ARM64
97+
tar -czf ../release/mwget-macos-arm64.tar.gz mwget-macos-arm64/mwget
98+
99+
# macOS x64
100+
tar -czf ../release/mwget-macos-x64.tar.gz mwget-macos-x64/mwget
101+
102+
# Windows x64
103+
cd mwget-windows-x64
104+
zip -r ../../release/mwget-windows-x64.zip mwget.exe
105+
106+
- name: Upload release assets
107+
uses: softprops/action-gh-release@v2
108+
with:
109+
files: |
110+
release/mwget-linux-x64.tar.gz
111+
release/mwget-linux-arm64.tar.gz
112+
release/mwget-macos-arm64.tar.gz
113+
release/mwget-macos-x64.tar.gz
114+
release/mwget-windows-x64.zip
115+
env:
116+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
117+
118+
test:
119+
name: Run tests
120+
runs-on: ubuntu-latest
121+
122+
steps:
123+
- uses: actions/checkout@v4
124+
125+
- name: Run tests
126+
run: cargo test --verbose
127+
128+
- name: Run clippy
129+
run: cargo clippy -- -D warnings
130+
131+
- name: Check formatting
132+
run: cargo fmt -- --check

0 commit comments

Comments
 (0)