-
Notifications
You must be signed in to change notification settings - Fork 14
231 lines (210 loc) · 8.76 KB
/
ci.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
225
226
227
228
229
230
231
# This file incorporates work [0] covered by the following copyright and
# permission notice:
#
# Copyright 2019 The Fuchsia Authors.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# [0] https://github.com/google/async-backtrace/blob/main/.github/workflows/ci.yml
name: CI
on:
pull_request:
push:
branches:
- staging
- trying
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: -Dwarnings
# `CRATE_NIGHTLY_XXX` are flags that we add to `XXX` only on the nightly
# toolchain.
CRATE_NIGHTLY_RUSTFLAGS: -Zrandomize-layout
CRATE_NIGHTLY_MIRIFLAGS: "-Zmiri-disable-isolation -Zmiri-symbolic-alignment-check"
jobs:
build_test:
runs-on: ubuntu-latest
strategy:
matrix:
toolchain: [ "stable", "nightly" ]
target: [ "i686-unknown-linux-gnu", "x86_64-unknown-linux-gnu" ]
name: Build & Test (toolchain:${{ matrix.toolchain }}, target:${{ matrix.target }})
steps:
- uses: actions/checkout@v3
# We use toolchain descriptors ("msrv", "stable", and "nightly") in the
# matrix. This step converts the current descriptor to a particular
# toolchain version by looking up the corresponding key in `Cargo.toml`. It
# sets the `CRATE_TOOLCHAIN` environment variable for future steps to use.
#
# Note that all metadata is stored in the `Cargo.toml` at
# the repository root. `async-backtrace-attributes` is tested with the same versions,
# and we have another CI job (see below) that makes sure that the
# `package.rust_version` key in async-backtrace-attributes's `Cargo.toml` is the same
# as the one in async-backtrace's `Cargo.toml`. This key indicates the crate's
# MSRV, and if this check weren't present, it would be possible for
# async-backtrace-attributes to be published with an earlier MSRV than the one we test
# for in CI - and thus potentially an MSRV that async-backtrace-attributes isn't
# actually compatible with.
- name: Set toolchain version
run: |
set -e
# Usage: msrv <crate-name>
function msrv {
cargo metadata --format-version 1 | jq -r ".packages[] | select(.name == \"$1\").rust_version"
}
case ${{ matrix.toolchain }} in
msrv)
CRATE_TOOLCHAIN="$(msrv async-backtrace)"
;;
stable)
CRATE_TOOLCHAIN="stable"
;;
nightly)
CRATE_TOOLCHAIN="nightly"
;;
*)
echo 'Unrecognized toolchain: ${{ matrix.toolchain }}' | tee -a $GITHUB_STEP_SUMMARY >&2
exit 1
;;
esac
echo "Found that the '${{ matrix.toolchain }}' toolchain is $CRATE_TOOLCHAIN" | tee -a $GITHUB_STEP_SUMMARY
echo "CRATE_TOOLCHAIN=$CRATE_TOOLCHAIN" >> $GITHUB_ENV
- name: Configure environment variables
run: |
set -e
if [[ '${{ matrix.toolchain }}' == 'nightly' ]]; then
RUSTFLAGS="$RUSTFLAGS $CRATE_NIGHTLY_RUSTFLAGS"
MIRIFLAGS="$MIRIFLAGS $CRATE_NIGHTLY_MIRIFLAGS"
echo "Using nightly toolchain; setting RUSTFLAGS='$RUSTFLAGS' and MIRIFLAGS='$MIRIFLAGS'" | tee -a $GITHUB_STEP_SUMMARY
echo "RUSTFLAGS=$RUSTFLAGS" >> $GITHUB_ENV
echo "MIRIFLAGS=$MIRIFLAGS" >> $GITHUB_ENV
else
echo "Using non-nightly toolchain; not modifying RUSTFLAGS='$RUSTFLAGS' or MIRIFLAGS='$MIRIFLAGS'" | tee -a $GITHUB_STEP_SUMMARY
fi
- name: Install Rust with toolchain ${{ env.CRATE_TOOLCHAIN }} and target ${{ matrix.target }}
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.CRATE_TOOLCHAIN }}
target: ${{ matrix.target }}
# Only nightly has a working Miri, so we skip installing on all other
# toolchains. This expression is effectively a ternary expression -
# see [1] for details.
#
# [1]
# https://github.com/actions/runner/issues/409#issuecomment-752775072
components: clippy ${{ matrix.toolchain == 'nightly' && ', miri' || '' }}
- name: Rust Cache
uses: Swatinem/[email protected]
# When building tests for the i686 target, we need certain libraries which
# are not installed by default; `gcc-multilib` includes these libraries.
- name: Install gcc-multilib
run: |
sudo apt-get update
sudo apt-get install gcc-multilib
if: ${{ contains(matrix.target, 'i686') }}
- name: Cargo update
run: cargo +${{ env.CRATE_TOOLCHAIN }} update --verbose
- name: Check lib
run: cargo +${{ env.CRATE_TOOLCHAIN }} check --target ${{ matrix.target }} --lib --verbose
- name: Check extras
run: cargo +${{ env.CRATE_TOOLCHAIN }} check --target ${{ matrix.target }} --all-targets --verbose
- name: Test (doc)
run: cargo +${{ env.CRATE_TOOLCHAIN }} test --target ${{ matrix.target }} --verbose --doc
# Only run tests when targetting x86 (32- or 64-bit) - we're executing on
# x86_64, so we can't run tests for any non-x86 target.
if: ${{ matrix.toolchain == 'nightly' && (contains(matrix.target, 'x86_64') || contains(matrix.target, 'i686')) }}
- name: Test (integration)
run: cargo +${{ env.CRATE_TOOLCHAIN }} test --target ${{ matrix.target }} --verbose --tests
# Only run tests when targetting x86 (32- or 64-bit) - we're executing on
# x86_64, so we can't run tests for any non-x86 target.
if: ${{ (contains(matrix.target, 'x86_64') || contains(matrix.target, 'i686')) }}
- name: Test (loom)
run: cargo +${{ env.CRATE_TOOLCHAIN }} test --target ${{ matrix.target }} --verbose --release --tests
# Only run tests when targetting x86 (32- or 64-bit) - we're executing on
# x86_64, so we can't run tests for any non-x86 target.
if: ${{ (contains(matrix.target, 'x86_64') || contains(matrix.target, 'aarch64')) }}
env:
RUSTFLAGS: --cfg loom ${{ env.RUSTFLAGS }}
- name: Test (miri)
run: cargo +${{ env.CRATE_TOOLCHAIN }} miri test --target ${{ matrix.target }}
# Only nightly has a working Miri, so we skip installing on all other
# toolchains.
if: ${{ matrix.toolchain == 'nightly' }}
check_fmt:
runs-on: ubuntu-latest
name: cargo fmt
steps:
- uses: actions/checkout@v3
- name: Install Rust (nightly)
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
components: rustfmt
- name: "`cargo fmt --check`"
run: |
set -e
cargo fmt --check
check_clippy:
runs-on: ubuntu-latest
name: cargo clippy
steps:
- uses: actions/checkout@v3
- name: Install Rust (nightly)
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
components: clippy
- name: Rust Cache
uses: Swatinem/[email protected]
- name: "`cargo clippy`"
run: |
set -e
cargo clippy --all-targets
check_readme:
runs-on: ubuntu-latest
name: Check README is correctly generated.
steps:
- uses: actions/checkout@v3
- name: Rust Cache
uses: Swatinem/[email protected]
- uses: extractions/setup-just@v1
- name: Check README matches
run: |
set -e
cargo install cargo-readme --version 3.2.0
diff <(just generate-readme) README.md
exit $?
ci-success:
name: ci
if: ${{ success() }}
needs:
- build_test
- check_fmt
- check_clippy
- check_readme
runs-on: ubuntu-latest
steps:
- name: CI succeeded
run: exit 0