-
Notifications
You must be signed in to change notification settings - Fork 225
167 lines (164 loc) · 6.8 KB
/
test-rust.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
name: test-rust
on:
# Currently we only run this as `workflow_call`, since `tests.yaml` always calls it.
workflow_call:
inputs:
os:
type: string
required: true
target:
type: string
required: true
features:
type: string
required: true
nightly:
description: "Whether to run extra tests (this is not nightly rust)"
type: boolean
default: false
env:
CARGO_TERM_COLOR: always
CLICOLOR_FORCE: 1
# This used to reduce the size of the cargo cache by ~25%. It's not as
# effective as it once was, as explained in
# https://github.com/PRQL/prql/pull/2797
RUSTFLAGS: "-C debuginfo=0"
RUSTDOCFLAGS: "-Dwarnings"
jobs:
test-rust:
runs-on: ${{ inputs.os }}
steps:
- name: 📂 Checkout code
uses: actions/checkout@v4
with:
fetch-tags: true
- name: Run docker compose
# This can go early because the DBs take a few seconds to start up.
if: ${{ contains(inputs.features, 'test-dbs-external') }}
run: docker compose up -d
working-directory: ./prqlc/prqlc/tests/integration/dbs
- if: ${{ contains(inputs.target, 'musl') }}
run: |
sudo apt-get update
sudo apt-get install -y musl-tools
- run: rustup target add ${{ inputs.target }}
- uses: baptiste0928/cargo-install@v3
with:
crate: wasm-bindgen-cli
if: inputs.target == 'wasm32-unknown-unknown'
- uses: baptiste0928/cargo-install@v3
with:
crate: cargo-insta
- uses: baptiste0928/cargo-install@v3
with:
crate: cargo-nextest
- run: ./.github/workflows/scripts/set_version.sh
shell: bash
- name: 💰 Cache
uses: Swatinem/rust-cache@v2
id: cache
with:
# We add the hash of the Cargo.lock file to the key, to prevent the
# gradual accumulation of disk space that comes from using previous
# caches. The rust cache is designed to remove old packages, but isn't
# that successful at it, and our current cache size at ~1.3GB is about
# as much as GHA can handle, such that if we hold old packages, it
# balloons to 2GB and fails. Some discussion at:
# https://github.com/Swatinem/rust-cache/issues/177
prefix-key: ${{ env.version }}-${{ hashFiles('Cargo.lock') }}
shared-key: rust-${{ inputs.target }}
# Don't save if empty features, because we run a test with empty
# features on linux, and don't want to save that instead of the one
# with all features. I tried including features in the key, but it
# contains a comma, which isn't allowed; a whole extra task to remove
# the comma seemed over the top.
save-if:
${{ github.ref == 'refs/heads/main' && inputs.features != '' }}
- uses: actions/setup-python@v5
# python isn't natively installed on macos-14, so we need to install it
if: ${{ inputs.os == 'macos-14' }}
with:
python-version: "3.11"
- name: Free up disk space
# https://github.com/actions/runner-images/issues/2840
run: ./.github/workflows/scripts/util_free_space.sh
# This takes ~3 minutes, so we'd really prefer not to run it on every
# PR. Trying to run it only when there is no cache hit. We may need to
# remove that condition and run it whenever we pull the docker images,
# or explore breaking up the tests more (though that's not easy to get
# savings on either). Ideally GH will allow for more disk space in the
# future... (deleting things doesn't actually remove the amount of stuff
# that GH needs to store, so it's purely performative!)
if:
${{ contains(inputs.features, 'test-dbs-external') &&
steps.cache.outputs.cache-hit == 'false' }}
# We split up the test compilation as recommended in
# https://matklad.github.io/2021/09/04/fast-rust-builds.html
- name: 🏭 Compile
uses: clechasseur/rs-cargo@v2
with:
command: test
args: >
--no-run --locked --target=${{ inputs.target }}
--no-default-features --features=${{ inputs.features }}
- name: Wait for database
uses: ifaxity/[email protected]
with:
resource: "tcp:1433 tcp:3306 tcp:5432 tcp:9004"
timeout: 60000
if: ${{ contains(inputs.features, 'test-dbs-external') }}
- name: 📋 Test
uses: clechasseur/rs-cargo@v2
with:
command: insta
# Here, we also add:
# - Unreferenced snapshots - `--unreferenced=auto` when testing on
# linux & with `test-dbs` feature.
# - Test runner - `--test-runner=nextest` when not targeting wasm32.
args: >
test --target=${{ inputs.target }} --no-default-features
--features=${{ inputs.features }} ${{ contains(inputs.features,
'test-dbs') && inputs.target == 'x86_64-unknown-linux-gnu' &&
'--unreferenced=auto' || '' }} ${{ inputs.target !=
'wasm32-unknown-unknown' && '--test-runner=nextest' || '' }}
- name: 📎 Clippy
uses: clechasseur/rs-cargo@v2
with:
command: clippy
# Note that `--all-targets` doesn't refer to targets like
# `wasm32-unknown-unknown`; it refers to lib / bin / tests etc.
#
args: >
--all-targets --target=${{ inputs.target }} --no-default-features
--features=${{ inputs.features }} -- -D warnings
- name: ⌨️ Fmt
uses: clechasseur/rs-cargo@v2
with:
command: fmt
args: --all --check
- name: 🗒️ Doc
# Only running on nightly, because of
# https://github.com/duckdb/duckdb-rs/issues/179#issuecomment-1710986020.
if:
inputs.nightly == 'true' && inputs.target != 'wasm32-unknown-unknown'
uses: clechasseur/rs-cargo@v2
with:
command: doc
# Only run with deps on nightly, since it's much slower, and so far™
# we haven't seen any errors.
args:
--target=${{ inputs.target }} --no-default-features --features=${{
inputs.features }} ${{ inputs.nightly != 'true' && '--no-deps' || ''
}}
- name: Build extra targets for cache
# When building the cache, we also run with `--all-targets` so that
# prqlc builds can use the same cache.
if:
${{ github.ref == 'refs/heads/main' && steps.cache.outputs.cache-hit
== 'false' }}
uses: clechasseur/rs-cargo@v2
with:
command: build
args:
--all-targets --target=${{ inputs.target }} --no-default-features
--features=${{ inputs.features }}