Repository navigation
107 lines (95 loc) · 4.06 KB
/
Copy pathtest_rust.yaml
File metadata and controls
107 lines (95 loc) · 4.06 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
name: test-rust
on:
workflow_call:
permissions:
contents: read
jobs:
find_rust_tests:
runs-on: ubuntu-24.04
outputs:
RUST_TASKS: ${{ steps.lsgrep.outputs.RUST_TASKS }}
# [{ "kind": "lib" | "test" | "bin", "name": "test_eventbus" }, ...]
RUST_TEST_TASKS: ${{ steps.lsgrep.outputs.RUST_TEST_TASKS }}
# [{ "kind": "test", "name": "test_eventbus" }, ...]
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- id: lsgrep
run: |
RUST_LIB_TASKS="$(jq -cn '[{kind: "lib", name: "lib"}]')"
RUST_TEST_TASKS="$(
find abxbus-rust/tests -maxdepth 1 -type f -name '*.rs' \
| sort \
| sed 's|^abxbus-rust/tests/||' \
| sed 's|\.rs$||' \
| jq -R -s -c 'split("\n")[:-1] | map({kind: "test", name: .})'
)"
RUST_BIN_TASKS="$(
(
if [[ -d abxbus-rust/src/bin ]]; then
find abxbus-rust/src/bin -maxdepth 1 -type f -name '*.rs' | sort
fi
) \
| sed 's|^abxbus-rust/src/bin/||' \
| sed 's|\.rs$||' \
| jq -R -s -c 'split("\n")[:-1] | map({kind: "bin", name: .})'
)"
RUST_TASKS="$(jq -cn --argjson lib "$RUST_LIB_TASKS" --argjson tests "$RUST_TEST_TASKS" --argjson bins "$RUST_BIN_TASKS" '$lib + $tests + $bins')"
echo "RUST_TEST_TASKS=${RUST_TEST_TASKS}" >> "$GITHUB_OUTPUT"
echo "RUST_TASKS=${RUST_TASKS}" >> "$GITHUB_OUTPUT"
echo "$RUST_TASKS"
- name: Check that at least one test file is found
run: |
if [[ -z "${{ steps.lsgrep.outputs.RUST_TEST_TASKS }}" || "${{ steps.lsgrep.outputs.RUST_TEST_TASKS }}" == "[]" ]]; then
echo "Failed to find any *.rs files in abxbus-rust/tests/ folder!" > /dev/stderr
exit 1
fi
tests:
needs:
- find_rust_tests
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
task: ${{ fromJson(needs.find_rust_tests.outputs.RUST_TASKS || '[{"kind":"error","name":"FAILED_TO_DISCOVER_TASKS"}]') }}
# autodiscovers files in abxbus-rust/tests/*.rs and abxbus-rust/src/bin/*.rs
# - { kind: "lib", name: "lib" }
# - { kind: "test", name: "test_eventbus" }
# - { kind: "bin", name: "abxbus-rust-roundtrip" }
# ... and more
name: rust-${{ matrix.task.kind }}-${{ matrix.task.name }}
timeout-minutes: 10
defaults:
run:
working-directory: abxbus-rust
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- name: Check that the previous step managed to find some tasks for us to run
run: |
if [[ "${{ matrix.task.kind }}" == "error" ]]; then
echo "Failed get list of tasks from find_rust_tests job" > /dev/stderr
exit 1
fi
- name: Set up Rust
uses: dtolnay/rust-toolchain@4cda84d5c5c54efe2404f9d843567869ab1699d4 # stable
with:
toolchain: 1.99.1
- name: Cache Cargo
uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
with:
workspaces: abxbus-rust -> target
- name: Set up Go for cross-runtime roundtrip tests
if: matrix.task.kind == 'test' && matrix.task.name == 'test_cross_runtime_roundtrip'
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
with:
go-version-file: abxbus-go/go.mod
cache: true
cache-dependency-path: abxbus-go/go.sum
- name: Run Rust library tests
if: matrix.task.kind == 'lib'
run: cargo test --locked --all-features --lib -- --nocapture --test-threads=1
- name: Run Rust integration test
if: matrix.task.kind == 'test'
run: cargo test --locked --all-features --test ${{ matrix.task.name }} -- --nocapture --test-threads=1
- name: Run Rust binary tests
if: matrix.task.kind == 'bin'
run: cargo test --locked --all-features --bin ${{ matrix.task.name }} -- --nocapture --test-threads=1