From 2b93adc0a9f8aacaae9fdaa75197f1befea5a4f3 Mon Sep 17 00:00:00 2001 From: "dustin.ray" Date: Fri, 17 Jan 2025 13:40:04 -0800 Subject: [PATCH 1/3] refactor: move examples into group so that running local check script can skip them --- .github/workflows/lint-and-test.yml | 43 ++++++++++++++++++----------- scripts/run_ci_checks.sh | 29 ++++++++++++------- 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index c939e835b..8f585d081 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -120,22 +120,33 @@ jobs: run: | cargo test proof_primitive::dory::dory_compute_commitments_test --no-default-features --features="std" && \ cargo test proof_primitive::dory::dynamic_dory_compute_commitments_test --no-default-features --features="std" - - name: Run hello_world example (With Blitzar) - run: cargo run --example hello_world --features="test" - - name: Run hello_world example (Without Blitzar and With Rayon) - run: cargo run --example hello_world --no-default-features --features="rayon test" - - name: Run hello_world example (Without Blitzar and Without Rayon) - run: cargo run --example hello_world --no-default-features --features="test" - - name: Run space example - run: cargo run --example space - - name: Run dog breeds example - run: cargo run --example dog_breeds - - name: Run wood types example - run: cargo run --example wood_types - - name: Run posql_db example (With Blitzar) - run: bash crates/proof-of-sql/examples/posql_db/run_example.sh - - name: Run posql_db example (Without Blitzar) - run: bash crates/proof-of-sql/examples/posql_db/run_example.sh --no-default-features --features="rayon" + + examples: + name: Run Examples (Heavy) + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - name: Install stable toolchain + run: curl https://sh.rustup.rs -sSf | bash -s -- -y --profile minimal && source ~/.cargo/env + - name: Run hello_world example (With Blitzar) + run: cargo run --example hello_world --features="test" + - name: Run hello_world example (Without Blitzar and With Rayon) + run: cargo run --example hello_world --no-default-features --features="rayon test" + - name: Run hello_world example (Without Blitzar and Without Rayon) + run: cargo run --example hello_world --no-default-features --features="test" + - name: Run space example + run: cargo run --example space + - name: Run dog breeds example + run: cargo run --example dog_breeds + - name: Run wood types example + run: cargo run --example wood_types + - name: Run posql_db example (With Blitzar) + run: bash crates/proof-of-sql/examples/posql_db/run_example.sh + - name: Run posql_db example (Without Blitzar) + run: bash crates/proof-of-sql/examples/posql_db/run_example.sh --no-default-features --features="rayon" + + clippy: name: Clippy runs-on: large-8-core-32gb-22-04 diff --git a/scripts/run_ci_checks.sh b/scripts/run_ci_checks.sh index a6855447a..8edb8f7e9 100755 --- a/scripts/run_ci_checks.sh +++ b/scripts/run_ci_checks.sh @@ -4,7 +4,7 @@ set -e # Display a help text -[ "$1" = "-h" -o "$1" = "--help" ] && echo "Runs all CI checks (excluding tests and udeps)." && exit +[ "$1" = "-h" -o "$1" = "--help" ] && echo "Runs all CI checks (excluding tests, udeps, and the 'examples' job)." && exit # The path to the YAML file that defines the CI workflows YAML_FILE=".github/workflows/lint-and-test.yml" @@ -30,21 +30,30 @@ if [ ! -f "$YAML_FILE" ]; then exit 1 fi -# Extract all lines that contain 'cargo' commands from the YAML file, -# excluding ones with '--ignored', 'test', 'rustup', or 'udeps' -cargo_commands=$(grep -E '^\s*run:.*cargo' "$YAML_FILE" | grep -v -- '--ignored' | grep -v 'test' | grep -v 'rustup' | grep -v 'udeps' | sed -E 's/^\s*run:\s*//') +# 1) Remove the entire `examples:` job section from the file +# 2) Extract lines that contain 'cargo' commands +# 3) Exclude lines with '--ignored', 'test', 'rustup', or 'udeps' +# 4) Strip off the 'run:' prefix +cargo_commands=$( + sed '/^\s*examples:/,/^[^[:space:]]/d' "$YAML_FILE" \ + | grep -E '^\s*run:.*cargo' \ + | grep -v -- '--ignored' \ + | grep -v 'test' \ + | grep -v 'rustup' \ + | grep -v 'udeps' \ + | sed -E 's/^\s*run:\s*//' +) if [ -z "$cargo_commands" ]; then - echo "No cargo commands (other than tests) found in the YAML file." + echo "No cargo commands found (other than tests, udeps, or in the 'examples' job)." exit 1 fi -# Run each cargo command, ignoring tests which should be handled separately -echo "Extracted cargo commands (excluding test commands, --ignored tests, and udeps):" +# Run each cargo command +echo "Extracted cargo commands (excluding tests, udeps, and the 'examples' job):" echo "$cargo_commands" echo "=========================" -# Execute the commands failed_tests=0 while IFS= read -r cmd; do echo "Running command: $cmd" @@ -57,7 +66,7 @@ done <<< "$cargo_commands" # Print the results if [ "$failed_tests" -gt 0 ]; then - echo "Error: $failed_tests CI checks (excluding tests and udeps) have FAILED." + echo "Error: $failed_tests CI checks have FAILED (excluding tests, udeps, and 'examples' job)." else - echo "All CI checks (excluding tests and udeps) have completed successfully." + echo "All CI checks (excluding tests, udeps, and 'examples' job) completed successfully." fi From 2537de8fd8479b7b9f45a7366bc6da8d18f6b0d3 Mon Sep 17 00:00:00 2001 From: "dustin.ray" Date: Fri, 17 Jan 2025 14:18:36 -0800 Subject: [PATCH 2/3] refactor: move examples out of check job and create scripts for tests and examples --- .github/workflows/lint-and-test.yml | 1 - scripts/run_ci_checks.sh | 21 ++++---- scripts/run_posql_examples.sh | 81 +++++++++++++++++++++++++++++ scripts/run_test_jobs.sh | 77 +++++++++++++++++++++++++++ 4 files changed, 167 insertions(+), 13 deletions(-) create mode 100644 scripts/run_posql_examples.sh create mode 100644 scripts/run_test_jobs.sh diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index 8f585d081..105a3508d 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -146,7 +146,6 @@ jobs: - name: Run posql_db example (Without Blitzar) run: bash crates/proof-of-sql/examples/posql_db/run_example.sh --no-default-features --features="rayon" - clippy: name: Clippy runs-on: large-8-core-32gb-22-04 diff --git a/scripts/run_ci_checks.sh b/scripts/run_ci_checks.sh index 8edb8f7e9..ada7840b7 100755 --- a/scripts/run_ci_checks.sh +++ b/scripts/run_ci_checks.sh @@ -1,10 +1,10 @@ #!/bin/bash -# Exit immediately if a command exits with a non-zero status -set -e - # Display a help text -[ "$1" = "-h" -o "$1" = "--help" ] && echo "Runs all CI checks (excluding tests, udeps, and the 'examples' job)." && exit +if [[ "$1" == "-h" || "$1" == "--help" ]]; then + echo "Runs all CI checks (excluding tests, udeps, and the 'examples' job)." + echo "Does NOT run toolchain install/update commands." +fi # The path to the YAML file that defines the CI workflows YAML_FILE=".github/workflows/lint-and-test.yml" @@ -20,20 +20,18 @@ while [[ ! -f "$current_dir/sxt-proof-of-sql/.github/workflows/lint-and-test.yml # If we reach the root directory (i.e., /), stop to prevent an infinite loop if [[ "$current_dir" == "/" ]]; then echo "Could not find file." - exit 1 fi done # Check if the YAML file exists if [ ! -f "$YAML_FILE" ]; then echo "YAML file $YAML_FILE does not exist." - exit 1 fi -# 1) Remove the entire `examples:` job section from the file -# 2) Extract lines that contain 'cargo' commands -# 3) Exclude lines with '--ignored', 'test', 'rustup', or 'udeps' -# 4) Strip off the 'run:' prefix +# 1) Remove the entire `examples:` job section from the file. +# 2) Extract lines that contain 'cargo' commands. +# 3) Exclude lines with '--ignored', 'test', 'rustup', or 'udeps'. +# 4) Strip off the 'run:' prefix. cargo_commands=$( sed '/^\s*examples:/,/^[^[:space:]]/d' "$YAML_FILE" \ | grep -E '^\s*run:.*cargo' \ @@ -46,11 +44,10 @@ cargo_commands=$( if [ -z "$cargo_commands" ]; then echo "No cargo commands found (other than tests, udeps, or in the 'examples' job)." - exit 1 fi # Run each cargo command -echo "Extracted cargo commands (excluding tests, udeps, and the 'examples' job):" +echo "Extracted cargo commands (excluding tests, udeps, 'examples' job, and toolchain installs):" echo "$cargo_commands" echo "=========================" diff --git a/scripts/run_posql_examples.sh b/scripts/run_posql_examples.sh new file mode 100644 index 000000000..ddf748c7b --- /dev/null +++ b/scripts/run_posql_examples.sh @@ -0,0 +1,81 @@ +#!/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," + echo "without stopping the shell on errors. Prints a summary of any failures." + +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 diff --git a/scripts/run_test_jobs.sh b/scripts/run_test_jobs.sh new file mode 100644 index 000000000..ba36aed53 --- /dev/null +++ b/scripts/run_test_jobs.sh @@ -0,0 +1,77 @@ +#!/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." + echo "Does NOT exit non-zero on failures, just prints a summary." +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 + + From 975f03942bea0a34f1c0abb9711d66ef56e56f1b Mon Sep 17 00:00:00 2001 From: "dustin.ray" Date: Fri, 17 Jan 2025 14:56:54 -0800 Subject: [PATCH 3/3] fix: help message --- scripts/run_ci_checks.sh | 1 - scripts/run_posql_examples.sh | 4 +--- scripts/run_test_jobs.sh | 1 - 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/run_ci_checks.sh b/scripts/run_ci_checks.sh index ada7840b7..5d03d2560 100755 --- a/scripts/run_ci_checks.sh +++ b/scripts/run_ci_checks.sh @@ -3,7 +3,6 @@ # Display a help text if [[ "$1" == "-h" || "$1" == "--help" ]]; then echo "Runs all CI checks (excluding tests, udeps, and the 'examples' job)." - echo "Does NOT run toolchain install/update commands." fi # The path to the YAML file that defines the CI workflows diff --git a/scripts/run_posql_examples.sh b/scripts/run_posql_examples.sh index ddf748c7b..df4870459 100644 --- a/scripts/run_posql_examples.sh +++ b/scripts/run_posql_examples.sh @@ -2,9 +2,7 @@ # Optional help text if [[ "$1" == "-h" || "$1" == "--help" ]]; then - echo "Runs only the cargo commands within the 'examples:' job in lint-and-test.yml," - echo "without stopping the shell on errors. Prints a summary of any failures." - + echo "Runs only the cargo commands within the 'examples:' job in lint-and-test.yml." fi # Location of GitHub Actions workflow file diff --git a/scripts/run_test_jobs.sh b/scripts/run_test_jobs.sh index ba36aed53..634880350 100644 --- a/scripts/run_test_jobs.sh +++ b/scripts/run_test_jobs.sh @@ -2,7 +2,6 @@ if [[ "$1" == "-h" || "$1" == "--help" ]]; then echo "Runs only the 'test' job cargo commands from lint-and-test.yml, ignoring rustup lines." - echo "Does NOT exit non-zero on failures, just prints a summary." fi YAML_FILE=".github/workflows/lint-and-test.yml"