fix(rust.sh): remove unnecessary nightly flag from cargo doc command#879
fix(rust.sh): remove unnecessary nightly flag from cargo doc command#879github-actions[bot] merged 1 commit intodevelopfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to simplify Rust documentation generation by removing the explicit nightly toolchain selector from the docs script, and it also introduces consistent “exit-on-error” and process-cleanup trap handling across several shell scripts.
Changes:
- Remove
+nightlyfromcargo docinvocation in the Rust docs script. - Add
set -eandINT/TERM/EXITtrap logic to multiple scripts to improve failure handling and subprocess cleanup. - Add trap teardown (
trap - ...) at the end of affected scripts.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/parse-args.sh | Adds set -e and trap setup/teardown around argument parsing. |
| scripts/packages/test/index.sh | Adds trap setup/teardown around Rust test detection/execution. |
| scripts/packages/docs/rust.sh | Removes +nightly from cargo doc and adds trap teardown. |
| scripts/packages/build/typescript.sh | Adds trap setup/teardown for TypeScript build script. |
| scripts/packages/build/rust.sh | Adds trap setup/teardown for Rust build script. |
| scripts/functions.sh | Adds set -e and trap setup/teardown to the shared functions library. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Exit immediately when any subprocess returns a non-zero command | ||
| set -e | ||
|
|
||
| # Kill all subprocesses when exiting | ||
| # shellcheck disable=2154 | ||
| trap 'exit $exit_code' INT TERM | ||
| trap 'exit_code=$?; kill 0' EXIT |
There was a problem hiding this comment.
parse-args.sh is sourced by other scripts (e.g. scripts/packages/build/*.sh). Adding set -e and especially installing/uninstalling INT/TERM/EXIT traps here mutates the caller shell: the final trap - INT TERM EXIT clears any traps set by the parent script, so the parent no longer has its cleanup/kill-on-exit behavior for the rest of execution. Recommend removing trap logic (and ideally set -e) from this shared, sourced helper, or refactor it into a function that returns parsed values without altering global shell options/traps.
| # Exit immediately when any subprocess returns a non-zero command | ||
| set -e | ||
|
|
||
| # Kill all subprocesses when exiting | ||
| # shellcheck disable=2154 | ||
| trap 'exit $exit_code' INT TERM | ||
| trap 'exit_code=$?; kill 0' EXIT | ||
|
|
There was a problem hiding this comment.
This file is sourced by multiple entrypoint scripts. Setting set -e and registering traps in a sourced library changes the caller’s execution environment, and the trap - INT TERM EXIT at the end immediately removes any traps the parent script set before sourcing this file. functions.sh should avoid changing shell options/traps; keep it to function definitions, and let entrypoint scripts own set -e/trap setup.
| export RUSTDOCFLAGS="--enable-index-page -Zunstable-options" | ||
|
|
||
| cargo doc +nightly --no-deps --document-private-items $verbose_flag $open_docs || handle_error "Failed to build cargo docs" | ||
| cargo doc --no-deps --document-private-items $verbose_flag $open_docs || handle_error "Failed to build cargo docs" |
There was a problem hiding this comment.
rust-toolchain.toml pins a stable toolchain, but this script still exports RUSTDOCFLAGS with -Zunstable-options (nightly-only). Removing cargo doc +nightly will make docs generation fail on stable. Either keep using the nightly toolchain for docs, or remove/guard the nightly-only -Z flags so cargo doc works on stable as intended.
| cargo doc --no-deps --document-private-items $verbose_flag $open_docs || handle_error "Failed to build cargo docs" | |
| cargo +nightly doc --no-deps --document-private-items $verbose_flag $open_docs || handle_error "Failed to build cargo docs" |
| set -e | ||
|
|
||
| # Kill all subprocesses when exiting | ||
| # shellcheck disable=2154 |
There was a problem hiding this comment.
exit_code is not initialized before being used in the INT/TERM trap. If the script is interrupted before any command fails, exit $exit_code will typically exit with the status of the last successful command (often 0), masking the interrupt. Initialize exit_code to a non-zero default (e.g. 130) or set explicit exit codes per-signal in the trap handlers.
| # shellcheck disable=2154 | |
| # shellcheck disable=2154 | |
| exit_code=130 |
| # Kill all subprocesses when exiting | ||
| # shellcheck disable=2154 | ||
| trap 'exit $exit_code' INT TERM | ||
| trap 'exit_code=$?; kill 0' EXIT |
There was a problem hiding this comment.
exit_code is not initialized before being used in the INT/TERM trap. On SIGINT/SIGTERM, this can cause the script to exit 0 (status of the last successful command) instead of a non-zero signal exit code, which can incorrectly mark CI runs as successful. Initialize exit_code up front or use explicit per-signal exit codes in the trap.
| cp "$built_path" "$dist_dir" || handle_error "Failed to copy the built file" | ||
| fi | ||
|
|
||
| # Remove traps to exit with 0 |
There was a problem hiding this comment.
The comment says “Remove traps to exit with 0”, but unsetting traps doesn’t control the exit status; it just restores default signal/exit handling. Consider rewording to reflect the actual intent (e.g. avoiding the EXIT trap cleanup on successful completion).
| # Remove traps to exit with 0 | |
| # Clear traps to restore default signal/exit handling (avoid EXIT trap cleanup on success) |
| # set positional arguments in their proper place | ||
| eval set -- "$PARAMS" | ||
|
|
||
| # Remove traps to exit with 0 |
There was a problem hiding this comment.
The comment says “Remove traps to exit with 0”, but unsetting traps doesn’t set/force exit status 0; it only removes the trap handlers. Consider rewording to avoid implying exit-code behavior.
| # Remove traps to exit with 0 | |
| # Clear custom traps before normal script completion |
| } No newline at end of file | ||
| } | ||
|
|
||
| # Remove traps to exit with 0 |
There was a problem hiding this comment.
The comment says “Remove traps to exit with 0”, but unsetting traps doesn’t influence the exit code; it only restores default signal/exit handling. Consider rewording to match behavior.
| # Remove traps to exit with 0 | |
| # Remove traps and restore default signal/exit handling |
d2954d9 to
a93dcff
Compare
- Updated the `cargo doc` command in `rust.sh` to remove the `+nightly` flag, simplifying the documentation build process. - This change aims to enhance compatibility and streamline the documentation generation without relying on the nightly version of Cargo.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #!/bin/bash | ||
| set -e # Exit immediately if a command fails | ||
|
|
||
| # Define the patterns: #[test], test_transform(, or test!( | ||
| # We use -E for extended regex to use the OR (|) operator |
There was a problem hiding this comment.
Dropping set -e here changes failure semantics: if cargo test --lib/... fails but cargo test --doc passes, this script will exit 0 and mask the failure. Restore set -e (or explicitly check/propagate the exit code after each cargo test) to ensure test failures are not hidden.
| #!/usr/bin/env sh | ||
|
|
||
| # Exit immediately when any subprocess returns a non-zero command | ||
| set -e | ||
|
|
||
| script_dir="$(cd "$(dirname "$0")" && pwd)" | ||
| dist_dir="./dist" | ||
|
|
There was a problem hiding this comment.
The PR title/description says this is only about removing +nightly from the Rust docs build, but this PR also removes set -e / trap-based error handling in multiple unrelated scripts (e.g., build/test scripts). If this broader behavior change is intentional, the PR description should be updated (and ideally split into a separate PR) so reviewers can evaluate the risk and rationale separately.
|
/approve |
|
/merge |
|
Success! Fast forwarded develop to doc-pipeline! |
cargo doccommand inrust.shto remove the+nightlyflag, simplifying the documentation build process.Description
Please include a summary of the changes and the related issue. Please also
include relevant motivation and context. List any dependencies that are required
for this change.
Fixes
(Optional) Fixes # (issue)
Additional Info
(Optional) Add any other relevant information about the pull request here.
Type of change
Please select options that are relevant.
not work as expected)
Checklist