Skip to content

Commit

Permalink
Added github workflows for test, lint, docs, and publish
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Panchenko committed Mar 1, 2024
1 parent 5523ddb commit 5fe7a71
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 8 deletions.
4 changes: 1 addition & 3 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@
"include_accsr_configuration_utils": ["N", "y"],
"include_readthedocs_yaml": ["N", "y"],
"initial_version": "0.1.0",
"_copy_without_render": [
"build_scripts/release-version.sh"
]
"_copy_without_render": []
}
56 changes: 56 additions & 0 deletions {{cookiecutter.project_name}}/.github/workflows/lint_and_docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: PEP8, Types and Docs Check

on: [push, pull_request]

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Cancel previous run
uses: styfle/[email protected]
{% raw -%}
with:
access_token: ${{ github.token }}
{%- endraw %}
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: {{cookiecutter.python_version}}
# use poetry and cache installed packages, see https://github.com/marketplace/actions/python-poetry-action
{% raw -%}
- name: Install poetry
uses: abatilo/actions-poetry@v2
- name: Setup a local virtual environment (if no poetry.toml file)
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
- uses: actions/cache@v3
name: Define a cache for the virtual environment based on the dependencies lock file
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}
- name: Install the project dependencies
run: |
poetry install --with dev
- name: Lint
run: poetry run poe lint
- name: Types
run: poetry run poe type-check
- name: Docs
run: poetry run poe doc-build
- name: Prepare Pages
if: github.ref == 'refs/heads/main'
run: |
mv docs/_build/html/* public/
- name: Deploy Pages
uses: JamesIves/[email protected]
if: github.ref == 'refs/heads/main'
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: public
TARGET_FOLDER: .
CLEAN: true
SINGLE_COMMIT: true
{%- endraw %}
10 changes: 5 additions & 5 deletions {{cookiecutter.project_name}}/.github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
- name: Build and publish
env:
{% raw -%}
TWINE_USERNAME: ${{ secrets.PYPI_REPO_USER }}
TWINE_PASSWORD: ${{ secrets.PYPI_REPO_PASS }}
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
{%- endraw %}
run: |
# TODO: build dist with poetry
python setup.py sdist bdist_wheel
twine upload dist/*
if [ -z "${PYPI_TOKEN}" ]; then echo "Set the PYPI_TOKEN variable in your repository secrets"; exit 1; fi
poetry config pypi-token.pypi $PYPI_TOKEN
poetry config repositories.pypi https://pypi.org/legacy
poetry publish --build --repository pypi
48 changes: 48 additions & 0 deletions {{cookiecutter.project_name}}/.github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Ubuntu

on: [push, pull_request]

jobs:
cpu:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'ci skip')"
strategy:
matrix:
python-version: [{{cookiecutter.python_version}}]
{% raw -%}
steps:
- name: Cancel previous run
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
# use poetry and cache installed packages, see https://github.com/marketplace/actions/python-poetry-action
- name: Install poetry
uses: abatilo/actions-poetry@v2
- name: Setup a local virtual environment (if no poetry.toml file)
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
- uses: actions/cache@v3
name: Define a cache for the virtual environment based on the dependencies lock file
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}
- name: Install the project dependencies
run: |
poetry install --with dev --extras "envpool"
- name: Test with pytest
run: poetry run poe test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV }}
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
{%- endraw %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Windows/MacOS

on: [push, pull_request]

jobs:
cpu-extra:
runs-on: ${{ matrix.os }}
if: "!contains(github.event.head_commit.message, 'ci skip')"
strategy:
matrix:
os: [macos-latest, windows-latest]
python-version: [{{cookiecutter.python_version}}]
{% raw -%}
steps:
- name: Cancel previous run
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
# use poetry and cache installed packages, see https://github.com/marketplace/actions/python-poetry-action
- name: Install poetry
uses: abatilo/actions-poetry@v2
- name: Setup a local virtual environment (if no poetry.toml file)
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
- uses: actions/cache@v3
name: Define a cache for the virtual environment based on the dependencies lock file
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}
- name: Install the project dependencies
# ugly as hell, but well...
# see https://github.com/python-poetry/poetry/issues/7611
run: poetry install --with dev || poetry install --with dev || poetry install --with dev
- name: Test with pytest
run: poetry run poe test-subset
{%- endraw %}
Empty file.
2 changes: 2 additions & 0 deletions {{cookiecutter.project_name}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ PYDEVD_DISABLE_FILE_VALIDATION="1"
# keep relevant parts in sync with pre-commit
[tool.poe.tasks] # https://github.com/nat-n/poethepoet
test = "pytest test --cov={{cookiecutter.project_name}} --cov-report=xml --cov-report=term-missing --durations=0 -v --color=yes"
# Adjust to a smaller set of tests if appropriate
test-subset = "pytest test --color=yes"
_black_check = "black --check ."
_ruff_check = "ruff check ."
_ruff_check_nb = "nbqa ruff docs"
Expand Down

0 comments on commit 5fe7a71

Please sign in to comment.