Feat: devcontainer pytest integration #397
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
| # Github Actions Workflow for CI | |
| name: CI | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| permissions: | |
| contents: read | |
| actions: read | |
| checks: write | |
| jobs: | |
| # Build devcontainers and run full pytest suite | |
| test-devcontainers: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| include: | |
| - subfolder: src/sample_cpu_project | |
| name: cpu-project | |
| - subfolder: src/sample_pytorch_gpu_project | |
| name: gpu-project | |
| fail-fast: false | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup .env file | |
| run: cp .env.example .env | |
| - name: Install devcontainer CLI | |
| run: npm install -g @devcontainers/cli | |
| - name: Build devcontainer and run pytest (${{ matrix.name }}) | |
| run: | | |
| devcontainer up --workspace-folder . --config ${{ matrix.subfolder }}/.devcontainer/devcontainer.json | |
| devcontainer exec --workspace-folder . --config ${{ matrix.subfolder }}/.devcontainer/devcontainer.json \ | |
| bash -c " | |
| cd /workspaces/repo/${{ matrix.subfolder }} && \ | |
| # Store the intermediate coverage.py SQLite DB in /tmp, which is guaranteed | |
| # to be writable inside the devcontainer; the final XML report is written | |
| # separately to /tmp/coverage.xml and then copied back into the workspace. | |
| COVERAGE_FILE=/tmp/.coverage pytest tests/ \ | |
| --junitxml=/tmp/test-results.xml \ | |
| -o junit_suite_name=${{ matrix.name }} \ | |
| --doctest-modules \ | |
| --cov=. \ | |
| --cov-config=/workspaces/repo/pyproject.toml \ | |
| --cov-report=xml:/tmp/coverage.xml && \ | |
| sed -i 's|<package name=\".\"|<package name=\"${{ matrix.name }}\"|g' /tmp/coverage.xml && \ | |
| sudo cp /tmp/test-results.xml /workspaces/repo/${{ matrix.subfolder }}/ && \ | |
| sudo cp /tmp/coverage.xml /workspaces/repo/${{ matrix.subfolder }}/" | |
| - name: Upload test results | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: test-results-${{ matrix.name }} | |
| path: ${{ matrix.subfolder }}/test-results.xml | |
| - name: Upload coverage report | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: coverage-${{ matrix.name }} | |
| path: ${{ matrix.subfolder }}/coverage.xml | |
| # Smoke test for notebooks devcontainer | |
| test-notebooks: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup .env file | |
| run: cp .env.example .env | |
| - name: Install devcontainer CLI | |
| run: npm install -g @devcontainers/cli | |
| - name: Build and smoke test notebooks devcontainer | |
| run: | | |
| devcontainer up --workspace-folder . --config notebooks/.devcontainer/devcontainer.json | |
| devcontainer exec --workspace-folder . --config notebooks/.devcontainer/devcontainer.json \ | |
| bash -c "cd /workspaces/repo && python --version && pytest --version && ruff --version" | |
| # Publish combined test results and coverage | |
| publish-test-results: | |
| needs: test-devcontainers | |
| runs-on: ubuntu-latest | |
| if: always() | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Download all test result artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: test-results-* | |
| path: test-results | |
| - name: Download all coverage artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: coverage-* | |
| path: coverage | |
| - name: Publish Test Results | |
| uses: dorny/test-reporter@v2 | |
| if: always() | |
| with: | |
| name: pytest | |
| path: 'test-results/**/*.xml' | |
| reporter: java-junit | |
| - name: Publish Code Coverage Summary Report | |
| uses: irongut/CodeCoverageSummary@v1.3.0 | |
| with: | |
| badge: true | |
| output: both | |
| format: markdown | |
| filename: 'coverage/**/*.xml' | |
| - name: Add code coverage summary to job summary | |
| run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY | |
| # Run linter on codebase | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Python 3.11 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: 3.11 | |
| - name: Install requirements | |
| run: | | |
| python -m venv venv | |
| source venv/bin/activate | |
| python -m pip install --upgrade pip | |
| pip install -r requirements-dev.txt | |
| - name: Run ruff linter | |
| run: | | |
| source venv/bin/activate | |
| ruff check --output-format github |