Skip to content

Commit

Permalink
Hypermodern Python Cookiecutter f993d87
Browse files Browse the repository at this point in the history
  • Loading branch information
cjolowicz committed May 22, 2020
1 parent 032608b commit a6ef1c7
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 154 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/constraints.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pip==20.1
pip==20.1.1
nox==2019.11.9
poetry==1.0.5
virtualenv==20.0.21
16 changes: 0 additions & 16 deletions .github/workflows/coverage.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .github/workflows/docs.yml

This file was deleted.

12 changes: 0 additions & 12 deletions .github/workflows/release-drafter.yml

This file was deleted.

84 changes: 57 additions & 27 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,72 @@
name: Release

on:
release:
types: [published]
push:
branches:
- master

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: actions/setup-python@v2
- name: Check out the repository
uses: actions/[email protected]
with:
fetch-depth: 2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.8"
- run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip install --constraint=.github/workflows/constraints.txt nox poetry
- name: Compute cache key prefix
if: matrix.os != 'windows-latest'
id: cache_key_prefix
shell: python

- name: Upgrade pip
run: |
import hashlib
import sys
pip install --constraint=.github/workflows/constraints.txt pip
pip --version
python = "py{}.{}".format(*sys.version_info[:2])
payload = sys.version.encode() + sys.executable.encode()
digest = hashlib.sha256(payload).hexdigest()
result = "${{ runner.os }}-{}-{}-pre-commit".format(python, digest[:8])
- name: Install Poetry
run: |
pip install --constraint=.github/workflows/constraints.txt poetry
poetry --version
print("::set-output name=result::{}".format(result))
- uses: actions/[email protected]
if: matrix.os != 'windows-latest'
- name: Detect and tag new version
id: check-version
uses: salsify/[email protected]
with:
path: ~/.cache/pre-commit
key: ${{ steps.cache_key_prefix.outputs.result }}-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: |
${{ steps.cache_key_prefix.outputs.result }}-
- run: nox --force-color
- run: poetry build --ansi
- uses: pypa/[email protected]
version-command: |
poetry version | awk '{ print $2 }'
- name: Bump version for developmental release
if: "! steps.check-version.outputs.tag"
run: |
poetry version patch &&
version=$(poetry version | awk '{ print $2 }') &&
poetry version $version.dev.$(date +%s)
- name: Build package
run: |
poetry build --ansi
- name: Publish package on PyPI
if: steps.check-version.outputs.tag
uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}

- name: Publish package on TestPyPI
if: "! steps.check-version.outputs.tag"
uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.TEST_PYPI_TOKEN }}
repository_url: https://test.pypi.org/legacy/

- name: Publish the release notes
uses: release-drafter/[email protected]
with:
publish: ${{ steps.check-version.outputs.tag != '' }}
tag: ${{ steps.check-version.outputs.tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26 changes: 0 additions & 26 deletions .github/workflows/test-pypi.yml

This file was deleted.

93 changes: 72 additions & 21 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,59 @@
name: Tests
on: [push, pull_request]

on:
- push
- pull_request

jobs:
tests:
name: ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- { python-version: 3.8, os: ubuntu-latest }
- { python-version: 3.8, os: windows-latest }
- { python-version: 3.8, os: macos-latest }
- { python-version: 3.7, os: ubuntu-latest }
- { python-version: 3.6, os: ubuntu-latest }
runs-on: ${{ matrix.os }}
name: Python ${{ matrix.python-version }} (${{ matrix.os }})
- { python-version: 3.8, os: ubuntu-latest, session: "pre-commit" }
- { python-version: 3.8, os: ubuntu-latest, session: "safety" }
- { python-version: 3.8, os: ubuntu-latest, session: "mypy-3.8" }
- { python-version: 3.7, os: ubuntu-latest, session: "mypy-3.7" }
- { python-version: 3.6, os: ubuntu-latest, session: "mypy-3.6" }
- { python-version: 3.8, os: ubuntu-latest, session: "tests-3.8" }
- { python-version: 3.7, os: ubuntu-latest, session: "tests-3.7" }
- { python-version: 3.6, os: ubuntu-latest, session: "tests-3.6" }
- { python-version: 3.8, os: windows-latest, session: "tests-3.8" }
- { python-version: 3.8, os: macos-latest, session: "tests-3.8" }
- { python-version: 3.8, os: ubuntu-latest, session: "docs" }

env:
NOXSESSION: ${{ matrix.session }}

steps:
- uses: actions/[email protected]
- uses: actions/setup-python@v2
- name: Check out the repository
uses: actions/[email protected]

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Compute cache key prefix
if: matrix.os != 'windows-latest'
id: cache_key_prefix

- name: Upgrade pip
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip --version
- name: Install Poetry
run: |
pip install --constraint=.github/workflows/constraints.txt poetry
poetry --version
- name: Install Nox
run: |
pip install --constraint=.github/workflows/constraints.txt nox
nox --version
- name: Compute pre-commit cache key
if: matrix.session == 'pre-commit'
id: pre-commit-cache
shell: python
run: |
import hashlib
Expand All @@ -32,14 +65,32 @@ jobs:
result = "${{ runner.os }}-{}-{}-pre-commit".format(python, digest[:8])
print("::set-output name=result::{}".format(result))
- uses: actions/[email protected]
if: matrix.os != 'windows-latest'
- name: Restore pre-commit cache
uses: actions/[email protected]
if: matrix.session == 'pre-commit'
with:
path: ~/.cache/pre-commit
key: ${{ steps.cache_key_prefix.outputs.result }}-${{ hashFiles('.pre-commit-config.yaml') }}
key: ${{ steps.pre-commit-cache.outputs.result }}-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: |
${{ steps.cache_key_prefix.outputs.result }}-
- run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip install --constraint=.github/workflows/constraints.txt nox poetry
- run: nox --force-color
${{ steps.pre-commit-cache.outputs.result }}-
- name: Run Nox
run: |
nox --force-color
- name: Upload documentation
if: matrix.session == 'docs'
uses: actions/upload-artifact@v2
with:
name: docs
path: docs/_build

- name: Create coverage report
if: always() && matrix.session == 'tests'
run: |
nox --force-color --session=coverage -- xml
- name: Upload coverage report
if: always() && matrix.session == 'tests'
uses: codecov/[email protected]
16 changes: 13 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,20 @@ def mypy(session: Session) -> None:
@nox.session(python=python_versions)
def tests(session: Session) -> None:
"""Run the test suite."""
args = session.posargs or ["--cov"]
install_package(session)
install(session, "coverage[toml]", "pytest", "pytest-cov")
session.run("pytest", *args)
install(session, "coverage[toml]", "pytest")
session.run("coverage", "run", "--parallel", "-m", "pytest", *session.posargs)
session.notify("coverage")


@nox.session
def coverage(session: Session) -> None:
"""Produce the coverage report."""
args = session.posargs or ["report"]
install(session, "coverage[toml]")
if not session.posargs and any(Path().glob(".coverage.*")):
session.run("coverage", "combine")
session.run("coverage", *args)


@nox.session(python=python_versions)
Expand Down
Loading

0 comments on commit a6ef1c7

Please sign in to comment.