Skip to content

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

Add: Tests on local runners with shared USB resources

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

Workflow file for this run

name: Test all targets
on: [push, pull_request]
env:
CI_PING_IP: 192.168.1.185
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
ci-setup:
runs-on: raspbian-armv7-kernel-5.10.33
outputs:
ci_number: ${{ steps.set-ci.outputs.ci_number }}
steps:
- name: Determine CI number
id: set-ci
run: |
# If hostname method fails, check for a file indicator
if [ -z "$CI_NUMBER" ]; then
if [ -f "/etc/ci1_indicator" ]; then
CI_NUMBER=1
elif [ -f "/etc/ci2_indicator" ]; then
CI_NUMBER=2
fi
fi
# If we still don't have a CI_NUMBER, exit with an error
if [ -z "$CI_NUMBER" ]; then
echo "Error: Unable to determine CI_NUMBER"
echo "Hostname: $HOSTNAME"
echo "Contents of /etc:"
ls -l /etc | grep ci
exit 1
fi
echo "Determined CI_NUMBER: $CI_NUMBER"
echo "ci_number=$CI_NUMBER" >> $GITHUB_OUTPUT
- name: Check if CI is busy and wait if necessary
run: |
MAX_WAIT_TIME=3600 # Maximum wait time in seconds (1 hour)
WAIT_INTERVAL=60 # Check every 60 seconds
TOTAL_WAIT=0
while [ $TOTAL_WAIT -lt $MAX_WAIT_TIME ]; do
BUSY_STATE=$(curl -s "http://${{ env.CI_PING_IP }}/switch/ci_busy_flag" | jq -r '.state')
if [ "$BUSY_STATE" = "OFF" ]; then
echo "CI is not busy, proceeding with setup"
break
fi
echo "CI is busy, waiting for $WAIT_INTERVAL seconds..."
sleep $WAIT_INTERVAL
TOTAL_WAIT=$((TOTAL_WAIT + WAIT_INTERVAL))
done
if [ $TOTAL_WAIT -ge $MAX_WAIT_TIME ]; then
echo "Timeout: CI remained busy for too long"
exit 1
fi
- name: Set busy state
run: |
curl -X POST "http://${{ env.CI_PING_IP }}/button/start_ci_run__set_busy_/press"
sleep 2
BUSY_STATE=$(curl -s "http://${{ env.CI_PING_IP }}/switch/ci_busy_flag" | jq -r '.state')
if [ "$BUSY_STATE" != "ON" ]; then
echo "Failed to set busy state"
exit 1
fi
- name: Set CI and wait for state change
run: |
MAX_RETRIES=5
RETRY_COUNT=0
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
curl -X POST "http://${{ env.CI_PING_IP }}/button/set_ci${{ steps.set-ci.outputs.ci_number }}_required/press"
sleep 10 # Wait for state change
LED_STATE=$(curl -s "http://${{ env.CI_PING_IP }}/binary_sensor/led_${{ steps.set-ci.outputs.ci_number }}_state" | jq -r '.state')
if [ "$LED_STATE" = "ON" ]; then
echo "Successfully set CI${{ steps.set-ci.outputs.ci_number }}"
break
fi
RETRY_COUNT=$((RETRY_COUNT+1))
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
echo "Failed to set CI after $MAX_RETRIES attempts"
exit 1
fi
echo "Retrying to set CI... (Attempt $RETRY_COUNT of $MAX_RETRIES)"
sleep 5
done
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 }}
ci-cleanup:
needs: [quick-tests, build, deploy]
runs-on: raspbian-armv7-kernel-5.10.33
if: always()
steps:
- name: Clear busy state
run: |
curl -X POST "http://${{ env.CI_PING_IP }}/button/end_ci_run__clear_busy_/press"
sleep 2
BUSY_STATE=$(curl -s "http://${{ env.CI_PING_IP }}/switch/ci_busy_flag" | jq -r '.state')
if [ "$BUSY_STATE" != "OFF" ]; then
echo "Failed to clear busy state"
exit 1
fi