-
Notifications
You must be signed in to change notification settings - Fork 0
158 lines (151 loc) · 4.94 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
name: CI
on:
push:
branches:
- master
- 'feature/**'
- 'hotfix/**'
tags:
- '**'
pull_request: {}
jobs:
lints:
name: Code lints
runs-on: ubuntu-latest
steps:
#----------------------------------------------
# check-out repo and set-up python
#----------------------------------------------
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8
#----------------------------------------------
# load pip cache if cache exists
#----------------------------------------------
- uses: actions/cache@v2
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 .
tests:
needs: [lints]
name: Test python ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', 'pypy-3.7']
env:
PYTHONPATH: .
PYTHON: ${{ matrix.python-version }}
steps:
#----------------------------------------------
# check-out repo and set-up environment
#----------------------------------------------
- uses: actions/checkout@v2
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- uses: snok/[email protected]
with:
virtualenvs-create: true
virtualenvs-in-project: true
#----------------------------------------------
# setup only test dependencies
#----------------------------------------------
- name: Remove lint dependencies
run: |
mv pyproject.toml ~pyproject.toml
cat ~pyproject.toml | sed '/^black =/d' | sed '/^isort =/d'| sed '/^flake8[a-zA-Z-]* =/d' > pyproject.toml
- name: Install dependencies
run: poetry install --no-interaction --no-root
#----------------------------------------------
# run tests with code coverage
#----------------------------------------------
- name: Run tests
run: |
source .venv/bin/activate
pytest --cov
env:
COVERAGE_FILE: coverage/.coverage.py${{ matrix.python-version }}
#----------------------------------------------
# store code coverage
#----------------------------------------------
- name: Store coverage files
uses: actions/upload-artifact@v2
with:
name: coverage
path: coverage
coverage-upload:
needs: [tests]
name: Coverage upload
runs-on: ubuntu-latest
steps:
#----------------------------------------------
# setup environment
#----------------------------------------------
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Setup depdendencies
run: pip install coverage
#----------------------------------------------
# prepare coverage data
#----------------------------------------------
- name: Get coverage files
uses: actions/download-artifact@v2
with:
name: coverage
path: coverage
- name: Combine coverage files
run: |
coverage combine coverage
coverage report
coverage xml
#----------------------------------------------
# upload code coverage
#----------------------------------------------
- name: Upload coverage
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml
fail_ci_if_error: true
build-deploy:
name: Build & deploy
needs: [lints, tests]
if: "success() && startsWith(github.ref, 'refs/tags/')"
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
runs-on: ubuntu-latest
steps:
#----------------------------------------------
# check-out repo and set-up python
#----------------------------------------------
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8
- uses: snok/[email protected]
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Configure poetry credentials
run: |
poetry config pypi-token.pypi "${PYPI_TOKEN}"
#----------------------------------------------
# build and deploy with poetry
#----------------------------------------------
- name: Build & deploy
run: |
poetry publish --build