-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move examples out of check script, create scripts for testi…
…ng and examples (#488) # Rationale for this change Currently, we have shell scripts to run the CI jobs locally before submitting commits to a PR, to ensure that remote CI jobs are successful with as few runs as possible. The current check job includes several computationally expensive examples that should not be included in in a check workflow. Making this refactor makes local CI simulation more reliable and reduces load of the remote CI runners. # What changes are included in this PR? - [x] moves examples into distinct block in lint-and-test yaml for CI jobs - [x] creates testing and examples scripts for separating the local CI jobs # Are these changes tested? - [x] Test that check script correctly identifies all clippy lints in lint-and-release yaml - [x] test that check script only runs checks - [x] test that examples script only runs examples - [x] test that test script only runs test
- Loading branch information
Showing
4 changed files
with
202 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Optional help text | ||
if [[ "$1" == "-h" || "$1" == "--help" ]]; then | ||
echo "Runs only the cargo commands within the 'examples:' job in lint-and-test.yml." | ||
fi | ||
|
||
# Location of GitHub Actions workflow file | ||
YAML_FILE=".github/workflows/lint-and-test.yml" | ||
|
||
# Ensure the file exists | ||
if [ ! -f "$YAML_FILE" ]; then | ||
echo "Error: $YAML_FILE not found." | ||
echo "Please run this script from the repository root or update YAML_FILE accordingly." | ||
echo "Exiting with status 0, no commands executed." | ||
|
||
fi | ||
|
||
################################################################################ | ||
# 1) Extract only the lines from 'examples:' up until the next top-level job | ||
# | ||
# - We look for lines starting with exactly two spaces, then 'examples:', | ||
# and capture everything until the next line that also starts with two | ||
# spaces and ends with a colon (i.e., ' coverage:', ' clippy:', etc.). | ||
# | ||
# 2) Then find lines containing `cargo` commands and strip off 'run:'. | ||
################################################################################ | ||
cargo_commands=$( | ||
sed -n -E '/^ examples:/,/^ [A-Za-z0-9_]+:/p' "$YAML_FILE" \ | ||
| grep -E '^\s*run:.*cargo' \ | ||
| sed -E 's/^\s*run:\s*//' | ||
) | ||
|
||
# If we didn't find any commands, no big deal—just exit quietly. | ||
if [ -z "$cargo_commands" ]; then | ||
echo "No cargo commands were found in the 'examples:' job block." | ||
echo "Nothing to run." | ||
|
||
fi | ||
|
||
echo "Commands extracted from the 'examples:' job:" | ||
echo "--------------------------------------------" | ||
echo "$cargo_commands" | ||
echo "--------------------------------------------" | ||
echo | ||
|
||
################################################################################ | ||
# 3) Run each command, but do NOT use exit codes. We'll collect failures | ||
# and report at the end. | ||
################################################################################ | ||
total=0 | ||
failed=0 | ||
|
||
while IFS= read -r cmd; do | ||
total=$((total + 1)) | ||
echo "[$total] Running: $cmd" | ||
|
||
if ! eval "$cmd"; then | ||
echo " -> Command FAILED (continuing)." | ||
failed=$((failed + 1)) | ||
else | ||
echo " -> Command succeeded." | ||
fi | ||
|
||
echo | ||
done <<< "$cargo_commands" | ||
|
||
################################################################################ | ||
# 4) Print a summary of how many commands failed. Always exit 0 to avoid | ||
# crashing the shell or signaling an error code. | ||
################################################################################ | ||
echo "Summary of examples job:" | ||
echo " Total commands: $total" | ||
echo " Failed commands: $failed" | ||
if [ "$failed" -gt 0 ]; then | ||
echo "Some commands failed, but we are NOT exiting with a non-zero status." | ||
else | ||
echo "All commands completed successfully!" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [[ "$1" == "-h" || "$1" == "--help" ]]; then | ||
echo "Runs only the 'test' job cargo commands from lint-and-test.yml, ignoring rustup lines." | ||
fi | ||
|
||
YAML_FILE=".github/workflows/lint-and-test.yml" | ||
|
||
# Ensure the YAML file exists | ||
if [ ! -f "$YAML_FILE" ]; then | ||
echo "Error: '$YAML_FILE' does not exist." | ||
echo "No commands to run. Exiting." | ||
fi | ||
|
||
############################################################################### | ||
# 1) Extract lines between: | ||
# ^ test: (2 spaces + 'test:') | ||
# and | ||
# ^ [A-Za-z0-9_]+: (2 spaces + something else + ':') | ||
# This ensures we only capture lines up to the next job at the same indentation. | ||
# | ||
# 2) Within that block, look for lines containing `run: cargo ...`. | ||
# 3) Exclude any with 'rustup'. | ||
# 4) Strip off 'run:' prefix. | ||
############################################################################### | ||
cargo_commands=$( | ||
sed -n '/^ test:/,/^ [A-Za-z0-9_]\+:/p' "$YAML_FILE" \ | ||
| grep -E '^\s*run:.*cargo' \ | ||
| grep -v 'rustup' \ | ||
| sed -E 's/^\s*run:\s*//' | ||
) | ||
|
||
if [ -z "$cargo_commands" ]; then | ||
echo "No cargo commands found in the 'test' job." | ||
exit 0 | ||
fi | ||
|
||
echo "Extracted cargo commands from the 'test:' job (skipping 'rustup'):" | ||
echo "------------------------------------------------------------------" | ||
echo "$cargo_commands" | ||
echo "------------------------------------------------------------------" | ||
echo | ||
|
||
############################################################################### | ||
# 2) Run each command, counting failures but NOT exiting on them. | ||
############################################################################### | ||
count=0 | ||
failed=0 | ||
|
||
while IFS= read -r cmd; do | ||
count=$((count + 1)) | ||
echo "[$count] Running command: $cmd" | ||
|
||
if ! eval "$cmd"; then | ||
echo " -> Command FAILED (continuing)." | ||
failed=$((failed + 1)) | ||
else | ||
echo " -> Command succeeded." | ||
fi | ||
echo | ||
done <<< "$cargo_commands" | ||
|
||
############################################################################### | ||
# 3) Print a summary. Always exit code 0 (no crash). | ||
############################################################################### | ||
echo "Summary of the 'test' job cargo commands:" | ||
echo " Total commands: $count" | ||
echo " Failed commands: $failed" | ||
|
||
if [ "$failed" -gt 0 ]; then | ||
echo "Some commands failed, but we are NOT exiting with a non-zero code." | ||
else | ||
echo "All commands in the 'test' job completed successfully!" | ||
fi | ||
|
||
|