|
| 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