Skip to content

Add: Tests on local runners with shared USB resources #240

Add: Tests on local runners with shared USB resources

Add: Tests on local runners with shared USB resources #240

Workflow file for this run

name: Test all targets
on: [push, pull_request]
jobs:
quick-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions-rs/[email protected]
with:
toolchain: stable
override: true
- name: Check Type
run: cargo fmt -- --check
- name: Run internal tests
run: cargo test --verbose -- --nocapture
- name: Build
run: cargo build
build:
needs: quick-tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions-rs/[email protected]
with:
toolchain: stable
override: true
- name: Build docs
run: cargo doc
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.ref == 'refs/heads/master' }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./target/doc
compile-example:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Compile ping_1d example for ARM v7
uses: houseabsolute/[email protected]
with:
target: armv7-unknown-linux-gnueabihf
args: "--example ping_1d --release"
- name: Upload compiled example
uses: actions/[email protected]
with:
name: ping_1d-armv7
path: target/armv7-unknown-linux-gnueabihf/release/examples/ping_1d
tests:
needs: compile-example
runs-on: raspbian-armv7-kernel-5.10.33
if: ${{ github.repository_owner == 'bluerobotics' }}
steps:
- name: Run CI management script
run: /etc/github_runner/ci_management.sh
- name: Download compiled ping_1d example
uses: actions/download-artifact@v4
with:
name: ping_1d-armv7
path: ./ping_1d-armv7
- name: Make ping_1d executable
run: chmod +x ./ping_1d-armv7/ping_1d
- name: Run Ping Tests
run: |
# Define your tests here
tests=(
"Basic Ping1D Test:/dev/ttyUSB_Ping1:30:"
"Extended Ping1D Test:/dev/ttyUSB_Ping1:60:--extended-test"
# Add more tests here, following the format:
# "Test Name:Serial Port:Timeout:Additional Args"
)
run_test() {
local test_name=$1
local serial_port=$2
local timeout=$3
local additional_args=$4
echo "Running test: $test_name"
set +e
timeout ${timeout}s ./ping_1d-armv7/ping_1d --serial-port ${serial_port} ${additional_args}
exit_code=$?
set -e
if [ $exit_code -eq 124 ]; then
echo "Test '$test_name' timed out after ${timeout} seconds"
return 1
elif [ $exit_code -ne 0 ]; then
echo "Test '$test_name' failed with exit code $exit_code"
return $exit_code
else
echo "Test '$test_name' completed successfully"
return 0
fi
}
# Run all tests
for test in "${tests[@]}"; do
IFS=':' read -r name port timeout args <<< "$test"
if ! run_test "$name" "$port" "$timeout" "$args"; then
echo "Test '$name' failed. Stopping test execution."
exit 1
fi
done
- name: Post CI management script
if: always()
run: |
source /etc/github_runner/ci_management.sh
clear_busy_state
deploy:
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout to repository
uses: actions/checkout@v2
with:
submodules: recursive
- name: Setup Rust toolchain
uses: actions-rs/[email protected]
with:
toolchain: stable
override: true
- name: Install cargo-bump
run: cargo install cargo-bump --force
- name: Modify version with tag
run: cargo bump ${{ github.ref_name }}
- name: Automatic commit for crate version upgrade
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: master
commit_message: "Cargo: Update the crate version to ${{ github.ref_name }}"
- name: Publish to crates.io
uses: katyo/publish-crates@v1
with:
args: --allow-dirty
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}