-
Notifications
You must be signed in to change notification settings - Fork 11
157 lines (142 loc) · 7.15 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
# actions can be run locally using act and docker, on Fedora 37 also with podman, using:
# https://github.com/nektos/act
# sudo dnf install -y act-cli podman-docker
# act --bind --container-daemon-socket $XDG_RUNTIME_DIR/podman/podman.sock -W .github/workflows/main.yml
name: Unit tests
concurrency: # On new workflow, cancel old workflows from the same PR, branch or tag:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
# 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]
env:
PYTHONWARNINGS: "ignore:DEPRECATION"
PIP_ROOT_USER_ACTION: "ignore" # For local testing using act-cli
PIP_NO_WARN_SCRIPT_LOCATION: "0" # For local testing using act-cli
PIP_DISABLE_PIP_VERSION_CHECK: "1" # Reduce noise in logs
jobs:
pre-commit:
env:
SKIP: pytest,pytype,no-commit-to-branch
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.11
- uses: pre-commit/[email protected]
- uses: pre-commit-ci/[email protected]
if: always()
test:
strategy:
# See: https://github.com/xenserver/python-libs/pull/26#discussion_r1179482169
# max-parallel: 1
# Want to get the results of all the tests, don't terminate all on a fail:
fail-fast: false
matrix:
include:
- python-version: '3.11'
os: ubuntu-22.04
- python-version: '3.12'
os: ubuntu-22.04
- python-version: '3.13'
os: ubuntu-22.04
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed by diff-cover to get the changed lines: origin/master..HEAD
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Python 2.7 from Ubuntu 20.04 using apt-get install
if: ${{ matrix.os == 'ubuntu-20.04' }}
run: sudo apt-get update && sudo apt-get install -y python2-dev
- name: Install missing cpio in containers of nektos/act
if: ${{ github.actor == 'nektos/act'}}
run: apt-get update && apt-get install -y cpio
- name: Run of tox on ubuntu-latest
if: ${{ startsWith(matrix.python-version, '3.') && matrix.python-version != 3.6 }}
run: |
pip install 'virtualenv<20.22' 'tox==4.5.1' tox-gh-actions
tox --workdir .github/workflows/.tox --recreate
- name: Select the coverage file for upload
if: |
( matrix.python-version == '3.6' || matrix.python-version == '3.11' ) &&
( !cancelled() && github.actor != 'nektos/act' )
id: coverage
run: mv $( ls -t .github/workflows/.tox/*/log/.coverage | head -1 ) .coverage
# The new reliable Codecov upload requires Codecov to query the GitHub API to check
# the repo and the commit. The repo (or organisation) owner needs to login to
# codecov, generated the CODECOV_TOKEN and save it as a secret in the ORG or the repo:
# https://docs.codecov.com/docs/adding-the-codecov-token
# Links to get and set the token:
# Get the CODECOV_TOKEN: https://app.codecov.io/gh/xenserver/python-libs/settings
# Set the CODE_COV_TOKEN: https://github.com/xenserver/python-libs/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 (fallback, legacy Node.js 16 action)
# If CODECOV_TOKEN is not set, use the legacy tokenless Codecov action:
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
# To reduce chances of GitHub's API throttling to hit this upload, only run the
# upload for the py38-covcombine-check job running on Ubuntu-20.04, which is the
# one we need. And only run it for PRs and the master branch, not for pushes.
# This reduces the number of uploads and the chance of hitting the rate limit
# by a factor of 6.
if: |
steps.coverage.outcome == 'success' &&
!env.CODECOV_TOKEN && !cancelled() &&
matrix.os == 'ubuntu-20.04' && github.actor != 'nektos/act' &&
( github.event.pull_request.number || github.ref == 'refs/heads/master' )
uses: codecov/codecov-action@v3
with:
directory: .github/workflows/.tox/py38-covcombine-check/log
env_vars: OS,PYTHON
# Use fail_ci_if_error: false as explained the big comment above:
# Not failing this job in this case is ok because the tox CI checks also contain
# a diff-cover check which would fail on changed lines missing coverage.
# The Codecov CLI is more reliable and should be used if the CODECOV_TOKEN is set.
# The Codecov CLI is used in the next step when CODECOV_TOKEN is set.
fail_ci_if_error: false
flags: unittest
name: py27-py38-combined
verbose: true
- name: Upload coverage reports to Codecov (used when secrets.CODECOV_TOKEN is set)
# If CODECOV_TOKEN is set, use the new Codecov CLI to upload the coverage reports
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
if: |
env.CODECOV_TOKEN && !cancelled() && github.actor != 'nektos/act' &&
steps.coverage.outcome == 'success' && matrix.os == 'ubuntu-20.04'
run: >
set -euxv;
mv .github/workflows/.tox/py38-covcombine-check/log/coverage.xml cov.xml;
curl -O https://cli.codecov.io/latest/linux/codecov; sudo chmod +x codecov;
./codecov upload-process --report-type coverage
--name "CLI Upload for ${{ env.PYTHON_VERSION }}"
--git-service github --fail-on-error --file cov.xml --disable-search
--flag python${{ env.PYTHON_VERSION }}
continue-on-error: false # Fail the job if the upload with CODECOV_TOKEN fails
- if: steps.coverage.outcome == 'success'
name: Upload coverage reports to Coveralls
env:
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: ${{ format('python{0}', steps.python.outputs.python-version ) }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: pip install coveralls && coveralls --service=github
# For combined coverage of 2.7, 3.8 and 3.11 we upload to Coveralls in parallel mode.
# To view the Coveralls results from the PR, click on the "Details" link to the right
# of the Coveralls Logo in the Checks section of the PR.
finish-coverage-upload:
if: github.actor != 'nektos/act'
needs: test
runs-on: ubuntu-latest
steps:
- name: Finish the coverage upload to Coveralls
uses: coverallsapp/github-action@v1
with:
parallel-finished: true