Skip to content

Commit a4e8ea8

Browse files
authored
Packaging (#8)
* rework readme and add makefile for convenience commands (#1) * rework setup.py and add __init__.py files (#1) * add github actions workflow, still need to add CC_TEST_REPORTER_ID secret to the repo settings (#1) * strong gitignore (#1)
1 parent 4cb00df commit a4e8ea8

File tree

12 files changed

+748
-68
lines changed

12 files changed

+748
-68
lines changed

.github/workflows/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Continous Integration Workflows
2+
3+
This package implements different workflows for CI.
4+
They are organised as follows.
5+
6+
### Documentation
7+
8+
The `documentation` workflow triggers on any push to master, builds the documentation and pushes it to the `gh-pages` branch (if the build is successful).
9+
It runs on `ubuntu-latest` and our lowest supported Python version, `Python 3.6`.
10+
11+
### Testing Suite
12+
13+
Tests are ensured in the `tests` workflow, which triggers on all pushes.
14+
It runs on a matrix of all available operating systems for all supported Python versions (currently `3.6`, `3.7`, `3.8` and `3.9`).
15+
16+
### Test Coverage
17+
18+
Test coverage is calculated in the `coverage` wokflow, which triggers on pushes to `master` and any push to a `pull request`.
19+
It runs on `ubuntu-latest` & the lowest supported Python version (`Python 3.6`), and reports the coverage results of the test suite to `CodeClimate`,
20+
21+
### Regular Testing
22+
23+
A `cron` workflow triggers every Monday at 3am (UTC time) and runs the full testing suite, on all available operating systems and supported Python versions.
24+
It also runs on `Python 3.x` so that newly released Python versions that would break tests are automatically detected.
25+
26+
### Publishing
27+
28+
Publishing to `PyPI` is done through the `publish` workflow, which triggers anytime a `release` is made of the Github repository.
29+
It builds a `wheel`, checks it, and pushes to `PyPI` if checks are successful.

.github/workflows/coverage.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Runs all tests and pushes coverage report to codeclimate
2+
name: Coverage
3+
4+
defaults:
5+
run:
6+
shell: bash
7+
8+
on: # Runs on all push events to master branch and any push related to a pull request
9+
push:
10+
branches:
11+
- master
12+
pull_request: # so that codeclimate gets coverage and reports on the diff
13+
14+
jobs:
15+
coverage:
16+
name: ${{ matrix.os }} / ${{ matrix.python-version }}
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
matrix: # only lowest supported Python on latest ubuntu
20+
os: [ubuntu-latest]
21+
python-version: [3.6]
22+
23+
steps:
24+
- uses: actions/checkout@v2
25+
26+
- name: Set up Python ${{ matrix.python-version }}
27+
uses: actions/setup-python@v1
28+
with:
29+
python-version: ${{ matrix.python-version }}
30+
31+
- name: Get full Python version
32+
id: full-python-version
33+
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
34+
35+
- name: Set up cache
36+
uses: actions/cache@v2
37+
id: cache
38+
with:
39+
path: .venv
40+
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
41+
42+
- name: Ensure cache is healthy
43+
if: steps.cache.outputs.cache-hit == 'true'
44+
run: pip --version >/dev/null 2>&1 || rm -rf .venv
45+
46+
- name: Upgrade pip, setuptools and wheel
47+
run: |
48+
python -m pip install --upgrade pip
49+
pip install setuptools wheel
50+
51+
- name: Install package
52+
run: pip install '.[test]'
53+
54+
- name: Set up env for CodeClimate (push)
55+
run: |
56+
echo "GIT_BRANCH=$GITHUB_REF" >> $GITHUB_ENV
57+
echo "GIT_COMMIT_SHA=$GITHUB_SHA" >> $GITHUB_ENV
58+
if: github.event_name == 'push'
59+
60+
- name: Set up env for CodeClimate (pull_request)
61+
env:
62+
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
63+
run: |
64+
echo "GIT_BRANCH=$GITHUB_HEAD_REF" >> $GITHUB_ENV
65+
echo "GIT_COMMIT_SHA=$PR_HEAD_SHA" >> $GITHUB_ENV
66+
if: github.event_name == 'pull_request'
67+
68+
- name: Prepare CodeClimate binary
69+
env:
70+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
71+
run: |
72+
curl -LSs 'https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64' >./cc-test-reporter;
73+
chmod +x ./cc-test-reporter
74+
./cc-test-reporter before-build
75+
76+
- name: Run all tests
77+
run: python -m pytest --cov-report xml --cov=tfs
78+
79+
- name: Push Coverage to CodeClimate
80+
if: ${{ success() }} # only if tests were successful
81+
env:
82+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
83+
run: ./cc-test-reporter after-build

.github/workflows/cron.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Runs all tests on master everyday at 10 am (UTC time)
2+
name: Cron Testing
3+
4+
defaults:
5+
run:
6+
shell: bash
7+
8+
on: # Runs on master branch on Mondays at 3am UTC time
9+
schedule:
10+
- cron: '* 3 * * mon'
11+
12+
jobs:
13+
tests:
14+
name: ${{ matrix.os }} / ${{ matrix.python-version }}
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
matrix:
18+
os: [ubuntu-16.04, ubuntu-18.04, ubuntu-20.04, macos-latest, windows-latest]
19+
python-version: [3.6, 3.7, 3.8, 3.9, 3.x] # crons should always run latest python hence 3.x
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
24+
- name: Set up Python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v1
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
29+
- name: Get full Python version
30+
id: full-python-version
31+
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
32+
33+
- name: Set up cache
34+
uses: actions/cache@v2
35+
id: cache
36+
with:
37+
path: .venv
38+
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
39+
40+
- name: Ensure cache is healthy
41+
if: steps.cache.outputs.cache-hit == 'true'
42+
run: pip --version >/dev/null 2>&1 || rm -rf .venv
43+
44+
- name: Upgrade pip, setuptools and wheel
45+
run: |
46+
python -m pip install --upgrade pip
47+
pip install setuptools wheel
48+
49+
- name: Install package
50+
run: pip install '.[test]'
51+
52+
- name: Run all tests
53+
run: python -m pytest
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Build documentation
2+
name: Build and upload documentation
3+
4+
defaults:
5+
run:
6+
shell: bash
7+
8+
on: # Runs on any push event to master
9+
push:
10+
branches:
11+
- 'master'
12+
13+
jobs:
14+
documentation:
15+
name: ${{ matrix.os }} / ${{ matrix.python-version }}
16+
runs-on: ${{ matrix.os }}
17+
strategy:
18+
matrix: # only lowest supported Python on latest ubuntu
19+
os: [ubuntu-latest]
20+
python-version: [3.6]
21+
22+
steps:
23+
- uses: actions/checkout@v2
24+
25+
- name: Set up Python ${{ matrix.python-version }}
26+
uses: actions/setup-python@v1
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
30+
- name: Get full Python version
31+
id: full-python-version
32+
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
33+
34+
- name: Set up cache
35+
uses: actions/cache@v2
36+
id: cache
37+
with:
38+
path: .venv
39+
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
40+
41+
- name: Ensure cache is healthy
42+
if: steps.cache.outputs.cache-hit == 'true'
43+
run: pip --version >/dev/null 2>&1 || rm -rf .venv
44+
45+
- name: Upgrade pip, setuptools and wheel
46+
run: |
47+
python -m pip install --upgrade pip
48+
pip install setuptools wheel twine
49+
50+
- name: Install package
51+
run: pip install '.[doc]'
52+
53+
- name: Build documentation
54+
run: python -m sphinx -b html doc ./doc_build -d ./doc_build
55+
56+
- name: Upload documentation to gh-pages
57+
if: ${{ success() }}
58+
uses: JamesIves/[email protected]
59+
with:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
BRANCH: gh-pages
62+
FOLDER: doc_build

.github/workflows/publish.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Publishes to PyPI upon creation of a release
2+
name: Upload Package to PyPI
3+
4+
defaults:
5+
run:
6+
shell: bash
7+
8+
on: # Runs everytime a release is added to the repository
9+
release:
10+
types: [created]
11+
12+
jobs:
13+
deploy:
14+
name: ${{ matrix.os }} / ${{ matrix.python-version }}
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
matrix: # only lowest supported Python on latest ubuntu
18+
os: [ubuntu-latest]
19+
python-version: [3.6]
20+
21+
22+
steps:
23+
- uses: actions/checkout@v2
24+
25+
- name: Set up Python ${{ matrix.python-version }}
26+
uses: actions/setup-python@v1
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
30+
- name: Get full Python version
31+
id: full-python-version
32+
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
33+
34+
- name: Set up cache
35+
uses: actions/cache@v2
36+
id: cache
37+
with:
38+
path: .venv
39+
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
40+
41+
- name: Ensure cache is healthy
42+
if: steps.cache.outputs.cache-hit == 'true'
43+
run: pip --version >/dev/null 2>&1 || rm -rf .venv
44+
45+
- name: Upgrade pip, setuptools and wheel
46+
run: |
47+
python -m pip install --upgrade pip
48+
pip install setuptools wheel twine
49+
50+
- name: Build and check build
51+
run: |
52+
python setup.py sdist bdist_wheel
53+
twine check dist/*
54+
55+
- name: Build and publish
56+
if: ${{ success() }}
57+
env:
58+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
59+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
60+
run: |
61+
python setup.py sdist bdist_wheel
62+
twine check dist/*
63+
twine upload dist/*

.github/workflows/tests.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Runs all tests not flagged as "extended" with a pytest marker
2+
name: Tests
3+
4+
defaults:
5+
run:
6+
shell: bash
7+
8+
on: [push] # Runs on all push events to any branch
9+
10+
11+
jobs:
12+
tests:
13+
name: ${{ matrix.os }} / ${{ matrix.python-version }}
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
matrix:
17+
os: [ubuntu-16.04, ubuntu-18.04, ubuntu-20.04, macos-latest, windows-latest]
18+
python-version: [3.6, 3.7, 3.8, 3.9]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v1
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
28+
- name: Get full Python version
29+
id: full-python-version
30+
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
31+
32+
- name: Set up cache
33+
uses: actions/cache@v2
34+
id: cache
35+
with:
36+
path: .venv
37+
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
38+
39+
- name: Ensure cache is healthy
40+
if: steps.cache.outputs.cache-hit == 'true'
41+
run: pip --version >/dev/null 2>&1 || rm -rf .venv
42+
43+
- name: Upgrade pip, setuptools and wheel
44+
run: |
45+
python -m pip install --upgrade pip
46+
pip install setuptools wheel
47+
48+
- name: Install package
49+
run: pip install '.[test]'
50+
51+
- name: Run basic tests
52+
run: python -m pytest

0 commit comments

Comments
 (0)