Skip to content

update workflow

update workflow #79

name: List and Test
on:
push:
branches:
- main
pull_request:
branches:
- "*"
jobs:
test:
name: Run Tests and Linters
strategy:
fail-fast: false
matrix:
python-version:
- "3.9"
- "3.10"
- "3.11"
os:
- ubuntu-latest
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- name: Check out
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache Poetry
uses: actions/cache@v4
with:
path: |
.venv
~/.cache/pypoetry
key: ${{ runner.os }}-poetry-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
- name: Install poetry
uses: abatilo/actions-poetry@v4
- name: Configure poetry
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
- name: Install dependencies
run: poetry install --no-interaction --with=dev
- name: Run pre-commit (skip pytest hook)
run: poetry run pre-commit run --all-files --hook-stage manual
- name: Run pytest with coverage (terminal, XML, and HTML)
run: poetry run pytest --cov=policy_inspector --cov-report=term-missing --cov-report=html
env:
PYTHONPATH: .
- name: Upload HTML coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-html-${{ matrix.os }}-py${{ matrix.python-version }}
path: htmlcov/
publish:
name: Build and Publish
if: ${{ github.ref == 'refs/heads/main' }}
needs:
- test
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install poetry
uses: abatilo/actions-poetry@v4
- name: Configure poetry
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
poetry config pypi-token.pypi $PYPI_TOKEN
- name: Build and publish the package
if: ${{ success() }}
run: poetry publish --build