-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (114 loc) · 3.97 KB
/
rust.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Rust
on:
push:
branches:
- main
paths-ignore:
- "**.md"
pull_request:
branches:
- main
paths-ignore:
- "**.md"
workflow_dispatch:
jobs:
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
features:
- ""
- "zip"
name: Build and Test on ${{ matrix.os }} with features '${{ matrix.features }}'
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-${{ matrix.features }}-${{ hashFiles('**/Cargo.lock') }}
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install zip (Linux)
if: runner.os == 'Linux'
run: sudo apt-get install -y zip
- name: Install zip (macOS)
if: runner.os == 'macOS'
run: brew install zip
- name: Check
run: cargo check --features "${{ matrix.features }}"
- name: Test
run: cargo test --features "${{ matrix.features }}"
- name: Lint
run: cargo clippy --all-targets --features "${{ matrix.features }}" -- -D warnings
- name: Format
run: cargo fmt --all -- --check
- name: Build
run: cargo build --release --features "${{ matrix.features }}"
- name: Set Target Triple (Linux and macOS)
if: runner.os != 'Windows'
shell: bash
run: |
if [ "${{ runner.os }}" == "Linux" ]; then
echo "TARGET_TRIPLE=x86_64-unknown-linux-gnu" >> $GITHUB_ENV
elif [ "${{ runner.os }}" == "macOS" ]; then
echo "TARGET_TRIPLE=x86_64-apple-darwin" >> $GITHUB_ENV
fi
- name: Set Target Triple (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
echo "TARGET_TRIPLE=x86_64-pc-windows-msvc" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: Set Artifact Name (Linux and macOS)
if: runner.os != 'Windows'
shell: bash
run: |
if [ "${{ matrix.features }}" != "" ]; then
if [ "${{ matrix.features }}" == "zip" ]; then
FEATURE_NAME="full"
else
FEATURE_NAME="${{ matrix.features }}"
fi
ARTIFACT_NAME="your_project_name-${{ env.TARGET_TRIPLE }}.${FEATURE_NAME}"
else
ARTIFACT_NAME="your_project_name-${{ env.TARGET_TRIPLE }}"
fi
echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> $GITHUB_ENV
- name: Set Artifact Name (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
if ($Env:matrix_features -ne "") {
if ($Env:matrix_features -eq "zip") {
$FEATURE_NAME = "full"
} else {
$FEATURE_NAME = $Env:matrix_features
}
$ARTIFACT_NAME = "your_project_name-$Env:TARGET_TRIPLE.$FEATURE_NAME"
} else {
$ARTIFACT_NAME = "your_project_name-$Env:TARGET_TRIPLE"
}
echo "ARTIFACT_NAME=$ARTIFACT_NAME" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: Create Zip Archive (Linux and macOS)
if: runner.os != 'Windows'
shell: bash
run: |
mkdir -p artifacts
zip -j "artifacts/${{ env.ARTIFACT_NAME }}.zip" "target/release/your_executable_name"
- name: Create Zip Archive (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
New-Item -ItemType Directory -Path artifacts
Compress-Archive -Path "target\release\your_executable_name.exe" -DestinationPath "artifacts\$($Env:ARTIFACT_NAME).zip"
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}.zip
path: artifacts/${{ env.ARTIFACT_NAME }}.zip