-
Notifications
You must be signed in to change notification settings - Fork 12
240 lines (233 loc) · 9.17 KB
/
test-python-plugin-example.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# GitHubActions for testing
# read the docs: https://help.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow
name: PythonPluginExample Test
on:
workflow_dispatch:
push:
branches: [ 'master', '3.0-dev' ]
paths:
- '.github/workflows/test-python-plugin-example.yaml'
- 'python-plugin-example/**'
pull_request:
branches: [ 'master', '3.0-dev' ]
paths:
- '.github/workflows/test-python-plugin-example.yaml'
- 'python-plugin-example/**'
defaults:
run:
working-directory: python-plugin-example
env:
project-directory: python-plugin-example
reports-directory: reports
reports-artifact: reports
coverage-artifact: coverage
latest-python-version: '3.9'
jobs:
test:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
env:
coverage-artifact-dir: _coverage
strategy:
fail-fast: false
matrix:
include:
# check the style
- name: 'Style'
os: ubuntu-latest
python: '3.9' # should be ${{ env.latest-python-version }}
toxenv: tests_start, style
no-unit-test: true
# check latest Python for all OS
- name: Linux
os: 'ubuntu-latest'
python: '3.9' # should be ${{ env.latest-python-version }}
toxenv: tests_start, py39
- name: Windows
os: windows-latest
python: '3.9' # should be ${{ env.latest-python-version }}
toxenv: tests_start, py39
- name: 'MacOs'
os: macos-latest
python: '3.9' # should be ${{ env.latest-python-version }}
toxenv: tests_start, py39
# check older Python
- name: '3.8'
os: ubuntu-latest
python: '3.8'
toxenv: tests_start, py38
- name: '3.7'
os: ubuntu-latest
python: '3.7'
toxenv: tests_start, py37
- name: '3.6'
os: ubuntu-latest
python: '3.6'
toxenv: tests_start, py36
steps:
- name: Fetch Code
# see https://github.com/actions/checkout
uses: actions/checkout@v2
- name: Setup Python ${{ matrix.python_version }}
# see https://github.com/actions/setup-python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Get pip cache dir
id: pip-cache
# as shown here: https://github.com/actions/cache/blob/master/examples.md#using-pip-to-get-cache-location
run: echo "::set-output name=dir::$(python -m pip cache dir)"
- name: Setup pip cache dir
continue-on-error: true
# see https://github.com/actions/cache
uses: actions/[email protected]
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: pip-${{ runner.os }}-${{ matrix.python }}-${{ hashFiles(format('{0}/requirements/*.txt', env.project-directory)) }}
restore-keys: pip-${{ runner.os }}-${{ matrix.python }}-
- name: Install dependencies
run: |
python -m pip install -U wheel setuptools pip
python -m pip install tox -c requirements/tox.txt
- name: Test ${{ env.project-directory }}
id: tests
run:
python -m tox -r -s false --
--junit-xml=${{ env.reports-directory }}/pytests/${{ runner.os }}-${{ matrix.python }}.xml
-o junit_suite_name=${{ runner.os }}-${{ matrix.python }}
env:
TOXENV: ${{ matrix.toxenv }}
TOX_PARALLEL_NO_SPINNER: 1
# has some issues with multiple parallel runs -- reports are sent to wrong run some times
# - name: Publish pytest results
# if: ${{ ! cancelled() && ! matrix.no-unit-test }}
# # see https://github.com/mikepenz/action-junit-report
# uses: mikepenz/action-junit-report@v1
# with:
# check_name: Pytests Report ${{ matrix.name }} PythonPluginExample
# report_paths: ${{ env.project-directory }}/${{ env.reports-directory }}/pytests/${{ runner.os }}-${{ matrix.python }}.xml
# github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Artifact reports
if: ${{ ! cancelled() && ! matrix.no-unit-test }}
# see https://github.com/actions/upload-artifact
uses: actions/upload-artifact@v2
with:
name: ${{ env.reports-artifact }}
path: ${{ env.project-directory }}/${{ env.reports-directory }}/
if-no-files-found: error
- name: Rename coverage for artifact
if: ${{ ! cancelled() && ! matrix.no-unit-test }}
run: |
mkdir ${{ env.coverage-artifact-dir }}
mv .coverage ${{ env.coverage-artifact-dir }}/${{ runner.os }}-${{ matrix.python }}.coverage
- name: Artifact coverage
if: ${{ ! cancelled() && ! matrix.no-unit-test }}
# see https://github.com/actions/upload-artifact
uses: actions/upload-artifact@v2
with:
name: ${{ env.coverage-artifact }}
path: ${{ env.project-directory }}/${{ env.coverage-artifact-dir }}/
if-no-files-found: error
- name: Tidy pip cache dir
if: ${{ always() }}
run: python -m pip cache remove 'nichtparasoup*' || true
test-reporting_merge:
name: Merge test reports
needs: [ 'test' ]
# jus wait until 'test' finished, but run regardless of the outcome
if: ${{ ! cancelled() }}
runs-on: ubuntu-latest
env:
coverage-artifact-dir: _coverage
steps:
- name: Fetch Code
# see https://github.com/actions/checkout
uses: actions/checkout@v2
- name: Fetch reports
# see https://github.com/actions/download-artifact
uses: actions/download-artifact@v2
with:
name: ${{ env.reports-artifact }}
path: ${{ env.project-directory }}/${{ env.reports-directory }}
- name: Fetch coverage
# see https://github.com/actions/download-artifact
uses: actions/download-artifact@v2
with:
name: ${{ env.coverage-artifact }}
path: ${{ env.project-directory }}/${{ env.coverage-artifact-dir }}
- name: Setup Python
# see https://github.com/actions/setup-python
uses: actions/setup-python@v2
with:
python-version: ${{ env.latest-python-version }}
- name: Get pip cache dir
id: pip-cache
# as shown here: https://github.com/actions/cache/blob/master/examples.md#using-pip-to-get-cache-location
run: echo "::set-output name=dir::$(python -m pip cache dir)"
- name: Setup pip cache dir
continue-on-error: true
# see https://github.com/actions/cache
uses: actions/[email protected]
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: pip-${{ runner.os }}-${{ env.latest-python-version }}-${{ hashFiles(format('{0}/requirements/*.txt', env.project-directory)) }}
restore-keys: pip-${{ runner.os }}-${{ env.latest-python-version }}-
- name: Install dependencies
run: |
python -m pip install -U wheel setuptools pip
python -m pip install coverage tox -c requirements/tests.txt -c requirements/tox.txt
- name: Merge pytest-reports
run: python -m tox -r -e pytests_merge
- name: Merge pytest-coverage
run: |
python -m coverage combine ${{ env.coverage-artifact-dir }}/*
python -m tox -r -e coverage_report
- name: Artifact combined reports
# see https://github.com/actions/upload-artifact
uses: actions/upload-artifact@v2
with:
name: ${{ env.reports-artifact }}
path: ${{ env.project-directory }}/${{ env.reports-directory }}/
if-no-files-found: error
can-sonar:
runs-on: ubuntu-latest
outputs:
has_token: ${{ steps.has-token.outputs.has_token }}
steps:
- id: has-token
run: |
if [[ -n "$SONAR_TOKEN" ]]
then
echo '::set-output name=has_token::false'
fi
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
working-directory: .
sonarcloud:
name: SonarScanner
needs: [ 'can-sonar', 'test', 'test-reporting_merge' ]
# have forks backed-up: Anyone without write access to a repository cannot read and use secrets
if: ${{ needs.can-sonar.outputs.has_token && ! cancelled() && github.repository_owner == 'k4cg' }}
runs-on: ubuntu-latest
steps:
- name: Fetch Code
# see https://github.com/actions/checkout
uses: actions/checkout@v2
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
- name: Fetch reports
continue-on-error: true
# see https://github.com/actions/download-artifact
uses: actions/download-artifact@v2
with:
name: ${{ env.reports-artifact }}
path: ${{ env.project-directory }}/${{ env.reports-directory }}
- name: SonarCloud Scan
# see https://github.com/SonarSource/sonarcloud-github-action
uses: sonarsource/[email protected]
with:
projectBaseDir: ${{ env.project-directory }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}