Skip to content

Commit 6b7293e

Browse files
arielb1Ariel Ben-Yehuda
andauthored
Ci local agents md (async-profiler#128)
* tests: fix numeric comparison [[ x < y ]] compares numbers by strings, so 10 < 9 - and `-lt` does not compare floating point numbers. Use bc as per https://stackoverflow.com/questions/8654051/how-can-i-compare-two-floating-point-numbers-in-bash * decoder: clippy * ci: add AGENTS.md and ci-local.py should allow doing automated changes in an easy enough way --------- Co-authored-by: Ariel Ben-Yehuda <me@arielby.net>
1 parent 615bac0 commit 6b7293e

File tree

5 files changed

+84
-3
lines changed

5 files changed

+84
-3
lines changed

AGENTS.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## Testing
2+
3+
- Use `cargo test` to run all tests in this workspace
4+
- To run the full suite of tests CI will run, see `scripts/ci-local.py`.
5+
- Before commiting run `cargo fmt` and `cargo clippy`, as well as `cd decoder && cargo fmt && cargo clippy`. YOU MUST FIX CLIPPY ERRORS.
6+
7+
## Finishing Up
8+
When instructed to "finish up", follow this process:
9+
10+
1. Run `cargo +nightly fmt --all` to format all code
11+
2. Run `cargo clippy --workspace --all-features -- -D warnings` and fix all errors
12+
3. Fix any small issues found. For big issues, confirm with the user first
13+
4. Amend changes into the most recent commit: `git add -A && git commit --amend --no-edit`
14+
5. Push: `git push --force-with-lease`
15+
6. Monitor CI on GitHub to ensure it passes. If it fails:
16+
- Analyze why the issue was missed
17+
- Update the pre-CI checks to catch similar issues
18+
- Fix the problem and repeat from step 1
19+
20+
Note: For a full local CI check matching what runs on GitHub, use `scripts/ci-local.py`
21+
22+
Helpful commands for monitoring CI:
23+
- Check PR status: `gh pr checks <branch-name>`
24+
- Watch until completion: `gh pr checks <branch-name> --watch` (refreshes every 10s, exits when done)
25+
- View with details: `gh pr view <branch-name> --json statusCheckRollup --jq '.statusCheckRollup[] | "\(.name): \(.status) - \(.conclusion)"'`
26+

decoder/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ fn poll_event_from_user_event(
565565
Some(PollEventKey {
566566
tid: thread_id as u32,
567567
clock_start: (start_time_ticks as u64).saturating_sub(duration),
568-
duration: duration as u64,
568+
duration,
569569
})
570570
} else {
571571
None

scripts/ci-local.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/python3
2+
3+
import os
4+
import subprocess
5+
import yaml
6+
import shlex
7+
import shutil
8+
9+
def runcmd(cmd, cwd='.', extra_env=None, shell=False):
10+
if extra_env:
11+
env = os.environ.copy()
12+
env.update(extra_env)
13+
else:
14+
env = None
15+
print(f'cd {cwd} && {cmd}')
16+
subprocess.check_call(cmd, cwd=cwd, env=env, shell=shell)
17+
18+
def run_integration_tests(y):
19+
print('Running integration tests')
20+
runcmd(shlex.split('cargo +stable build --all-features --verbose --example simple --example pollcatch-without-agent'),
21+
extra_env=y['jobs']['build-for-testing']['env'])
22+
shutil.copy('./target/debug/examples/simple', './tests/simple')
23+
shutil.copy('./target/debug/examples/pollcatch-without-agent', './tests/pollcatch-without-agent')
24+
shutil.copy('./decoder/target/debug/pollcatch-decoder', './tests/pollcatch-decoder')
25+
for action in y['jobs']['test']['steps']:
26+
if action.get('shell') == 'bash':
27+
runcmd(action['run'], shell=True, cwd=action.get('working-directory', '.'))
28+
29+
def main():
30+
y = yaml.safe_load(open('.github/workflows/build.yml'))
31+
build = y['jobs']['build']
32+
for ek,ev in build['env'].items():
33+
os.environ[ek] = str(ev)
34+
35+
# Decoder
36+
runcmd(['cargo', f'+nightly', 'fmt', '--all'], cwd='./decoder')
37+
runcmd(['cargo', f'+nightly', 'clippy', '--workspace', '--all-features', '--', '-D', 'warnings'], cwd='./decoder')
38+
runcmd(['cargo', '+nightly', 'test'], cwd='./decoder')
39+
runcmd(['cargo', '+nightly', 'build'], cwd='./decoder')
40+
41+
# Main
42+
runcmd(['cargo', f'+nightly', 'fmt', '--all'])
43+
runcmd(['cargo', f'+nightly', 'clippy', '--workspace', '--all-features', '--', '-D', 'warnings'])
44+
for toolchain in build['strategy']['matrix']['toolchain']:
45+
for flags in build['strategy']['matrix']['flags']:
46+
runcmd(['cargo', f'+{toolchain}', 'build', '--verbose'] + shlex.split(flags))
47+
runcmd(['cargo', f'+{toolchain}', 'test', '--verbose'] + shlex.split(flags))
48+
runcmd(['cargo', '+nightly', 'doc', '--verbose', '--no-deps'], extra_env={'RUSTDOCFLAGS': '-D warnings --cfg docsrs'})
49+
50+
run_integration_tests(y)
51+
52+
print('All tests successful!')
53+
54+
if __name__ == '__main__':
55+
main()

tests/integration.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ found_good=0
2828
for profile in $dir/*.jfr; do
2929
duration=$(./pollcatch-decoder duration "$profile")
3030
# Ignore "partial" profiles of less than 8s
31-
if [[ $duration > 8 ]]; then
31+
if ! (( $(echo "${duration}<8" | bc) )); then
3232
found_good=1
3333
else
3434
echo "Profile $profile is too short"

tests/separate_runtime_integration.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ found_good=0
1919
for profile in $dir/*.jfr; do
2020
duration=$(./pollcatch-decoder duration "$profile")
2121
# Ignore "partial" profiles of less than 2s
22-
if [[ $duration > 2 ]]; then
22+
if ! (( $(echo "${duration}<2" | bc) )); then
2323
found_good=1
2424
else
2525
echo "Profile $profile is too short"

0 commit comments

Comments
 (0)