Skip to content

Commit 4361859

Browse files
committed
Implement releases
1 parent 098a6af commit 4361859

1 file changed

Lines changed: 232 additions & 20 deletions

File tree

.github/workflows/ci.yml

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

0 commit comments

Comments
 (0)