Skip to content

Commit 95358ab

Browse files
authored
Create rust.yml
add github workflow
1 parent 24b33c4 commit 95358ab

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

.github/workflows/rust.yml

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Rust
2+
3+
on:
4+
push:
5+
tags:
6+
# Regex for a version number such as 0.2.1
7+
- "[0-9]+.[0-9]+.[0-9]+"
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
build-and-upload:
14+
name: Build and upload
15+
runs-on: ${{ matrix.os }}
16+
17+
strategy:
18+
matrix:
19+
include:
20+
- build: linux
21+
os: ubuntu-latest
22+
target: x86_64-unknown-linux-musl
23+
24+
- build: macos
25+
os: macos-latest
26+
target: x86_64-apple-darwin
27+
28+
- build: macos-aarch64
29+
os: macos-latest
30+
target: aarch64-apple-darwin
31+
32+
- build: windows-msvc
33+
os: windows-latest
34+
target: x86_64-pc-windows-msvc
35+
steps:
36+
- name: Clone repository
37+
uses: actions/checkout@v3
38+
39+
- name: Install Rust
40+
# Or @nightly if you want
41+
uses: dtolnay/rust-toolchain@stable
42+
# Arguments to pass in
43+
with:
44+
# Make Rust compile to our target (defined in the matrix)
45+
targets: ${{ matrix.target }}
46+
47+
- name: Get the release version from the tag
48+
shell: bash
49+
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
50+
51+
- name: Build
52+
uses: actions-rs/cargo@v1
53+
with:
54+
use-cross: true
55+
command: build
56+
args: --verbose --release --target ${{ matrix.target }}
57+
58+
- name: Build archive
59+
shell: bash
60+
run: |
61+
# Replace with the name of your binary
62+
binary_name="<BINARY_NAME>"
63+
64+
dirname="$binary_name-${{ env.VERSION }}-${{ matrix.target }}"
65+
mkdir "$dirname"
66+
if [ "${{ matrix.os }}" = "windows-latest" ]; then
67+
mv "target/${{ matrix.target }}/release/$binary_name.exe" "$dirname"
68+
else
69+
mv "target/${{ matrix.target }}/release/$binary_name" "$dirname"
70+
fi
71+
cp "settings.json" "$dirname"
72+
73+
if [ "${{ matrix.os }}" = "windows-latest" ]; then
74+
7z a "$dirname.zip" "$dirname"
75+
echo "ASSET=$dirname.zip" >> $GITHUB_ENV
76+
else
77+
tar -czf "$dirname.tar.gz" "$dirname"
78+
echo "ASSET=$dirname.tar.gz" >> $GITHUB_ENV
79+
fi
80+
81+
- name: Upload the binaries
82+
uses: softprops/action-gh-release@v1
83+
with:
84+
files: |
85+
${{ env.ASSET }}

0 commit comments

Comments
 (0)