-
Notifications
You must be signed in to change notification settings - Fork 10
275 lines (242 loc) · 11.9 KB
/
main.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
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#--------------------------------------------------------------------------------------
# This GitHub Actions workflow can be run locally using https://github.com/nektos/act
#
# act normally uses docker, but it can also be run using podman on Fedora 37:
# dnf install act-cli podman
# podman system service -t 0 &
# act --bind --container-daemon-socket $XDG_RUNTIME_DIR/podman/podman.sock -W .github/workflows/main.yml
#--------------------------------------------------------------------------------------
name: "Pytest test suites"
#
# The GitHub events that trigger this workflow:
# Checks can be skipped by adding "skip-checks: true" to a commit message,
# or requested by adding "request-checks: true" if disabled by default for pushes:
# https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/about-status-checks#skipping-and-requesting-checks-for-individual-commits
#
on: [push, pull_request]
# Docs: https://github.com/marketplace/actions/commit-status-updater#workflow-permissions
# and more info on https://github.com/actions/first-interaction/issues/10
# Allow actions in PRs from other repos to create a comment and update status:
permissions:
pull-requests: write # creating a comment
statuses: write # # updating commit status
#
# Cancel a currently running workflow from the same PR, branch or tag
# when a new workflow is triggered:
# https://stackoverflow.com/questions/66335225/how-to-cancel-previous-runs-in-the-pr-when-you-push-new-commitsupdate-the-curre
#
concurrency:
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
env:
# Setup Coveralls to for parallel coverage upload from python2 and 3 workflows
COVERALLS_PARALLEL: true
DEBIAN_FRONTEND: noninteractive
# No warnings for pip and pytest themselves; pytest enables warnings in conftest.py
PYTHONWARNINGS: ignore
# Development Mode for stronger checks: https://docs.python.org/3/library/devmode.html
PYTHONDEVMODE: yes
jobs:
container-tests:
name: "Python2: Container tests"
runs-on: ubuntu-22.04
# https://github.com/Docker-Hub-frolvlad/docker-alpine-python2
container: frolvlad/alpine-python2
steps:
- uses: actions/checkout@v4
- name: Install test tools
run: apk add --no-cache libxml2-utils bash
- name: Install python requirements
run: pip install -r requirements.txt
- name: Test sar file collection, extended by XSI-1385 with plain-text SARs
run: bash -x tests/integration/sar-file-collection.test.sh
- name: Test creating a tarball for /etc/systemd
run: bash -x tests/integration/xenserver-config-systemd.sh
python2-tests:
name: "Python2: PyLint and Pytest"
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: LizardByte/setup-python-action@master
with:
python-version: 2.7
- name: Install dependencies
run: |
if [ -f requirements.txt ]; then pip2 install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip2 install -r requirements-dev.txt; fi
pip2 install pylint==1.9.4; sudo mkdir /opt/xensource # mountpoint for tests
- name: Run pylint-1.9.4 for pylint --py3k linting (configured in .pylintrc)
run: python2 -m pylint xen-bugtool
- name: Run python2 -m pytest to execute all unit and integration tests
run: >
python2 -m pytest -v -rA
--cov xen-bugtool
--cov tests/
--junitxml=.git/pytest27.xml
--cov-report term-missing
--cov-report xml:.git/coverage27.xml
- name: Upload to Codecov (CLI uploader with CODECOV_TOKEN)
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
if: |
env.CODECOV_TOKEN && !cancelled() &&
( github.event.pull_request.number || github.ref == 'refs/heads/master' )
run: >
rm -rfv codecov;curl -O https://cli.codecov.io/latest/linux/codecov &&
sudo chmod +x codecov && ./codecov upload-process --report-type coverage
--git-service github --fail-on-error --file .git/coverage27.xml
--flag python2.7 --name "Python 2.7 CLI uploader"
continue-on-error: true
- name: Upload to Codecov (legacy Node.js 16 action, tokenless)
# If CODECOV_TOKEN is not set, use the legacy tokenless codecov action:
if: |
!env.CODECOV_TOKEN && !cancelled() &&
( github.event.pull_request.number || github.ref == 'refs/heads/master' )
uses: codecov/codecov-action@v3
env:
PYTHON: python2.7
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
directory: .git
files: coverage27.xml
flags: python2.7
env_vars: OS,PYTHON
fail_ci_if_error: false
name: "Python 2.7 Node.js uploader"
verbose: true
- name: Add Pytest 2.7 coverage comment (if write permission is available)
if: ${{ ! github.event.pull_request.head.repo.fork && github.event.pull_request.number }}
uses: MishaKav/pytest-coverage-comment@main
continue-on-error: true
with:
junitxml-path: .git/pytest27.xml
pytest-xml-coverage-path: .git/coverage27.xml
unique-id-for-comment: pytest-coverage-python27
title: Pytest Code coverage comment for Python 2.7
- name: Upload coverage reports to Coveralls
env:
COVERALLS_FLAG_NAME: python2.7
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
curl -sL https://coveralls.io/coveralls-linux.tar.gz | tar -xz
cp .git/coverage27.xml coverage.xml
./coveralls --service-name=github --format=cobertura
pre-commit:
name: "Python3: Pre-Commit Suite"
runs-on: ubuntu-22.04
env:
PYTHON_VERSION: "3.10"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # For diff-cover to get the changed lines: origin/master..HEAD
# https://www.python4data.science/en/latest/productive/git/advanced/hooks/ci.html
- uses: actions/setup-python@v5
id: python
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
- run: pip install -r requirements-dev.txt; sudo mkdir /opt/xensource
name: Install the pytest dependencies for running the pytest suite using Python3
- uses: actions/cache@v4
name: Setup cache for running pre-commit fast
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
# https://docs.python.org/3/library/devmode.html#resourcewarning-example
# If pytest runs with PYTHONDEVMODE=yes, it enables resource checks like
# unclosed file warnings. Configure GitHub to show all such warnings as
# annotations at the source location they occur in the PR code review:
- run: >
echo "::add-matcher::.github/workflows/Python-problemMatcher-status-report.json";
- uses: pre-commit/[email protected]
name: Run pre-commit checks
with:
# Show the output of the commands for the problem matcher, see above.
extra_args: --all-files --verbose
env:
PYTHONDEVMODE: yes # Enable Python3 checks. See the comment above.
# Skip the no-commit-to-branch check inside of GitHub CI (for CI on merge to master)
# TODO: For push workflows, fix check-branch-needs-rebase to work in GitHub CI.
# GitHub PR workflows are already always rebased to the target branch (on run):
SKIP: no-commit-to-branch,check-branch-needs-rebase
- uses: frabert/replace-string-action@v2
id: get_sonarcloud_project_key
with:
pattern: '(\w+)/(\w+)'
replace-with: '$1_$2'
string: ${{ github.repository }}
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@v2
if: ${{ env.SONAR_TOKEN }}
with:
args: >
-Dsonar.organization=${{ github.repository_owner }}
-Dsonar.projectKey=${{ steps.get_sonarcloud_project_key.outputs.replaced }}
-Dsonar.python.version=3.6
-Dsonar.python.coverage.reportPaths=.git/coverage.xml
-Dsonar.python.xunit.reportPath=.git/pytest.xml
-Dsonar.sources=.
-Dsonar.exclusions=tests/**
-Dsonar.tests=tests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# Codecov's tokenless upload requires Codecov to query the GitHub API to check
# the repo and the commit. Due to the massive rate of tokenless uploads, Codecov
# uploads often fail due to GitHub API rate limits. Therefore, the CODECOV_TOKEN
# should be set in the repository's secrets by the repository owner:
# https://docs.codecov.com/docs/adding-the-codecov-token
# For gh.com/xenserver/status-report, these are the links to get and set the token:
# Get: https://app.codecov.io/gh/xenserver/status-report/settings
# Set: https://github.com/xenserver/status-report/settings/secrets/actions
# Without it, the API calls are rate-limited by GitHub, and the upload may fail:
# https://github.com/codecov/feedback/issues/126#issuecomment-1932658904
- name: Upload coverage reports to Codecov
# If CODECOV_TOKEN is set, use the new Codecov CLI to upload the coverage reports
if: |
env.CODECOV_TOKEN && !cancelled() &&
( github.event.pull_request.number || github.ref == 'refs/heads/master' )
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: >
cp .git/coverage.xml coverage3.xml &&
rm -rfv codecov;curl -O https://cli.codecov.io/latest/linux/codecov &&
sudo chmod +x codecov && ./codecov upload-process --report-type coverage
--git-service github --fail-on-error --file coverage3.xml --disable-search
--flag python${{ env.PYTHON_VERSION }}
--name "CLI Upload for ${{ env.PYTHON_VERSION }}"
continue-on-error: false # Fail the job if the upload with CODECOV_TOKEN fails
- name: Upload coverage reports to Codecov (fallback, legacy Node.js 16 action)
# If CODECOV_TOKEN is not set, use the legacy tokenless Codecov action:
if: |
!env.CODECOV_TOKEN && !cancelled() &&
( github.event.pull_request.number || github.ref == 'refs/heads/master' )
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
uses: codecov/codecov-action@v3
with:
directory: .git
env_vars: OS,PYTHON
# Whether the job should fail if Codecov runs into an error during upload.
# Not failing the job in this case is ok because the pre-commit checks
# also contain a diff-cover job which would fail on missing changed lines:
fail_ci_if_error: false
flags: python${{ env.PYTHON_VERSION }}
name: "Node.js Uploader for ${{ steps.python.outputs.python-version }}"
- name: Add Pytest coverage comment (if write permission is available)
if: ${{ ! github.event.pull_request.head.repo.fork && github.event.pull_request.number }}
uses: MishaKav/pytest-coverage-comment@main
continue-on-error: true
with:
junitxml-path: .git/pytest.xml
pytest-xml-coverage-path: .git/coverage.xml
unique-id-for-comment: pre-commit-coverage
title: >
Python3 coverage comment from
https://github.com/marketplace/actions/pytest-coverage-comment
- name: Upload coverage reports to Coveralls
env:
COVERALLS_FLAG_NAME: ${{ format('python{0}', steps.python.outputs.python-version ) }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: pip install coveralls && coveralls --service=github && coveralls --finish || true