Skip to content

Commit f59c3ff

Browse files
committed
Implement releases
1 parent 098a6af commit f59c3ff

1 file changed

Lines changed: 231 additions & 20 deletions

File tree

.github/workflows/ci.yml

Lines changed: 231 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,89 @@ on: [push, pull_request]
33
name: CI
44

55
jobs:
6-
ci:
6+
build:
7+
name: ${{ matrix.name }}
78
runs-on: ${{ matrix.os }}
89
strategy:
10+
fail-fast: false
911
matrix:
10-
os: [windows-latest, ubuntu-latest, macos-latest]
11-
rust:
12-
- stable
13-
- beta
14-
- nightly
15-
- 1.86.0 # MSRV
12+
include:
13+
# MSRV builds
14+
- name: Windows - MSRV
15+
os: windows-latest
16+
rust: 1.86.0
17+
target: x86_64-pc-windows-msvc
18+
- name: Linux - MSRV
19+
os: ubuntu-latest
20+
rust: 1.86.0
21+
target: x86_64-unknown-linux-gnu
22+
- name: macOS - MSRV
23+
os: macos-latest
24+
rust: 1.86.0
25+
target: aarch64-apple-darwin
26+
# Beta builds
27+
- name: Windows - Beta
28+
os: windows-latest
29+
rust: beta
30+
target: x86_64-pc-windows-msvc
31+
- name: Linux - Beta
32+
os: ubuntu-latest
33+
rust: beta
34+
target: x86_64-unknown-linux-gnu
35+
- name: macOS - Beta
36+
os: macos-latest
37+
rust: beta
38+
target: aarch64-apple-darwin
39+
# Nightly builds
40+
- name: Windows - Nightly
41+
os: windows-latest
42+
rust: nightly
43+
target: x86_64-pc-windows-msvc
44+
- name: Linux - Nightly
45+
os: ubuntu-latest
46+
rust: nightly
47+
target: x86_64-unknown-linux-gnu
48+
- name: macOS - Nightly
49+
os: macos-latest
50+
rust: nightly
51+
target: aarch64-apple-darwin
52+
# Stable builds with artifact creation
53+
- name: Windows - Stable (x86_64)
54+
os: windows-latest
55+
rust: stable
56+
target: x86_64-pc-windows-msvc
57+
artifact_name: cargo-ndk_windows_x86_64
58+
- name: Linux - Stable (x86_64)
59+
os: ubuntu-latest
60+
rust: stable
61+
target: x86_64-unknown-linux-gnu
62+
artifact_name: cargo-ndk_linux_x86_64
63+
- name: macOS - Stable (aarch64)
64+
os: macos-latest
65+
rust: stable
66+
target: aarch64-apple-darwin
67+
artifact_name: cargo-ndk_macos_aarch64
1668
steps:
1769
- name: Checkout
1870
uses: actions/checkout@v4
71+
- name: Install Rust toolchain
72+
uses: dtolnay/rust-toolchain@master
73+
with:
74+
toolchain: ${{ matrix.rust }}
75+
targets: ${{ matrix.target && format('{0},', matrix.target) || '' }}aarch64-linux-android,armv7-linux-androideabi
76+
components: rustfmt, clippy
77+
- name: Check code formatting
78+
run: cargo fmt --all -- --check
79+
- name: Run clippy
80+
run: cargo clippy -- -D warnings
1981
- name: Install MSYS (Windows only)
2082
if: runner.os == 'Windows'
2183
uses: msys2/setup-msys2@v2
2284
with:
2385
path-type: inherit
2486
msystem: UCRT64
25-
- name: Install Rust toolchain
26-
uses: dtolnay/rust-toolchain@master
27-
with:
28-
toolchain: ${{ matrix.rust }}
29-
targets: aarch64-linux-android, armv7-linux-androideabi
30-
components: rustfmt, clippy
3187
- name: Run build
32-
run: cargo install --locked --path .
88+
run: cargo install --locked --target ${{ matrix.target }} --path .
3389
- name: Smoke test `ndk-env`
3490
run: cargo ndk-env --target armeabi-v7a
3591
- name: Run basic example
@@ -44,9 +100,164 @@ jobs:
44100
if: runner.os != 'Windows'
45101
working-directory: example/openssl
46102
run: cargo ndk -t arm64-v8a --platform 28 build
47-
- name: Check code formatting
48-
continue-on-error: true
49-
run: cargo fmt --all -- --check
50-
- name: Run clippy
51-
continue-on-error: true
52-
run: cargo clippy -- -D warnings
103+
- name: Get version
104+
if: matrix.target
105+
id: version
106+
shell: bash
107+
run: |
108+
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
109+
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
110+
else
111+
echo "VERSION=dev" >> $GITHUB_OUTPUT
112+
fi
113+
- name: Build release binary
114+
if: matrix.target
115+
run: cargo build --locked --release --target ${{ matrix.target }}
116+
- name: Copy binary (Unix)
117+
if: matrix.target && runner.os != 'Windows'
118+
run: |
119+
mkdir artifacts
120+
for file in cargo-ndk cargo-ndk-env cargo-ndk-test cargo-ndk-runner; do
121+
cp target/${{ matrix.target }}/release/$file artifacts/$file
122+
done
123+
- name: Copy binary (Windows)
124+
if: matrix.target && runner.os == 'Windows'
125+
run: |
126+
mkdir artifacts
127+
foreach ($file in @('cargo-ndk.exe', 'cargo-ndk-env.exe', 'cargo-ndk-test.exe', 'cargo-ndk-runner.exe')) {
128+
Copy-Item "target/${{ matrix.target }}/release/$file" "artifacts/$file"
129+
}
130+
- name: Create tar.gz archive (Unix)
131+
if: matrix.target && runner.os != 'Windows'
132+
run: |
133+
cd artifacts
134+
tar -cf ../${{ matrix.artifact_name }}_${{ steps.version.outputs.VERSION }}.tar *
135+
gzip -9 ../${{ matrix.artifact_name }}_${{ steps.version.outputs.VERSION }}.tar
136+
- name: Create zip archive (Windows)
137+
if: matrix.target && runner.os == 'Windows'
138+
run: |
139+
cd artifacts
140+
7z a -mx=9 ../${{ matrix.artifact_name }}_${{ steps.version.outputs.VERSION }}.zip *
141+
- name: Upload artifacts (Unix)
142+
uses: actions/upload-artifact@v4
143+
if: matrix.target && runner.os != 'Windows'
144+
with:
145+
name: ${{ matrix.artifact_name }}_${{ steps.version.outputs.VERSION }}
146+
path: ${{ matrix.artifact_name }}_${{ steps.version.outputs.VERSION }}.tar.gz
147+
- name: Upload artifacts (Windows)
148+
uses: actions/upload-artifact@v4
149+
if: matrix.target && runner.os == 'Windows'
150+
with:
151+
name: ${{ matrix.artifact_name }}_${{ steps.version.outputs.VERSION }}
152+
path: ${{ matrix.artifact_name }}_${{ steps.version.outputs.VERSION }}.zip
153+
build-non-host:
154+
name: ${{ matrix.name }}
155+
runs-on: ${{ matrix.os }}
156+
strategy:
157+
fail-fast: false
158+
matrix:
159+
include:
160+
- name: Windows - Stable (aarch64, non-host)
161+
os: windows-latest
162+
rust: stable
163+
target: aarch64-pc-windows-msvc
164+
artifact_name: cargo-ndk_windows_arm64
165+
- name: Linux - Stable (aarch64, non-host)
166+
os: ubuntu-latest
167+
rust: stable
168+
target: aarch64-unknown-linux-gnu
169+
artifact_name: cargo-ndk_linux_aarch64
170+
cross: true
171+
- name: macOS - Stable (x86_64, non-host)
172+
os: macos-latest
173+
rust: stable
174+
target: x86_64-apple-darwin
175+
artifact_name: cargo-ndk_macos_x86_64
176+
steps:
177+
- name: Checkout
178+
uses: actions/checkout@v4
179+
- name: Install Rust toolchain
180+
uses: dtolnay/rust-toolchain@master
181+
with:
182+
toolchain: ${{ matrix.rust }}
183+
targets: ${{ matrix.target }}
184+
- name: Set up cross compilation (Linux)
185+
if: matrix.cross
186+
run: |
187+
cargo install cross --git https://github.com/cross-rs/cross
188+
- name: Build release binary (native)
189+
if: '!matrix.cross'
190+
run: cargo build --locked --release --target ${{ matrix.target }}
191+
- name: Build release binary (cross)
192+
if: matrix.cross
193+
run: cross build --locked --release --target ${{ matrix.target }}
194+
- name: Get version
195+
id: version
196+
shell: bash
197+
run: |
198+
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
199+
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
200+
else
201+
echo "VERSION=dev" >> $GITHUB_OUTPUT
202+
fi
203+
- name: Copy binary (Unix)
204+
if: runner.os != 'Windows'
205+
run: |
206+
mkdir artifacts
207+
for file in cargo-ndk cargo-ndk-env cargo-ndk-test cargo-ndk-runner; do
208+
cp target/${{ matrix.target }}/release/$file artifacts/$file
209+
done
210+
- name: Copy binary (Windows)
211+
if: runner.os == 'Windows'
212+
run: |
213+
mkdir artifacts
214+
foreach ($file in @('cargo-ndk.exe', 'cargo-ndk-env.exe', 'cargo-ndk-test.exe', 'cargo-ndk-runner.exe')) {
215+
Copy-Item "target/${{ matrix.target }}/release/$file" "artifacts/$file"
216+
}
217+
- name: Create tar.gz archive (Unix)
218+
if: runner.os != 'Windows'
219+
run: |
220+
cd artifacts
221+
tar -cf ../${{ matrix.artifact_name }}_${{ steps.version.outputs.VERSION }}.tar *
222+
gzip -9 ../${{ matrix.artifact_name }}_${{ steps.version.outputs.VERSION }}.tar
223+
- name: Create zip archive (Windows)
224+
if: runner.os == 'Windows'
225+
run: |
226+
cd artifacts
227+
7z a -mx=9 ../${{ matrix.artifact_name }}_${{ steps.version.outputs.VERSION }}.zip *
228+
- name: Upload artifacts (Unix)
229+
uses: actions/upload-artifact@v4
230+
if: runner.os != 'Windows'
231+
with:
232+
compression-level: 0
233+
name: ${{ matrix.artifact_name }}_${{ steps.version.outputs.VERSION }}
234+
path: ${{ matrix.artifact_name }}_${{ steps.version.outputs.VERSION }}.tar.gz
235+
- name: Upload artifacts (Windows)
236+
uses: actions/upload-artifact@v4
237+
if: runner.os == 'Windows'
238+
with:
239+
compression-level: 0
240+
name: ${{ matrix.artifact_name }}_${{ steps.version.outputs.VERSION }}
241+
path: ${{ matrix.artifact_name }}_${{ steps.version.outputs.VERSION }}.zip
242+
release:
243+
name: Create GitHub Release
244+
runs-on: ubuntu-latest
245+
needs: [build, build-non-host]
246+
if: startsWith(github.ref, 'refs/tags/v') && contains(github.ref, '.')
247+
steps:
248+
- name: Download all artifacts
249+
uses: actions/download-artifact@v4
250+
with:
251+
path: artifacts
252+
- name: Unzip all the things
253+
run: |
254+
for file in artifacts/*.zip; do
255+
unzip "$file" -d upload/
256+
done
257+
ls -l upload/
258+
- name: Create release
259+
uses: softprops/action-gh-release@v2
260+
with:
261+
files: upload/*
262+
generate_release_notes: true
263+
prerelease: ${{ contains(github.ref, '-') }}

0 commit comments

Comments
 (0)