-
Notifications
You must be signed in to change notification settings - Fork 2
135 lines (114 loc) · 3.87 KB
/
ci.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
name: CI
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize]
permissions:
id-token: write
checks: write
pull-requests: write
contents: write
jobs:
test:
runs-on: ubuntu-latest
env:
HATCH_CACHE_DIR: ${{ github.workspace }}/.hatch_cache
HATCH_DATA_DIR: ${{ github.workspace }}/.hatch_data
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Hatch
uses: pypa/hatch@install
- name: Restore Hatch Directory
uses: actions/cache/restore@v4
id: cache-restore
with:
path: |
${{ env.HATCH_CACHE_DIR }}
${{ env.HATCH_DATA_DIR }}
key: ${{ runner.os }}-hatch-${{ hashFiles('pyproject.toml') }}
- name: Install Dependencies
if: steps.cache-restore.outputs.cache-hit != 'true'
run: |
hatch python install 3.8 3.12
- name: Install Dependencies
if: steps.cache-restore.outputs.cache-hit != 'true'
run: |
hatch env create test
- name: Cache Hatch Directory
uses: actions/cache/save@v4
if: steps.cache-restore.outputs.cache-hit != 'true'
id: cache-hatch
with:
path: |
${{ env.HATCH_CACHE_DIR }}
${{ env.HATCH_DATA_DIR }}
key: ${{ runner.os }}-hatch-${{ hashFiles('pyproject.toml') }}
- name: Run Lint
continue-on-error: true
run: |
hatch run lint:ruff check -o lint.json --output-format json
shell: bash
- name: Run Unit Tests
continue-on-error: true
shell: bash
run: |
hatch test --cover --all --parallel --junitxml=junit.xml
- name: Combine Coverage Reports
continue-on-error: true
run: |
hatch run +py=3.12 test:coverage combine
shell: bash
- name: Report coverage
continue-on-error: true
run: |
hatch run +py=3.12 test:coverage xml
shell: bash
- name: SonarQube Scan
if: always()
uses: sonarsource/[email protected]
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }}
with:
args: >
-Dsonar.tests=tests/
-Dsonar.verbose=true
-Dsonar.sources=src/
-Dsonar.projectKey=${{github.repository_owner}}_${{github.event.repository.name}}
-Dsonar.python.coverage.reportPaths=coverage.xml
-Dsonar.python.ruff.reportPaths=lint.json
- name: SonarQube Quality Gate check
id: sonarqube-quality-gate-check
uses: sonarsource/sonarqube-quality-gate-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }}
# Build and verify packages
- name: Build
run: hatch build
- name: Verify Packages
run: |
ls dist/*.tar.gz | hatch run +py=3.12 test:xargs -n1 twine check
ls dist/*.whl | hatch run +py=3.12 test:xargs -n1 twine check
shell: bash
- name: Surface failing tests
if: always()
uses: pmeier/pytest-results-action@main
with:
# A list of JUnit XML files, directories containing the former, and wildcard
# patterns to process.
# See @actions/glob for supported patterns.
path: junit.xml
# (Optional) Add a summary of the results at the top of the report
summary: true
# (Optional) Select which results should be included in the report.
# Follows the same syntax as `pytest -r`
display-options: fEX
# (Optional) Fail the workflow if no JUnit XML was found.
fail-on-empty: true
# (Optional) Title of the test results section in the workflow summary
title: Unit Test results