-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (94 loc) · 3.09 KB
/
unittest.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
name: "UnitTests"
on:
# add push to main trigger for sonarcloud scan
push:
branches:
- "main"
- "master"
workflow_dispatch:
pull_request:
paths:
- "nuvla/**"
- "tests/**"
- ".github/workflows/unittest.yml"
jobs:
setup-matrix:
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.set-versions.outputs.versions }}
latest: ${{ steps.set-latest.outputs.latest }}
steps:
- id: set-versions
run: |
echo "versions=${{ vars.SUPPORTED_PYTHON_VERSIONS }}" >> $GITHUB_OUTPUT
- id: set-latest
run: |
sudo apt-get install -y jq
latest=$(echo '${{ fromJSON(vars.SUPPORTED_PYTHON_VERSIONS) }}' | jq '.[-1]')
echo "latest=$latest" >> $GITHUB_OUTPUT
run-tests:
needs: setup-matrix
runs-on: ubuntu-latest
strategy:
matrix:
python_version: ${{ fromJSON(needs.setup-matrix.outputs.versions) }}
steps:
- uses: actions/checkout@v4
- name: Install python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_version }}
cache: 'pip'
- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v4
with:
path: ~/.local # the path depends on the OS
key: poetry-${{ matrix.python_version }} # increment to reset cache
- name: Setup Poetry
uses: snok/install-poetry@v1
if: steps.cached-poetry.outputs.cache-hit != 'true'
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Install dependencies
run: |
poetry install --with=tests
- name: Run Unittests
run: >
poetry run pytest
--junitxml=test-report.xml
--cov=nuvla
--cov-report=xml
--cov-report term
--cov-config=.coveragerc
--cov-branch
- name: Install jq (For Quality Gate)
if: matrix.python_version == needs.setup-matrix.outputs.latest
run: |
sudo apt-get update
sudo apt-get install -y jq
- name: SonarCloud Scan
if: matrix.python_version == needs.setup-matrix.outputs.latest
uses: SonarSource/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}
with:
args: >
-Dsonar.python.version=${{ matrix.python_version }}
- name: SonarQube Quality Gate check
if: matrix.python_version == needs.setup-matrix.outputs.latest
uses: sonarsource/[email protected]
# Force to fail step after specific time
timeout-minutes: 5
with:
scanMetadataReportFile: .scannerwork/report-task.txt
env:
SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
if: always()
with:
check_name: "| UnitTest for Py${{ matrix.python_version }} |"
files: test-report.xml