-
Notifications
You must be signed in to change notification settings - Fork 1
191 lines (165 loc) · 5.69 KB
/
build.yaml
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: Build
on:
#pull_request:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
env:
APP_NAME: cargo-appraiser
jobs:
build-linux:
runs-on: ubuntu-latest
strategy:
matrix:
target: [
"x86_64-unknown-linux-gnu",
"aarch64-unknown-linux-gnu",
"armv7-unknown-linux-gnueabihf"
]
steps:
# 1. Checkout the repository
- uses: actions/checkout@v4
# 2. Install Rust Toolchain
- name: Install Rust Toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
# 3. Install `cross`
- name: Install Cross
run: |
cargo install cross
# 4. Cache Cargo dependencies (optional but recommended)
- name: Cache Cargo Registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache Cargo Git
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-git-
# 5. Cache Cross Docker Image (optional but recommended)
- name: Cache Cross Docker Image
uses: actions/cache@v3
with:
path: ~/.cache/cross
key: ${{ runner.os }}-cross-${{ matrix.target }}
restore-keys: |
${{ runner.os }}-cross-
# 6. Build the project using `cross`
- name: Build with Cross
env:
RUSTFLAGS: "-Awarnings"
run: cross build --release --target ${{ matrix.target }} --bin ${{ env.APP_NAME }} --features vendored-openssl
# 7. Upload the build artifact
- name: Upload Build Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.APP_NAME }}-${{ matrix.target }}
path: target/${{ matrix.target }}/release/${{ env.APP_NAME }}
if-no-files-found: error
build-macos:
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-apple-darwin
runs-on: macos-14-large
- target: aarch64-apple-darwin
runs-on: macos-latest
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install and configure OpenSSL
run: |
# Install OpenSSL@3 using Homebrew
brew install openssl@3
# Set OpenSSL environment variables
echo "OPENSSL_DIR=$(brew --prefix openssl@3)" >> $GITHUB_ENV
echo "OPENSSL_INCLUDE_DIR=$(brew --prefix openssl@3)/include" >> $GITHUB_ENV
echo "OPENSSL_LIB_DIR=$(brew --prefix openssl@3)/lib" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=$(brew --prefix openssl@3)/lib/pkgconfig" >> $GITHUB_ENV
echo "$(brew --prefix openssl@3)/bin" >> $GITHUB_PATH
- name: Build macOS
uses: actions-rs/cargo@v1
env:
OPENSSL_DIR: ${{ env.OPENSSL_DIR }}
OPENSSL_INCLUDE_DIR: ${{ env.OPENSSL_INCLUDE_DIR }}
OPENSSL_LIB_DIR: ${{ env.OPENSSL_LIB_DIR }}
PKG_CONFIG_PATH: ${{ env.PKG_CONFIG_PATH }}
with:
command: build
args: --release --bin ${{ env.APP_NAME }} --target ${{ matrix.target }}
- name: Upload macOS artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.APP_NAME }}-${{ matrix.target }}
path: target/${{ matrix.target }}/release/${{ env.APP_NAME }}
if-no-files-found: error
build-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-pc-windows-msvc
- name: Build Windows
run: cargo build --release --bin ${{ env.APP_NAME }} --target x86_64-pc-windows-msvc
- name: Upload Windows artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.APP_NAME }}-x86_64-pc-windows-msvc
path: target/x86_64-pc-windows-msvc/release/${{ env.APP_NAME }}.exe
if-no-files-found: error
release:
needs: [build-linux, build-macos, build-windows]
runs-on: ubuntu-latest
env:
TARGETS: >-
x86_64-unknown-linux-gnu
aarch64-unknown-linux-gnu
x86_64-apple-darwin
aarch64-apple-darwin
x86_64-pc-windows-msvc
armv7-unknown-linux-gnueabihf
FILES: >-
cargo-appraiser-linux-amd64
cargo-appraiser-linux-arm64
cargo-appraiser-darwin-amd64
cargo-appraiser-darwin-arm64
cargo-appraiser-windows-amd64
cargo-appraiser-linux-armhf
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Rename and move artifacts
run: |
mkdir -p ./artifacts
targets=(${{ env.TARGETS }})
files=(${{ env.FILES }})
for i in "${!targets[@]}"; do
artifact_name="${{ env.APP_NAME }}-${targets[$i]}"
output_name="${files[$i]}"
if [[ "${targets[$i]}" == *"-windows-"* ]]; then
mv "$artifact_name/${{ env.APP_NAME }}.exe" "./artifacts/$output_name.exe"
else
mv "$artifact_name/${{ env.APP_NAME }}" "./artifacts/$output_name"
fi
done
- name: Release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
draft: false
fail_on_unmatched_files: true
files: ./artifacts/**