generated from iai-group/template-project
-
Notifications
You must be signed in to change notification settings - Fork 0
204 lines (170 loc) · 5.6 KB
/
ci.yaml
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
name: build
on:
pull_request:
types:
- opened
- reopened
- synchronize
paths-ignore:
- "**.md"
env:
REPO_NAME: ${{ github.event.repository.name }}
jobs:
pre-commit:
if: always()
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: "3.9"
cache: "pip"
- name: Install Dependencies
run: |
pip install --upgrade pip
pip install -r requirements.txt
- name: Install Graphviz
uses: tlylt/install-graphviz@v1
- name: Run black
shell: bash
run: pre-commit run black --all-files
- name: Run flake8
shell: bash
run: pre-commit run flake8 --all-files
- name: Run docformatter
shell: bash
run: pre-commit run docformatter --all-file
- name: Run pydocstyle
shell: bash
run: pre-commit run pydocstyle --all-file
mypy:
if: always()
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: "3.9"
cache: "pip"
- name: Install Dependencies
run: |
pip install --upgrade pip
pip install -r requirements.txt
- name: Install Graphviz
uses: tlylt/install-graphviz@v1
- name: Run mypy
shell: bash
run: pre-commit run mypy --all-file
build-and-test:
name: "Build and Test Python 3.9"
runs-on: ubuntu-latest
if: always()
strategy:
max-parallel: 5
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.9
cache: "pip"
- name: Install Dependencies
run: |
pip install --upgrade pip
pip install -r requirements.txt
pip install pytest-github-actions-annotate-failures
- name: Install graphviz
uses: tlylt/install-graphviz@v1
- name: PyTest with code coverage
continue-on-error: true
run: |
pytest --junitxml pytest.xml --cov=. --cov-report=term-missing --cov-report=xml --cov-branch | tee pytest-coverage.txt
- name: Upload Coverage Results txt
if: always()
uses: actions/upload-artifact@v3
with:
name: coverage-results-txt
path: ./pytest-coverage.txt
- name: Upload Coverage Results xml
if: always()
uses: actions/upload-artifact@v3
with:
name: coverage-results-xml
path: ./coverage.xml
- name: Upload Unit Test Results
if: always()
uses: actions/upload-artifact@v3
with:
name: unit-test-py39
path: ./pytest.xml
publish-test-results:
name: "Publish Unit Tests Results"
needs: build-and-test
runs-on: ubuntu-latest
if: always()
timeout-minutes: 20
steps:
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
with:
files: artifacts/unit-test-py39/*.xml
- name: Pytest coverage comment in pull-request
uses: MishaKav/pytest-coverage-comment@main
with:
default-branch: main
pytest-coverage-path: artifacts/coverage-results-txt/pytest-coverage.txt
hide-badge: true
hide-report: false
create-new-comment: false
hide-comment: false
report-only-changed-files: true
- name: Get the Coverage
shell: bash
run: |
regex='<coverage.+line-rate="([0-9).[0-9]+)".+>'
line=$(grep -oP $regex artifacts/coverage-results-xml/coverage.xml)
[[ $line =~ $regex ]]
coverage=$( bc <<< ${BASH_REMATCH[1]}*100 )
if (( $(echo "$coverage > 90" |bc -l) )); then
COLOR=green
else
COLOR=red
fi
echo "COVERAGE=${coverage%.*}%" >> $GITHUB_ENV
echo "COLOR=$COLOR" >> $GITHUB_ENV
- name: Create the Badge
uses: schneegans/dynamic-badges-action@v1.6.0
with:
auth: ${{ secrets.GIST_SECRET }}
gistID: 8446f35dc373966dc971fb9237483cce
filename: coverage.${{ env.REPO_NAME }}.${{ github.event.number }}.json
label: coverage
message: ${{ env.COVERAGE }}
color: ${{ env.COLOR }}
- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: Current Branch | Main Branch |
- name: Create coverage comment
uses: peter-evans/create-or-update-comment@v2.1.0
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Current Branch | Main Branch |
| ------ | ------ |
![Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/NoB0/8446f35dc373966dc971fb9237483cce/raw/coverage.${{ env.REPO_NAME }}.${{ github.event.number }}.json) | ![Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/NoB0/8446f35dc373966dc971fb9237483cce/raw/coverage.${{ env.REPO_NAME }}.main.json) |
edit-mode: replace