-
Notifications
You must be signed in to change notification settings - Fork 61
184 lines (155 loc) · 5.33 KB
/
rust-tests.yml
File metadata and controls
184 lines (155 loc) · 5.33 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
name: Rust Tests
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
env:
CARGO_TERM_COLOR: always
jobs:
check-changes:
name: Check what code changed
runs-on: ubuntu-latest
outputs:
rust-changed: ${{ steps.changes.outputs.rust }}
npm-changed: ${{ steps.changes.outputs.npm }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for changes
id: changes
run: |
if [ "${{ github.event_name }}" == "push" ]; then
# For push events, check changes since the previous commit
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD)
else
# For pull requests, check changes against the base branch
git fetch origin "${{ github.base_ref }}"
CHANGED_FILES=$(git diff --name-only "origin/${{ github.base_ref }}" HEAD)
fi
echo "Changed files:"
echo "$CHANGED_FILES"
# Check if any Rust-related files changed
if echo "$CHANGED_FILES" | grep -E '\.(rs|toml)$|^Cargo\.|^Makefile$|^\.github/workflows/rust-tests\.yml$|^\.githooks/|^scripts/|^tests/' > /dev/null; then
echo "Rust code or related files changed"
echo "rust=true" >> "$GITHUB_OUTPUT"
else
echo "No Rust code changes detected"
echo "rust=false" >> "$GITHUB_OUTPUT"
fi
# Check if any NPM-related files changed
if echo "$CHANGED_FILES" | grep -E '^npm/|package\.json$|package-lock\.json$|\.js$|\.ts$|\.json$|^examples/chat/' > /dev/null; then
echo "NPM/Node.js code or related files changed"
echo "npm=true" >> "$GITHUB_OUTPUT"
else
echo "No NPM code changes detected"
echo "npm=false" >> "$GITHUB_OUTPUT"
fi
test:
name: Test on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: check-changes
if: needs.check-changes.outputs.rust-changed == 'true'
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@1.88.0
with:
components: rustfmt, clippy
- name: Setup Rust cache
uses: actions/cache@v4
timeout-minutes: 5
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('rust-toolchain', 'rust-toolchain.toml') || 'stable' }}
restore-keys: |
${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-
${{ runner.os }}-cargo-
- name: Show Rust version
run: |
rustc --version
cargo --version
cargo clippy --version
- name: Check formatting
run: cargo fmt --all -- --check
- name: Lint with clippy
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Build
run: cargo build
- name: Run unit tests
run: cargo test --lib
- name: Run integration tests
run: cargo test --test integration_tests
- name: Run property tests
run: cargo test --test property_tests
- name: Run CLI tests
run: cargo test --test cli_tests
npm-tests:
name: NPM Agent Tests on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: check-changes
if: needs.check-changes.outputs.npm-changed == 'true'
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node-version: [20]
steps:
- uses: actions/checkout@v4
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install Rust toolchain (for building local binary)
uses: dtolnay/rust-toolchain@1.88.0
with:
components: rustfmt
- name: Setup Node.js cache
uses: actions/cache@v4
with:
path: |
npm/node_modules
~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('npm/package.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install npm dependencies
run: |
cd npm
npm install
- name: Build Rust binary for tests and place in npm/bin
shell: bash
run: |
# Ensure a local binary exists to avoid network downloads during tests
rustup show
cargo build --release
mkdir -p npm/bin
if [[ "${{ runner.os }}" == "Windows" ]]; then
cp target/release/probe.exe npm/bin/probe.exe
else
cp target/release/probe npm/bin/probe-binary
chmod +x npm/bin/probe-binary
fi
- name: Build npm package
run: |
cd npm
npm run build
- name: Run npm agent tests
run: |
cd npm
npm test
- name: Upload coverage reports
if: always()
uses: actions/upload-artifact@v4
with:
name: npm-coverage-${{ matrix.os }}-node${{ matrix.node-version }}
path: npm/coverage/
retention-days: 7