-
Notifications
You must be signed in to change notification settings - Fork 10
224 lines (195 loc) · 7.11 KB
/
build-and-test.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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# Taken from https://github.com/prefix-dev/pixi/blob/c32351a/.github/workflows/rust.yml
name: Build and Test Static Binary
on:
push:
tags:
- "v*"
branches:
- main
workflow_dispatch:
pull_request:
permissions:
contents: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
RUST_LOG: info
RUST_BACKTRACE: 1
RUSTFLAGS: "-D warnings"
CARGO_TERM_COLOR: always
CICD_INTERMEDIATES_DIR: "_cicd-intermediates"
TEST_FEATURES: "slow_integration_tests"
XDG_CACHE_HOME: ${{ github.workspace }}/.cache
jobs:
crate_metadata:
name: Extract crate metadata
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Extract crate information
id: crate_metadata
run: |
cargo metadata --manifest-path yen-rs/Cargo.toml --no-deps --format-version 1 | jq -r '"name=" + .packages[0].name' | tee -a $GITHUB_OUTPUT
cargo metadata --manifest-path yen-rs/Cargo.toml --no-deps --format-version 1 | jq -r '"version=" + .packages[0].version' | tee -a $GITHUB_OUTPUT
cargo metadata --manifest-path yen-rs/Cargo.toml --no-deps --format-version 1 | jq -r '"maintainer=" + .packages[0].authors[0]' | tee -a $GITHUB_OUTPUT
cargo metadata --manifest-path yen-rs/Cargo.toml --no-deps --format-version 1 | jq -r '"homepage=" + .packages[0].homepage' | tee -a $GITHUB_OUTPUT
outputs:
name: ${{ steps.crate_metadata.outputs.name }}
version: ${{ steps.crate_metadata.outputs.version }}
maintainer: ${{ steps.crate_metadata.outputs.maintainer }}
homepage: ${{ steps.crate_metadata.outputs.homepage }}
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
needs: [crate_metadata]
strategy:
fail-fast: false
matrix:
include:
- {
name: "Linux-x86_64",
target: x86_64-unknown-linux-musl,
os: ubuntu-20.04,
}
- {
name: "Linux-aarch64",
target: aarch64-unknown-linux-musl,
os: ubuntu-latest,
}
- {
name: "Linux-x86",
target: i686-unknown-linux-musl,
os: ubuntu-latest,
}
- {
name: "macOS-x86_64",
target: x86_64-apple-darwin,
os: macOS-latest,
}
- {
name: "macOS-aarch64",
target: aarch64-apple-darwin,
os: macOS-latest,
}
- {
name: "windows-x86_64",
target: x86_64-pc-windows-msvc,
os: windows-latest,
}
- {
name: "windows-x86",
target: i686-pc-windows-msvc,
os: windows-latest,
}
env:
#
# These are some environment variables that configure the build so that the binary size is reduced.
# Inspiration was taken from this blog: https://arusahni.net/blog/2020/03/optimizing-rust-binary-size.html
#
# Enable Link Time Optimization (LTO) for our release builds. This increases link time but drastically reduces
# binary size.
CARGO_PROFILE_RELEASE_LTO: true
# Use a single code gen unit, this effectively disables parallel linking but ensures that everything is linked
# together in a single unit which reduces the file-size at the cost of link time.
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 1
# Optimize the binary for size. This reduces the filesize at the cost of a slower binary.
CARGO_PROFILE_OPT_LEVEL: s
steps:
- name: Checkout source code
uses: actions/checkout@v3
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: ${{ matrix.target }}
cache: false
- uses: taiki-e/setup-cross-toolchain-action@v1
with:
target: ${{ matrix.target }}
- name: Use static CRT
shell: bash
run: echo "RUSTFLAGS=${RUSTFLAGS} -C target-feature=+crt-static" >> "${GITHUB_ENV}"
- name: Set release specific compilation flags
if: steps.is-release.outputs.IS_RELEASE
shell: bash
run: |
echo "CARGO_PROFILE_RELEASE_LTO=true" >> $GITHUB_ENV
echo "CARGO_PROFILE_RELEASE_STRIP=true" >> $GITHUB_ENV
- uses: Swatinem/rust-cache@v2
- name: Ensure cache directory exists
shell: bash
if: matrix.os == 'ubuntu-20.04' && matrix.use-cross
run: |
mkdir -p ${XDG_CACHE_HOME}
- name: Show version information (Rust, cargo, GCC)
shell: bash
run: |
gcc --version || true
rustup -V
rustup toolchain list
cargo -V
rustc -V
- name: Check for release
id: is-release
shell: bash
run: |
unset IS_RELEASE ; if [[ $GITHUB_REF =~ ^refs/tags/v[0-9].* ]]; then IS_RELEASE='true' ; fi
echo "IS_RELEASE=${IS_RELEASE}" >> $GITHUB_OUTPUT
- name: Build
run: >
cargo build
--locked
--release
--manifest-path yen-rs/Cargo.toml
${{ steps.build-options.outputs.CARGO_BUILD_OPTIONS}}
- name: Set binary name & path
id: bin
shell: bash
run: |
EXE_SUFFIX=""
case ${{ matrix.target }} in
*-pc-windows-*) EXE_SUFFIX=".exe" ;;
esac;
# Setup paths
BIN_NAME="${{ needs.crate_metadata.outputs.name }}"
BIN_PATH="yen-rs/target/${{ matrix.target }}/release/${BIN_NAME}"
mv "$BIN_PATH${EXE_SUFFIX}" "$BIN_PATH-${{matrix.target}}${EXE_SUFFIX}"
BIN_PATH="$BIN_PATH-${{matrix.target}}${EXE_SUFFIX}"
# Let subsequent steps know where to find the binary
echo "BIN_PATH=${BIN_PATH}" >> $GITHUB_OUTPUT
echo "BIN_NAME=${BIN_NAME}" >> $GITHUB_OUTPUT
- name: Run the binary
shell: bash
run: |
${{ steps.bin.outputs.BIN_PATH }} list &>> $GITHUB_STEP_SUMMARY
- name: Install linux dependencies
if: matrix.os == 'ubuntu-latest'
run: |
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install libc6:i386
- name: Run tests
shell: bash
run: |
python -m venv venv
if [ -d ./venv/bin ]; then VENV_BIN_PATH=./venv/bin; fi
if [ -d ./venv/Scripts ]; then VENV_BIN_PATH=./venv/Scripts; fi
${VENV_BIN_PATH}/pip install -r requirements-dev.txt
YEN_RUST_PATH=${{ steps.bin.outputs.BIN_PATH }} ${VENV_BIN_PATH}/pytest
- name: "Artifact upload: binary"
uses: actions/upload-artifact@master
with:
name: yen-${{ matrix.target }}
path: ${{ steps.bin.outputs.BIN_PATH }}
- name: Publish packages
uses: softprops/action-gh-release@v1
if: steps.is-release.outputs.IS_RELEASE
with:
draft: true
files: |
${{ steps.bin.outputs.BIN_PATH }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}