|
| 1 | +name: Reusable Tests |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + os: |
| 7 | + description: "Operating system name" |
| 8 | + required: true |
| 9 | + default: Ubuntu |
| 10 | + type: string |
| 11 | + image: |
| 12 | + description: "Runner image" |
| 13 | + required: true |
| 14 | + default: ubuntu-latest |
| 15 | + type: string |
| 16 | + python-version: |
| 17 | + description: "Python version to test against" |
| 18 | + required: true |
| 19 | + default: "3.10" |
| 20 | + type: string |
| 21 | + |
| 22 | +defaults: |
| 23 | + run: |
| 24 | + shell: bash |
| 25 | +env: |
| 26 | + POETRY_VERSION: 1.8.2 |
| 27 | + |
| 28 | +jobs: |
| 29 | + tests: |
| 30 | + name: ${{ inputs.os }} / Python ${{ inputs.python-version }} |
| 31 | + runs-on: ${{ inputs.image }} |
| 32 | + |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v4 |
| 35 | + |
| 36 | + - name: Set up Python ${{ inputs.python-version }} |
| 37 | + uses: actions/setup-python@v5 |
| 38 | + with: |
| 39 | + python-version: ${{ inputs.python-version }} |
| 40 | + |
| 41 | + - name: Get full Python version |
| 42 | + id: full-python-version |
| 43 | + run: echo "version=$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")" >> $GITHUB_OUTPUT |
| 44 | + |
| 45 | + - name: Bootstrap poetry (Linux and macOS) |
| 46 | + run: | |
| 47 | + curl -sSL https://install.python-poetry.org | POETRY_VERSION=${{ env.POETRY_VERSION }} python - |
| 48 | +
|
| 49 | + - name: Update PATH (Linux and macOS) |
| 50 | + if: runner.os != 'Windows' |
| 51 | + run: echo "$HOME/.local/bin" >> $GITHUB_PATH |
| 52 | + |
| 53 | + - name: Update PATH for Windows |
| 54 | + if: runner.os == 'Windows' |
| 55 | + run: echo "$APPDATA\\Python\\Scripts" >> $GITHUB_PATH |
| 56 | + |
| 57 | + - name: Configure poetry |
| 58 | + run: poetry config virtualenvs.in-project true |
| 59 | + |
| 60 | + - name: Set up cache |
| 61 | + uses: actions/cache@v4 |
| 62 | + id: cache |
| 63 | + with: |
| 64 | + path: .venv |
| 65 | + key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }} |
| 66 | + |
| 67 | + - name: Ensure cache is healthy |
| 68 | + if: steps.cache.outputs.cache-hit == 'true' |
| 69 | + run: timeout 10s poetry run pip --version || rm -rf .venv |
| 70 | + |
| 71 | + - name: Check Poetry .lock |
| 72 | + run: poetry check --lock |
| 73 | + |
| 74 | + - name: Install dependencies |
| 75 | + run: poetry install --with dev |
| 76 | + |
| 77 | + - name: Run pre-commit hooks |
| 78 | + run: poetry run make pre_commit |
| 79 | + |
| 80 | + - name: Run pytest |
| 81 | + run: poetry run pytest -v |
0 commit comments