-
Notifications
You must be signed in to change notification settings - Fork 20
288 lines (281 loc) · 12.3 KB
/
test.yml
File metadata and controls
288 lines (281 loc) · 12.3 KB
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
name: Test
on:
pull_request:
types: ['opened', 'edited', 'reopened', 'synchronize']
branches-ignore:
- "v[0-9]+.[0-9]+.[0-9]+.[0-9]+"
- release
push:
branches:
- main
env:
CARGO_TERM_COLOR: always
RUST_VERSION: 1.84.1
jobs:
setup:
runs-on: ubuntu-latest
outputs:
packages-count: ${{ steps.set-packages.outputs.packages-count }}
packages: ${{ steps.set-packages.outputs.packages }}
crashtracker-feature: ${{ steps.set-packages.outputs.crashtracker-feature }}
run-test-spawn: ${{ steps.set-packages.outputs.run-test-spawn }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
with:
fetch-depth: 0
- name: Get changed crates
id: changed-crates
uses: ./.github/actions/changed-crates
- name: Set unit test packages
id: set-packages
env:
CHANGED_CRATES_STATUS: ${{ steps.changed-crates.outputs.status }}
CHANGED_CRATES_COUNT: ${{ steps.changed-crates.outputs.crates_count }}
AFFECTED_CRATES: ${{ steps.changed-crates.outputs.affected_crates }}
run: |
if [[ "$CHANGED_CRATES_STATUS" == "skipped" ]]; then
COUNT="1"
PACKAGES=""
CRASHTRACKER_FEATURE="--features libdd-crashtracker/generate-unit-test-files"
RUN_TEST_SPAWN="true"
elif [[ "$CHANGED_CRATES_COUNT" == "0" ]]; then
COUNT="0"
PACKAGES=""
CRASHTRACKER_FEATURE=""
RUN_TEST_SPAWN="false"
else
UNIT_CRATES=$(echo "$AFFECTED_CRATES" | jq '[.[] | select(. != "builder")]')
COUNT=$(echo "$UNIT_CRATES" | jq 'length')
PACKAGES=$(echo "$UNIT_CRATES" | jq -r 'map("-p " + .) | join(" ")')
if echo "$UNIT_CRATES" | jq -e 'any(. == "libdd-crashtracker")' > /dev/null; then
CRASHTRACKER_FEATURE="--features libdd-crashtracker/generate-unit-test-files"
else
CRASHTRACKER_FEATURE=""
fi
if echo "$UNIT_CRATES" | jq -e 'any(. == "test_spawn_from_lib")' > /dev/null; then
RUN_TEST_SPAWN="true"
else
RUN_TEST_SPAWN="false"
fi
fi
{
echo "packages-count=$COUNT"
echo "packages=$PACKAGES"
echo "crashtracker-feature=$CRASHTRACKER_FEATURE"
echo "run-test-spawn=$RUN_TEST_SPAWN"
} >> $GITHUB_OUTPUT
test:
name: "cargo test #${{ matrix.platform }} ${{ matrix.rust_version }}"
needs: setup
if: needs.setup.outputs.packages-count != '0'
runs-on: ${{ matrix.platform }}
permissions:
checks: write
contents: read
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
PACKAGES: ${{ needs.setup.outputs.packages }}
CRASHTRACKER_FEATURE: ${{ needs.setup.outputs.crashtracker-feature }}
TRACING_CRATES: "libdd-data-pipeline libdd-trace-utils datadog-tracer-flare"
strategy:
matrix:
platform: [windows-latest, ubuntu-latest, macos-15]
rust_version: [""]
include:
- platform: "ubuntu-latest"
rust_version: "${RUST_VERSION}"
fail-fast: false
steps:
- name: Free Disk Space (Ubuntu only)
if: runner.os == 'Linux' && matrix.platform == 'ubuntu-latest'
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # 1.3.1
with:
tool-cache: false
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: false
swap-storage: true
- name: Checkout sources
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
- name: Install Rust ${{ matrix.rust_version }}
if: matrix.rust_version != ''
run: rustup install ${{ matrix.rust_version }} && rustup default ${{ matrix.rust_version }}
- id: rust-version
# On Windows run happens in a PowerShell, so start bash explicitly
run: bash -c 'echo "version=$(rustc --version)" >> $GITHUB_OUTPUT'
- name: Install cargo nextest
uses: taiki-e/install-action@2c41309d51ede152b6f2ee6bf3b71e6dc9a8b7df # 2.49.27
with:
tool: nextest@0.9.96
- name: Cache [rust]
uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # 2.8.1
with:
cache-targets: true # cache build artifacts
cache-bin: true # cache the ~/.cargo/bin directory
- name: "Remove nextest CI report"
shell: bash
run: rm -rf target/nextest/ci/junit.xml
- name: "[${{ steps.rust-version.outputs.version}}] cargo build"
shell: bash
run: |
if [[ -z "$PACKAGES" ]]; then
cargo build --workspace --exclude builder --verbose
else
# word splitting on $PACKAGES is intentional
# shellcheck disable=SC2086
cargo build $PACKAGES --verbose
fi
- name: "[${{ steps.rust-version.outputs.version}}] cargo test (doc) and cargo nextest run"
shell: bash
# Run doc tests with cargo test and run tests with nextest and generate junit.xml
run: |
if [[ -z "$PACKAGES" ]]; then
# shellcheck disable=SC2086
cargo test --workspace $CRASHTRACKER_FEATURE --exclude builder --doc --verbose
# shellcheck disable=SC2086
cargo nextest run --workspace $CRASHTRACKER_FEATURE --exclude builder --profile ci --verbose -E '!test(tracing_integration_tests::)'
else
# shellcheck disable=SC2086
cargo test $PACKAGES $CRASHTRACKER_FEATURE --doc --verbose
# shellcheck disable=SC2086
cargo nextest run $PACKAGES $CRASHTRACKER_FEATURE --profile ci --verbose -E '!test(tracing_integration_tests::)'
fi
env:
RUST_BACKTRACE: full
- name: "[${{ steps.rust-version.outputs.version}}] Tracing integration tests"
if: runner.os == 'Linux'
shell: bash
run: |
if [[ -z "$PACKAGES" ]]; then
# shellcheck disable=SC2086
for crate in $TRACING_CRATES; do
PACKAGES="$PACKAGES -p $crate"
done
cargo nextest run $PACKAGES --profile ci --test-threads=1 --verbose -E 'test(tracing_integration_tests::)'
else
TRACING_PACKAGES=""
for crate in $TRACING_CRATES; do
if echo "$PACKAGES" | grep -qw -- "-p $crate"; then
TRACING_PACKAGES="$TRACING_PACKAGES -p $crate"
fi
done
if [[ -z "$TRACING_PACKAGES" ]]; then
echo "No tracing integration test crates found in PACKAGES, skipping."
else
# shellcheck disable=SC2086
cargo nextest run $TRACING_PACKAGES --profile ci --test-threads=1 --verbose -E 'test(tracing_integration_tests::)'
fi
fi
env:
RUST_BACKTRACE: full
- name: "[${{ steps.rust-version.outputs.version}}] RUSTFLAGS=\"-C prefer-dynamic\" cargo nextest run --package test_spawn_from_lib"
if: needs.setup.outputs.run-test-spawn == 'true'
shell: bash
run: cargo nextest run --package test_spawn_from_lib --features prefer-dynamic -E '!test(tracing_integration_tests::)'
env:
RUSTFLAGS: "-C prefer-dynamic"
RUST_BACKTRACE: full
- name: Add file attributes to JUnit XML
if: success() || failure()
shell: bash
run: cargo run --bin add_junit_file_attributes -- target/nextest/ci/junit.xml
- name: Report Test Results
if: success() || failure()
uses: mikepenz/action-junit-report@db71d41eb79864e25ab0337e395c352e84523afe # 4.3.1
with:
report_paths: "target/nextest/ci/junit.xml"
check_name: "[${{ matrix.platform }}:${{ matrix.rust_version }}] test report"
include_passed: true
- name: Upload test results to Datadog
if: success() || failure()
shell: bash
run: |
# Download datadog-ci binary
if [ "${{ runner.os }}" == "Linux" ]; then
URL="https://github.com/DataDog/datadog-ci/releases/download/v4.2.2/datadog-ci_linux-x64"
OUTPUT="datadog-ci"
CHECKSUM_CMD="sha256sum"
EXPECTED_CHECKSUM="3e1e9649d15d3feacced89ec90de66151046a58c7844217e4112362ad8dbf8d1"
elif [ "${{ runner.os }}" == "Windows" ]; then
URL="https://github.com/DataDog/datadog-ci/releases/download/v4.2.2/datadog-ci_win-x64"
OUTPUT="datadog-ci.exe"
CHECKSUM_CMD="sha256sum"
EXPECTED_CHECKSUM="13313279cb884fe098e2f80ca21d23e67b78a090a12e891e8e35be653ee2bbd0"
elif [ "${{ runner.os }}" == "macOS" ]; then
URL="https://github.com/DataDog/datadog-ci/releases/download/v4.2.2/datadog-ci_darwin-x64"
OUTPUT="datadog-ci"
CHECKSUM_CMD="shasum -a 256"
EXPECTED_CHECKSUM="071a6140b17438b3f9dd6c65da48b48ea03fc310034fa624ce874fdb6c325da4"
fi
echo "Downloading datadog-ci from $URL"
curl -L --fail --retry 3 -o "$OUTPUT" "$URL"
chmod +x "$OUTPUT"
# Verify checksum
ACTUAL_CHECKSUM=$($CHECKSUM_CMD "$OUTPUT" | cut -d' ' -f1)
echo "Expected checksum: $EXPECTED_CHECKSUM"
echo "Actual checksum: $ACTUAL_CHECKSUM"
if [ "$ACTUAL_CHECKSUM" != "$EXPECTED_CHECKSUM" ]; then
echo "Checksum verification failed!"
exit 1
fi
echo "Checksum verification passed"
# Upload test results
./"$OUTPUT" junit upload \
--service libdatadog \
--env ci \
--logs \
--tags rustc:${{ matrix.rust_version }},arch:${{ runner.arch }},os:${{ runner.os }},platform:${{ matrix.platform }} \
target/nextest/ci/junit.xml
env:
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
cross-centos7:
name: build and test using cross - on centos7
needs: setup
if: needs.setup.outputs.packages-count != '0'
runs-on: ubuntu-latest
env:
PACKAGES: ${{ needs.setup.outputs.packages }}
CRASHTRACKER_FEATURE: ${{ needs.setup.outputs.crashtracker-feature }}
concurrency:
group: ci-${{ github.ref }}-cross-centos7
cancel-in-progress: true
steps:
- name: Free Disk Space
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # 1.3.1
with:
tool-cache: true
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: true
swap-storage: true
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
- name: Cache [rust]
uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # 2.8.1
with:
cache-targets: true # cache build artifacts
cache-bin: true # cache the ~/.cargo/bin directory
- run: cargo install cross || true
- name: cross build and test
run: |
if [[ -z "$PACKAGES" ]]; then
cross build --workspace --target x86_64-unknown-linux-gnu --exclude builder
# shellcheck disable=SC2086
cross test --workspace $CRASHTRACKER_FEATURE --target x86_64-unknown-linux-gnu --exclude builder -- --skip "::single_threaded_tests::" --skip "tracing_integration_tests::"
# shellcheck disable=SC2086
cross test --workspace $CRASHTRACKER_FEATURE --target x86_64-unknown-linux-gnu --exclude builder --exclude bin_tests -- --skip "::tests::" --skip "::api_tests::" --test-threads 1 --skip "tracing_integration_tests::"
else
# shellcheck disable=SC2086
cross build $PACKAGES --target x86_64-unknown-linux-gnu
# shellcheck disable=SC2086
cross test $PACKAGES $CRASHTRACKER_FEATURE --target x86_64-unknown-linux-gnu -- --skip "::single_threaded_tests::" --skip "tracing_integration_tests::"
# Remove bin_tests from packages for the second test run, as it is excluded in workspace mode too
PACKAGES_NO_BIN_TESTS=$(echo "$PACKAGES" | sed 's/-p bin_tests//g' | xargs)
# shellcheck disable=SC2086
cross test $PACKAGES_NO_BIN_TESTS $CRASHTRACKER_FEATURE --target x86_64-unknown-linux-gnu -- --skip "::tests::" --skip "::api_tests::" --test-threads 1 --skip "tracing_integration_tests::"
fi