-
Notifications
You must be signed in to change notification settings - Fork 2.1k
146 lines (130 loc) · 4.73 KB
/
unit-tests.yml
File metadata and controls
146 lines (130 loc) · 4.73 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
# Reusable Workflow: Tests
#
# Runs test suites via the Makefile. By default runs unit tests and component
# validation. Callers can enable additional suites (CLI, Vector API, behavior)
# via boolean inputs.
#
# With coverage: false (default), plain cargo-nextest; uploads test results to Datadog.
# With coverage: true, cargo-llvm-cov (COVERAGE=true); uploads an lcov artifact named "coverage-unit".
#
# When `default` is true (the default), all nextest-based suites run in a
# single `make test` invocation with the relevant features enabled. When
# `default` is false, only the explicitly enabled suites run, using a nextest
# filter expression to select the matching tests.
name: Tests
on:
workflow_call:
inputs:
ref:
description: "Git ref to checkout"
required: false
type: string
coverage:
description: "Collect code coverage (sets COVERAGE=true for make targets)"
required: false
type: boolean
default: false
default:
description: "Run the full default unit test suite (--workspace with default features)"
required: true
type: boolean
component-validation:
description: "Include component validation tests"
required: false
type: boolean
default: true
cli:
description: "Include CLI tests"
required: false
type: boolean
default: false
vector-api:
description: "Include Vector API tests"
required: false
type: boolean
default: false
behavior:
description: "Include behavior tests (cargo run based, no coverage)"
required: false
type: boolean
default: false
permissions:
contents: read
env:
CI: true
DD_ENV: "ci"
jobs:
tests:
name: Tests
runs-on: ubuntu-24.04-8core
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ inputs.ref }}
- uses: ./.github/actions/dd-token
- uses: ./.github/actions/setup
with:
rust: true
cargo-nextest: true
cargo-llvm-cov: ${{ inputs.coverage }}
datadog-ci: ${{ !inputs.coverage }}
protoc: true
libsasl2: true
- name: Run tests
run: |
add_suite() {
local enabled="$1" feature="$2" filter="$3"
[[ "${enabled}" != "true" ]] && return
FEATURES="${FEATURES:+$FEATURES,}${feature}"
if [[ "${{ inputs.default }}" != "true" ]]; then
SCOPE="${SCOPE:+$SCOPE | }${filter}"
fi
}
# Mirror the Makefile's OS-based default: `default-msvc` on Windows,
# `default` elsewhere. Keep in sync with the FEATURES defaults in Makefile.
if [[ "${RUNNER_OS}" == "Windows" ]]; then
DEFAULT_FEATURES="default-msvc"
else
DEFAULT_FEATURES="default"
fi
if [[ "${{ inputs.default }}" == "true" ]]; then
FEATURES="${DEFAULT_FEATURES}"
else
FEATURES=""
fi
add_suite "${{ inputs.component-validation }}" "component-validation-tests" "test(components::validation::tests)"
add_suite "${{ inputs.cli }}" "cli-tests" "package(vector) & binary(=integration)"
add_suite "${{ inputs.vector-api }}" "vector-api-tests" "binary(=vector_api)"
# Skip `make test` entirely if no nextest-based suite was selected
# (e.g. behavior-only runs). Running `make test` with empty FEATURES
# would otherwise execute the workspace-wide suite.
if [[ "${{ inputs.default }}" == "true" ]]; then
make test FEATURES="${FEATURES}"
elif [[ -n "${SCOPE}" ]]; then
make test FEATURES="${FEATURES}" SCOPE="-E '${SCOPE}'"
else
echo "No nextest suites selected; skipping 'make test'"
fi
env:
COVERAGE: ${{ inputs.coverage }}
- name: Behavior tests
if: ${{ inputs.behavior }}
run: make test-behavior
- name: Upload test results to Datadog
if: ${{ !inputs.coverage && always() }}
run: scripts/upload-test-results.sh
- name: Generate lcov report
if: ${{ inputs.coverage }}
run: |
make coverage-report
# Normalize absolute source paths to relative so they merge cleanly with
# coverage from the containerized integration tests (which use SF:src/...).
sed -i "s|SF:$(pwd)/|SF:|g" lcov.info
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
if: ${{ inputs.coverage }}
with:
name: coverage-unit
path: lcov.info