-
Notifications
You must be signed in to change notification settings - Fork 1
130 lines (112 loc) · 4.08 KB
/
tests_and_coverage.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
name: Tests and Coverage
on:
push:
branches: ['testing']
pull_request:
branches: ['main', 'master']
workflow_dispatch:
jobs:
tests:
name: Python ${{ matrix.python_version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
python_version:
- '3.13'
- '3.12'
- '3.11'
- '3.9'
- '3.8'
- '3.7'
- '3.6'
- 'pypy3.10'
os: ['ubuntu-20.04', 'windows-latest']
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: List the modified files
run: echo "FILES_MODIFIED=$(git diff --name-only HEAD HEAD^ | xargs)" >> $GITHUB_ENV
if: ${{ !startsWith(matrix.os, 'windows-') }}
- name: List the modified files (Windows)
run: |
$FILES_MODIFIED = $(git diff --name-only HEAD HEAD^) -join ' '
echo "FILES_MODIFIED=$FILES_MODIFIED" | Out-File -FilePath $env:GITHUB_ENV
if: ${{ startsWith(matrix.os, 'windows-') }}
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}
if: ${{ contains(env.FILES_MODIFIED, '.py') }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade coverage
if: ${{ contains(env.FILES_MODIFIED, '.py') }}
- name: Lint
run: |
python -m pip install --upgrade bandit
python -m bandit --recursive tremolo/
python -m pip install --upgrade flake8
python -m flake8 .
if: |
contains(env.FILES_MODIFIED, '.py') &&
matrix.os == 'ubuntu-20.04' && matrix.python_version == '3.13'
- name: Run tests
run: python alltests.py
if: ${{ contains(env.FILES_MODIFIED, '.py') && matrix.python_version != '3.13' }}
- name: Run tests with coverage
run: |
python -m coverage run alltests.py
python -m coverage combine
mkdir artifact && mv .coverage artifact/.coverage.${{ matrix.os }}
if: |
contains(env.FILES_MODIFIED, '.py') &&
matrix.python_version == '3.13' && !startsWith(matrix.os, 'windows-')
- name: Run tests with coverage (Windows)
shell: cmd
run: |
python -m coverage run alltests.py
python -m coverage combine
mkdir artifact && move .coverage artifact\.coverage.windows
if: |
contains(env.FILES_MODIFIED, '.py') &&
matrix.python_version == '3.13' && startsWith(matrix.os, 'windows-')
- uses: actions/upload-artifact@v3
with:
path: artifact
include-hidden-files: true
if: ${{ contains(env.FILES_MODIFIED, '.py') && matrix.python_version == '3.13' }}
report:
name: Upload coverage to SonarCloud Scan
needs: ['tests']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: List the modified files
run: echo "FILES_MODIFIED=$(git diff --name-only HEAD HEAD^ | xargs)" >> $GITHUB_ENV
- name: Install dependencies
run: |
python -m venv --system-site-packages .local
echo "$HOME/.local/bin" >> $GITHUB_PATH
python -m pip install --upgrade pip
python -m pip install --upgrade coverage
if: ${{ contains(env.FILES_MODIFIED, '.py') }}
- uses: actions/download-artifact@v3
if: ${{ contains(env.FILES_MODIFIED, '.py') }}
- run: |
tree -L 2
- name: Combine and view report
run: |
python -m coverage combine artifact
python -m coverage report --show-missing --skip-covered
python -m coverage xml
if: ${{ contains(env.FILES_MODIFIED, '.py') }}
- uses: sonarsource/sonarcloud-github-action@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: ${{ contains(env.FILES_MODIFIED, '.py') }}