This file contains hidden or 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
| name: Launching a test Slurm cluster, running unit tests, and performing a SonarQube scan | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| branches: | |
| - main | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install . | |
| pip install mypy pytest pytest-cov | |
| - name: Static type checking | |
| run: | | |
| mypy --version | |
| mypy src --ignore-missing-imports --check-untyped-defs --python-version 3.10 | |
| - name: Start Slurm Container and run pytest | |
| run: | | |
| echo "Starting slurm test container" | |
| nohup docker run -p 10022:22 -p 6821:6820 --name testslurm --privileged ghcr.io/xenon-middleware/slurm:25 -d & | |
| pid=$! | |
| # Wait for container to become healthy | |
| while ! docker exec testslurm scontrol ping > /dev/null 2>&1; do | |
| echo \"Waiting for Slurm to initialize...\" | |
| sleep 5 | |
| done | |
| # Get and export token | |
| TEST_CLUSTER_TOKEN=$(docker exec testslurm scontrol token) | |
| export $TEST_CLUSTER_TOKEN | |
| # Run tests | |
| python -m pytest --cov --cov-report term --cov-report xml --junitxml=xunit-result.xml | |
| # Correct coverage paths within coverage.xml file | |
| sed -i "s+$PWD/++g" coverage.xml | |
| # Cleanup | |
| echo "KILLING $pid" | |
| kill -9 $pid | |
| # Remove container | |
| docker stop testslurm | |
| docker rm testslurm | |
| # - name: SonarCloud Scan | |
| # uses: SonarSource/sonarcloud-github-action@master | |
| # env: | |
| # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | |
| # SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |