-
Notifications
You must be signed in to change notification settings - Fork 2
200 lines (191 loc) · 5.71 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
name: main
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Hatch
run: pipx install hatch
- name: Set up python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.9"
cache: "pip"
cache-dependency-path: "pyproject.toml"
- name: Check formatting
run: hatch run ruff-format --check
- name: Check docstrings with darglint
run: hatch run darglint
- name: Type check with mypy
run: hatch run mypy
- name: Lint with ruff
run: hatch run ruff
test:
runs-on: ${{ matrix.os }}-latest
strategy:
matrix:
os: [ubuntu, macos, windows]
python-version:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "pypy3.9"
- "pypy3.10"
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Install Hatch
run: pipx install hatch
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
cache: "pip"
cache-dependency-path: "pyproject.toml"
- name: Test with pytest
env:
COVERAGE_FILE: .coverage.${{ matrix.os }}.${{ matrix.python-version }}
run: hatch run pytest-ci ${{ matrix.python-version }}
- name: Upload coverage data
uses: actions/upload-artifact@v4
with:
name: coverage-data-${{ matrix.os }}-${{ matrix.python-version }}
path: .coverage.${{ matrix.os }}.${{ matrix.python-version }}
include-hidden-files: true
coverage:
runs-on: ubuntu-latest
needs: test
outputs:
percentage: ${{ steps.percentage.outputs.percentage }}
steps:
- uses: actions/checkout@v4
- name: Install Coverage.py
run: pipx install coverage[toml]
- name: Download coverage data
uses: actions/download-artifact@v4
with:
pattern: coverage-data-*
merge-multiple: true
- name: Combine data
run: coverage combine
- name: Output coverage percentage
id: percentage
run: |
coverage json
echo "percentage=$(jq '.totals.percent_covered_display' coverage.json)" >> $GITHUB_OUTPUT
- name: Save coverage report
run: coverage report --format=markdown >> $GITHUB_STEP_SUMMARY
- name: Ensure 100% coverage
run: coverage report --fail-under=100
coverage-badge:
runs-on: ubuntu-latest
needs: coverage
if: github.event_name == 'push' && github.ref_name == 'main'
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: "coverage-badge"
- name: Calculate badge color
id: color
run: |
echo "color=$(python3 -Ic 'print(
min(
(percentage, color)
for percentage, color in [
(100, "brightgreen"),
(90, "green"),
(70, "yellowgreen"),
(50, "yellow"),
(30, "orange"),
(0, "red"),
]
if percentage >= int(${{ needs.coverage.outputs.percentage }})
)[1]
)')" >> $GITHUB_OUTPUT
- name: Update JSON file
run: |
jq -n \
--argjson schemaVersion 1 \
--arg label coverage \
--arg message ${{ needs.coverage.outputs.percentage }}% \
--arg color ${{ steps.color.outputs.color }} \
'$ARGS.named' > coverage-badge.json
- name: Create commit
run: |
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git commit -am "Update coverage" && git push || true
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Hatch
run: pipx install hatch
- name: Build project
run: hatch build
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts
path: dist/*
if-no-files-found: error
pypi-publish:
runs-on: ubuntu-latest
needs:
- lint
- test
- coverage
- build
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
environment: pypi-publish
permissions:
id-token: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: artifacts
path: dist
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
lint-spec-parser:
runs-on: ubuntu-latest
defaults:
run:
working-directory: spec_parser
steps:
- uses: actions/checkout@v4
- name: Install Poetry
run: pipx install poetry
- name: Set up python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.9"
cache: "poetry"
cache-dependency-path: "spec_parser/poetry.lock"
- name: Install dependencies
run: poetry install --sync
- name: Check formatting
run: poetry run poe ruff-format --check
- name: Type check with mypy
run: poetry run poe mypy
- name: Lint with ruff
run: poetry run poe ruff
dummy-required-job:
runs-on: ubuntu-latest
needs:
- lint
- test
- coverage
- build
- lint-spec-parser
if: always()
steps:
- run: exit 1
if: ${{ contains( needs.*.result, 'failure' ) || contains( needs.*.result, 'cancelled' ) }}