Skip to content

Commit c0cdf20

Browse files
chore(ci): extract unit tests into reusable workflow (#25247)
* chore(ci): extract unit tests into reusable workflow * chore(ci): fix component-validation input and add OS-based FEATURES default * chore(ci): pass Datadog credentials into reusable unit-tests workflow
1 parent cfb942b commit c0cdf20

3 files changed

Lines changed: 125 additions & 24 deletions

File tree

.github/workflows/changes.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ jobs:
280280
- ".github/workflows/changes.yml"
281281
test-yml:
282282
- ".github/workflows/test.yml"
283+
- ".github/workflows/unit-tests.yml"
283284
- ".github/workflows/changes.yml"
284285
integration-yml:
285286
- ".github/workflows/integration.yml"

.github/workflows/test.yml

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,31 +56,13 @@ jobs:
5656
- run: make check-clippy
5757

5858
test:
59-
name: Unit and Component Validation tests - x86_64-unknown-linux-gnu
60-
runs-on: ubuntu-24.04-8core
61-
if: ${{ needs.changes.outputs.source == 'true' || needs.changes.outputs.test-yml == 'true' }}
6259
needs: changes
63-
steps:
64-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
65-
- uses: ./.github/actions/setup
66-
with:
67-
rust: true
68-
cargo-nextest: true
69-
datadog-ci: true
70-
protoc: true
71-
libsasl2: true
72-
- name: Unit Test
73-
run: make test
74-
env:
75-
CARGO_BUILD_JOBS: 5
76-
77-
# Validates components for adherence to the Component Specification
78-
- name: Check Component Spec
79-
run: make test-component-validation
80-
81-
- name: Upload test results
82-
run: scripts/upload-test-results.sh
83-
if: always()
60+
if: ${{ needs.changes.outputs.source == 'true' || needs.changes.outputs.test-yml == 'true' }}
61+
uses: ./.github/workflows/unit-tests.yml
62+
with:
63+
default: true
64+
component-validation: true
65+
secrets: inherit
8466

8567
check-scripts:
8668
name: Check scripts

.github/workflows/unit-tests.yml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Reusable Workflow: Tests
2+
#
3+
# Runs test suites via the Makefile. By default runs unit tests and component
4+
# validation. Callers can enable additional suites (CLI, Vector API, behavior)
5+
# via boolean inputs.
6+
#
7+
# When `default` is true, all nextest-based suites run in a single `make test`
8+
# invocation with the relevant features enabled. When `default` is false, only
9+
# the explicitly enabled suites run, using a nextest filter expression to
10+
# select the matching tests.
11+
12+
name: Tests
13+
14+
on:
15+
workflow_call:
16+
inputs:
17+
ref:
18+
description: "Git ref to checkout"
19+
required: false
20+
type: string
21+
default:
22+
description: "Run the full default unit test suite (--workspace with default features)"
23+
required: true
24+
type: boolean
25+
component-validation:
26+
description: "Include component validation tests"
27+
required: false
28+
type: boolean
29+
default: true
30+
cli:
31+
description: "Include CLI tests"
32+
required: false
33+
type: boolean
34+
default: false
35+
vector-api:
36+
description: "Include Vector API tests"
37+
required: false
38+
type: boolean
39+
default: false
40+
behavior:
41+
description: "Include behavior tests"
42+
required: false
43+
type: boolean
44+
default: false
45+
46+
permissions:
47+
contents: read
48+
49+
env:
50+
CARGO_INCREMENTAL: "0"
51+
CI: true
52+
DD_ENV: "ci"
53+
DD_API_KEY: ${{ secrets.DD_API_KEY }}
54+
55+
jobs:
56+
tests:
57+
name: Tests
58+
runs-on: ubuntu-24.04-8core
59+
steps:
60+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
61+
with:
62+
ref: ${{ inputs.ref }}
63+
64+
- uses: ./.github/actions/setup
65+
with:
66+
rust: true
67+
cargo-nextest: true
68+
datadog-ci: true
69+
protoc: true
70+
libsasl2: true
71+
72+
- name: Run tests
73+
run: |
74+
add_suite() {
75+
local enabled="$1" feature="$2" filter="$3"
76+
[[ "${enabled}" != "true" ]] && return
77+
FEATURES="${FEATURES:+$FEATURES,}${feature}"
78+
if [[ "${{ inputs.default }}" != "true" ]]; then
79+
SCOPE="${SCOPE:+$SCOPE | }${filter}"
80+
fi
81+
}
82+
83+
# Mirror the Makefile's OS-based default: `default-msvc` on Windows,
84+
# `default` elsewhere. Keep in sync with the FEATURES defaults in Makefile.
85+
if [[ "${RUNNER_OS}" == "Windows" ]]; then
86+
DEFAULT_FEATURES="default-msvc"
87+
else
88+
DEFAULT_FEATURES="default"
89+
fi
90+
91+
if [[ "${{ inputs.default }}" == "true" ]]; then
92+
FEATURES="${DEFAULT_FEATURES}"
93+
else
94+
FEATURES=""
95+
fi
96+
97+
add_suite "${{ inputs.component-validation }}" "component-validation-tests" "test(components::validation::tests)"
98+
add_suite "${{ inputs.cli }}" "cli-tests" "package(vector) & binary(=integration)"
99+
add_suite "${{ inputs.vector-api }}" "vector-api-tests" "binary(=vector_api)"
100+
101+
# Skip `make test` entirely if no nextest-based suite was selected
102+
# (e.g. behavior-only runs). Running `make test` with empty FEATURES
103+
# would otherwise execute the workspace-wide suite.
104+
if [[ "${{ inputs.default }}" == "true" ]]; then
105+
make test FEATURES="${FEATURES}"
106+
elif [[ -n "${SCOPE}" ]]; then
107+
make test FEATURES="${FEATURES}" SCOPE="-E '${SCOPE}'"
108+
else
109+
echo "No nextest suites selected; skipping 'make test'"
110+
fi
111+
112+
- name: Behavior tests
113+
if: ${{ inputs.behavior }}
114+
run: make test-behavior
115+
116+
- name: Upload test results to Datadog
117+
if: ${{ always() }}
118+
run: scripts/upload-test-results.sh

0 commit comments

Comments
 (0)