Github Workflows: setup python CI #5
Workflow file for this run
This file contains 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
# This workflow will install Python dependencies, run tests and lint with a single version of Python | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | |
name: Python CI | |
on: | |
push: | |
branches: ["main"] | |
pull_request: | |
branches: ["main"] | |
permissions: | |
contents: read | |
jobs: | |
# linting: | |
# runs-on: ubuntu-latest | |
# steps: | |
# #---------------------------------------------- | |
# # check-out repo and set-up python | |
# #---------------------------------------------- | |
# - uses: actions/checkout@v4 | |
# - uses: actions/setup-python@v5 | |
# #---------------------------------------------- | |
# # load pip cache if cache exists | |
# #---------------------------------------------- | |
# - uses: actions/cache@v4 | |
# with: | |
# path: ~/.cache/pip | |
# key: ${{ runner.os }}-pip | |
# restore-keys: ${{ runner.os }}-pip | |
# #---------------------------------------------- | |
# # install and run linters | |
# #---------------------------------------------- | |
# - run: python -m pip install black flake8 isort | |
# - run: | | |
# flake8 . | |
# black . --check | |
# isort . | |
test: | |
# needs: linting | |
strategy: | |
fail-fast: true | |
matrix: | |
os: [ubuntu-latest, macos-latest] | |
python-version: ['3.13'] | |
runs-on: ${{ matrix.os }} | |
env: | |
ALLURE_RESULTS_PATH: 'build/${{ matrix.os }}_${{ matrix.python-version }}/allure-results' | |
ALLURE_REPORTS_PATH: 'build/${{ matrix.os }}_${{ matrix.python-version }}/allure-reports' | |
COVERAGE_REPORT_PATH: 'build/${{ matrix.os }}_${{ matrix.python-version }}/python-coverage-report' | |
steps: | |
#---------------------------------------------- | |
# check-out repo and set-up python | |
#---------------------------------------------- | |
- name: "[Python] checkout repository" | |
uses: actions/checkout@v4 | |
- name: "[Python] Setup python ${{ matrix.python-version }}" | |
id: setup-python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
#---------------------------------------------- | |
# ----- install & configure poetry ----- | |
#---------------------------------------------- | |
- name: "[Python] Install Poetry" | |
uses: snok/install-poetry@v1 | |
with: | |
virtualenvs-create: true | |
virtualenvs-in-project: true | |
virtualenvs-path: .venv | |
installer-parallel: true | |
#---------------------------------------------- | |
# load cached venv if cache exists | |
#---------------------------------------------- | |
- name: "[Python] Load cached venv" | |
id: cached-poetry-dependencies | |
uses: actions/cache@v4 | |
with: | |
path: .venv | |
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} | |
#---------------------------------------------- | |
# install dependencies if cache does not exist | |
#---------------------------------------------- | |
- name: "[Python] Install dependencies" | |
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' | |
run: poetry install --no-interaction --no-root | |
#---------------------------------------------- | |
# install your root project, if required | |
#---------------------------------------------- | |
- name: Install project | |
run: poetry install --no-interaction | |
#---------------------------------------------- | |
# run test suite | |
#---------------------------------------------- | |
- name: "[Python] Run tests" | |
run: > | |
poetry run pytest | |
--alluredir $ALLURE_RESULTS_PATH | |
--color no | |
--cov $COVERAGE_REPORT_PATH | |
--cov-report html | |
--clean | |
- name: "[Python] Create coverage report" | |
run: poetry run coverage report | |
- name: "[Python] Store coverage results" | |
uses: actions/upload-artifact@v4 | |
with: | |
name: python-coverage-report | |
path: $COVERAGE_REPORT_PATH | |
retention-days: 1 | |
- name: "[Python] Store allure test results" | |
uses: actions/upload-artifact@v4 | |
with: | |
name: allure-results | |
path: $ALLURE_RESULTS_PATH | |
retention-days: 1 |