Skip to content

Commit

Permalink
ci: Setup of CI and CD
Browse files Browse the repository at this point in the history
- Keep `release-please` action in a separate workflow
- Cache python env according to platform, python path (exact version) and `pyproject.toml` hash for fast CI
- Run `flakehell` and `black` (check-only) on pushes/PRs to ensure consistent codestyle
- Run `pytest` on pushes/PR on a matrix of python versions and platforms
- Upload code coverage to Codecov on pushes/PR
- For draft PRs, tests & checks are skipped
- Run `flit publish` on release to build and publish package (token stored as gh secret)

Closes #7
Co-authored-by: Mestery <mestery@pm.me>
  • Loading branch information
LeMinaw authored and fblanchetNaN committed May 15, 2021
1 parent 99ddfaf commit 39281be
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 4 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CD - Publish package

on:
release:
types: [released]

jobs:
publish:
name: Publish to PyPI
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Cache python env
uses: actions/cache@v2
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}
- name: Install deps
env:
PIP_UPGRADE: True
UPGRADE_STRATEGY: eager
run: |
python -m pip install pip flit
python -m flit install --deps develop
- name: Build and publish with Flit
env:
FLIT_USERNAME: __token__
FLIT_PASSWORD: ${{ secrets.FLIT_TOKEN }}
run: python -m flit publish
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CD - Release package
name: CD - Release Please

on:
push:
Expand Down
80 changes: 80 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: CI - Test package

on:
push:
branches: [main]
pull_request:
branches: [main]
types: [opened, reopened, synchronize, ready_for_review]


jobs:
lint:
name: Lint
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Cache python env
uses: actions/cache@v2
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}
- name: Install deps
env:
PIP_UPGRADE: True
UPGRADE_STRATEGY: eager
run: |
python -m pip install pip flit
python -m flit install --deps develop
- name: Check format with black
run: python -m black -v --check .
- name: Lint with flakehell
run: python -m flakehell lint -v

test:
name: Tests
needs: lint
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.6, 3.7, 3.8, 3.9]
runs-on: ${{ matrix.os }}
env:
_OS: ${{ matrix.os }}
_PY: ${{ matrix.python-version }}

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Cache python env
uses: actions/cache@v2
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}
- name: Install deps
env:
PIP_UPGRADE: True
UPGRADE_STRATEGY: eager
run: |
python -m pip install pip flit
python -m flit install --deps develop
- name: Run tests with pytest
run: pytest -v --cov=incipyt --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
fail_ci_if_error: true
env_vars: _OS,_PY
11 changes: 8 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dev = [
"build",
"pre-commit",
"black",
"flake8!=3.9.1",
"flake8",
"flakehell",
"flake8-bandit",
"flake8-bugbear",
Expand All @@ -49,8 +49,7 @@ dev = [
"pep8-naming",
]
test = [
"pytest-coverage",
"pytest-html",
"pytest-cov",
]
doc = [
"m2r",
Expand All @@ -63,6 +62,8 @@ exclude = [
".env",
".git",
]
# Fix combatibility with flake8 3.9.[1-2] as of writing
extended_default_ignore = []

[tool.flakehell.plugins]
flake8-bandit = ["+*"]
Expand All @@ -75,3 +76,7 @@ flake8-use-fstring = ["+*"]
pep8-naming = ["+*"]
pycodestyle = ["+*", "-W503", "-E501"]
pyflakes = ["+*"]

[tool.flakehell.exceptions."tests/*.py"]
flake8-bandit = ["-S101"] # Asserts
flake8-docstrings = ["-*"]
Empty file added tests/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions tests/test_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import incipyt # noqa: F401


def test_dummy():
assert True

0 comments on commit 39281be

Please sign in to comment.