Pytests #7
Workflow file for this run
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
# Workflow for running tests on server code | |
name: Run Tests | |
on: | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
- reopened | |
paths: | |
- "src/server/**" | |
- "src/sandbox/**" | |
# Allows running this workflow manually | |
workflow_dispatch: | |
jobs: | |
check: | |
runs-on: ubuntu-latest | |
services: | |
docker: | |
image: docker:latest | |
options: --privileged | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- uses: docker/setup-buildx-action@v3 | |
with: | |
version: latest | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: "3.11" | |
- name: Cache dependencies | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cache/pip | |
src/.tox | |
key: ${{ runner.os }}-pip-${{ hashFiles('src/requirements.txt', 'src/server/requirements.txt', 'src/sandbox/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install dependencies | |
run: | | |
cd src/ | |
python -m pip install --upgrade pip wheel setuptools | |
pip install -r requirements.txt | |
pip install pytest docker | |
- name: Determine changed files | |
id: changes | |
run: | | |
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}) | |
echo "Changed files: $CHANGED_FILES" | |
if echo "$CHANGED_FILES" | grep -q '^src/sandbox/'; then | |
echo "client=true" >> $GITHUB_ENV | |
fi | |
if echo "$CHANGED_FILES" | grep -q '^src/server/'; then | |
echo "server=true" >> $GITHUB_ENV | |
fi | |
- name: Run Server Tests | |
if: env.server == 'true' | |
continue-on-error: true | |
run: | | |
cd src/ | |
pytest server || echo "Server tests failed" >> result.txt | |
- name: Run Client Tests | |
if: env.client == 'true' | |
continue-on-error: true | |
run: | | |
cd src/ | |
pytest sandbox || echo "Client tests failed" >> result.txt | |
- name: Fail on Server or Client Tests | |
run: | | |
if grep -q "failed" src/result.txt; then | |
echo "Tests failed. Blocking PR." | |
exit 1 | |
fi | |
# Block merging if the job fails | |
permissions: | |
pull-requests: write |