Skip to content

Commit 05eab20

Browse files
committed
refactor(ci): move the stub-freshness check into test-pure-rust.nu
Every other pure-Rust CI step is a registered function in this script; the stub check was inline shell in the workflow. Register it as check-python-stubs in both the test map and the pipeline so it also runs in a local full-suite run, and reduce the job to invoking it.
1 parent eae4afe commit 05eab20

2 files changed

Lines changed: 37 additions & 19 deletions

File tree

.github/workflows/ci.yml

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,11 @@ jobs:
514514
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
515515
skipPush: ${{ github.event_name == 'pull_request' }}
516516

517+
- name: Install Nushell
518+
run: |
519+
nix profile install nixpkgs#nushell
520+
chmod +x scripts/test-pure-rust.nu
521+
517522
- name: Setup nix environment
518523
run: |
519524
nix print-dev-env '.#pureRust-ci' --accept-flake-config > /tmp/nix-dev-env.sh
@@ -527,28 +532,10 @@ jobs:
527532
# Deliberately does NOT restore the `python-tests` job's generated-types
528533
# cache: a restored copy would be compared against the tree instead of a
529534
# freshly generated one, and the check would report on the cache.
530-
#
531-
# `touch build.rs` forces the generator to run even when cargo considers
532-
# the crate up to date -- otherwise a warm target dir makes this a no-op
533-
# that passes without generating anything.
534535
- name: Generated Python stubs are up to date
535536
run: |
536537
source /tmp/nix-dev-env.sh
537-
touch crates/hiroz-msgs/build.rs
538-
cargo build -j4 -p hiroz-msgs --features python_registry
539-
# `git status --porcelain`, not `git diff`: diff only reports tracked
540-
# files, so a stub for a newly-added package would be generated,
541-
# left untracked, and silently pass.
542-
drift=$(git status --porcelain -- crates/hiroz-msgs/python/hiroz_msgs_py/types)
543-
if [ -n "$drift" ]; then
544-
echo "$drift"
545-
git diff -- crates/hiroz-msgs/python/hiroz_msgs_py/types
546-
echo "::error::Generated Python stubs are stale. Run"
547-
echo " cargo build -p hiroz-msgs --features python_registry"
548-
echo "and commit the result."
549-
exit 1
550-
fi
551-
echo "Generated Python stubs match the message assets."
538+
nu scripts/test-pure-rust.nu check-python-stubs
552539
553540
go-tests:
554541
name: Go Tests (${{ matrix.os }})

scripts/test-pure-rust.nu

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,35 @@ def check-rustdoc-links [] {
7272
}
7373
}
7474

75+
def check-python-stubs [] {
76+
log-step "Generated Python stubs are up to date"
77+
# The stubs under crates/hiroz-msgs/python/hiroz_msgs_py/types/ are
78+
# generated from the .msg/.srv assets and committed. Nothing used to check
79+
# that the committed copy still matched the generator, so an asset change
80+
# without a rebuild-and-commit went unnoticed -- which is how six
81+
# rcl_interfaces classes fell out of the checked-in copy.
82+
#
83+
# `touch build.rs` forces the generator to run even when cargo considers
84+
# the crate up to date; without it a warm target dir makes this a no-op
85+
# that passes without generating anything.
86+
let stub_dir = "crates/hiroz-msgs/python/hiroz_msgs_py/types"
87+
touch crates/hiroz-msgs/build.rs
88+
run-cmd "cargo build -j4 -p hiroz-msgs --features python_registry"
89+
90+
# `git status --porcelain`, not `git diff`: diff reports only tracked
91+
# files, so a stub for a newly-added package would be generated, left
92+
# untracked, and silently pass.
93+
let drift = (^git status --porcelain -- $stub_dir | complete)
94+
if ($drift.stdout | str trim | is-not-empty) {
95+
print ($drift.stdout | str trim)
96+
print (^git diff -- $stub_dir | complete | get stdout)
97+
error make {
98+
msg: $"generated Python stubs are stale -- run `cargo build -p hiroz-msgs --features python_registry` and commit ($stub_dir)"
99+
}
100+
}
101+
print $"Generated Python stubs match the message assets."
102+
}
103+
75104
def check-examples [] {
76105
log-step "Check all examples (cargo check --examples)"
77106
run-cmd "cargo check --examples"
@@ -109,6 +138,7 @@ def get-test-map [] {
109138
check-hu: { check-hu }
110139
check-examples: { check-examples }
111140
check-rustdoc-links: { check-rustdoc-links }
141+
check-python-stubs: { check-python-stubs }
112142
check-distro-features: { check-distro-features }
113143
clippy-hiroz-py: { clippy-hiroz-py }
114144
clippy-tests: { clippy-tests }
@@ -124,6 +154,7 @@ def get-test-pipeline [] {
124154
"check-hu"
125155
"check-examples"
126156
"check-rustdoc-links"
157+
"check-python-stubs"
127158
"check-distro-features"
128159
"clippy-hiroz-py"
129160
"clippy-tests"

0 commit comments

Comments
 (0)