Skip to content

Prepare code for operations #599

Prepare code for operations

Prepare code for operations #599

Workflow file for this run

name: Trigger Tests
on:
push:
branches:
- main
pull_request:
types:
- opened
- synchronize
- reopened
jobs:
unit_tests:
runs-on: ubuntu-latest
steps:
- name: compile and test on remote device
uses: appleboy/[email protected]
with:
host: ${{ secrets.SECRET_IP }}
username: ${{ secrets.SECRET_USER}}
password: ${{ secrets.SSH_PASS }}
key: ${{ secrets.RPI_PRIVATE_KEY }}
port: ${{ secrets.SECRET_PORT }}
script: |
# Initialize a variable to indicate if any command failed
#To stop the script if any command fails
set -e
failed=false
ls
cd ./UnitDir
# Get the branch name
branch="${{ github.head_ref }}"
if [ -z "$branch" ]; then
branch="${{ github.ref }}"
branch="${branch#refs/heads/}"
fi
echo "Testing branch: $branch"
# Clone the repository for the branch
REPO_DIR="2024_C_AV_RPI_${branch}"
if [ ! -d "$REPO_DIR" ]; then
echo "Cloning repository for branch $branch..."
git clone [email protected]:EPFLRocketTeam/2024_C_AV_RPI.git "$REPO_DIR"
fi
# Change to the repository directory
cd "$REPO_DIR"
echo "Fetching updates for branch $branch..."
git fetch origin
echo "Resetting to origin/$branch..."
git reset --hard "origin/$branch"
git submodule update --init --recursive --remote
# Create a temporary build directory for this test run
BUILD_DIR="build_$(date +%s)"
echo "Creating temporary build directory: $BUILD_DIR"
mkdir "$BUILD_DIR"
cd "$BUILD_DIR"
echo "Running CMake configuration..."
cmake -DENABLE_TESTING=ON -DENABLE_COVERAGE=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
echo "Building project..."
make || failed=true
echo "Running tests..."
ctest --output-on-failure || failed=true
echo "Generating coverage data..."
find . -name "*.gcda" -exec gcov {} \;
# Run sonarcloud
source ~/.bashrc
cd ..
/opt/sonar-scanner/bin/sonar-scanner -Dsonar.token=${{ secrets.SONAR_TOKEN }} -Dsonar.exclusions=src/sensor_drivers/**,src/i2c_interface/**,src/post_flight/** -Dsonar.sources=src -Dsonar.tests=tests -Dsonar.cfamily.compile-commands="${BUILD_DIR}/compile_commands.json" -Dsonar.host.url=https://sonarcloud.io -Dsonar.scm.provider=git -Dsonar.projectKey=epflrocketteam-1_2024_C_AV_RPI -Dsonar.organization=epflrocketteam-1 -Dsonar.projectBaseDir="/home/av/UnitDir/${REPO_DIR}" -Dsonar.cfamily.gcov.reportsPath=build -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} -Dsonar.pullrequest.branch=${{ github.head_ref }} -Dsonar.pullrequest.base=${{ github.base_ref }}
cd ..
rm -rf "$BUILD_DIR"
if [ "$failed" = true ]; then
exit 1
fi
echo "All tests passed successfully!"