-
Notifications
You must be signed in to change notification settings - Fork 1
164 lines (153 loc) · 4.54 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
name: Build
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
release:
types: [ "published" ]
permissions:
contents: read
concurrency:
group: main-${{ github.head_ref || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
format-checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Project
run: python -m pip install -e .
- name: Install ruff
run: |
python -m pip install ruff==0.6.1
- name: Formatting Checks
run: ruff format --check src tests
type-checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Project
run: python -m pip install -e .
- name: Install mypy
run: python -m pip install mypy==1.11.1
- name: Type Checks
run: mypy src
tests:
name: Tests / ${{ matrix.python-version }}
runs-on: ubuntu-latest
needs:
- format-checks
- type-checks
strategy:
fail-fast: false
matrix:
python-version: [ "3.8", "3.9", "3.10" ]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Project
run: python -m pip install -e .
- name: Install Coverage
run: python -m pip install "coverage[toml]==7.6.1"
- name: Run Tests ${{ matrix.python-version }}
run: python -m coverage run -m unittest discover -s tests
- uses: actions/upload-artifact@v3
with:
name: cov-${{ matrix.python-version }}
path: .coverage.*
retention-days: 5
coverage:
runs-on: ubuntu-latest
needs:
- tests
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Coverage
run: python -m pip install "coverage[toml]==7.6.1"
- name: Download Coverage Data
uses: actions/download-artifact@v3
- name: Prepare Coverage Report
run: |
python -m coverage combine **/.coverage.*
python -m coverage report -m --skip-covered
python -m coverage json
- name: Output Coverage
run: echo "COVERAGE_JSON=$(jq -c . < coverage.json)" >> $GITHUB_ENV
- name: Get Coverage Totals
id: coverage-total
run: echo "coverage_total=${{ fromJson(env.COVERAGE_JSON).totals.percent_covered_display }}" >> $GITHUB_OUTPUT
outputs:
coverage_total: ${{ steps.coverage-total.outputs.coverage_total }}
coverage-badge:
runs-on: ubuntu-latest
needs:
- coverage
if: github.ref == 'refs/heads/main'
environment: release
env:
COVERAGE_TOTAL: ${{ needs.coverage.outputs.coverage_total }}
steps:
- name: Create Coverage Badge
uses: schneegans/[email protected]
with:
auth: ${{ secrets.GIST_TOKEN }}
gistID: ${{ vars.GIST_COVERAGE_ID }}
filename: ${{ vars.GIST_COVERAGE_NAME }}
label: Coverage
message: ${{ env.COVERAGE_TOTAL }}%
valColorRange: ${{ env.COVERAGE_TOTAL }}
maxColorRange: 90
minColorRange: 50
build:
runs-on: ubuntu-latest
needs:
- coverage
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install PyPa's build package
run: python -m pip install build
- name: Build
run: python -m build
- uses: actions/upload-artifact@v3
with:
name: build-${{ github.sha }}
path: dist
retention-days: 5
deploy:
runs-on: ubuntu-latest
needs:
- build
if: github.event_name == 'release'
environment: release
permissions:
contents: write
id-token: write
steps:
- uses: actions/download-artifact@v3
with:
name: build-${{ github.sha }}
path: dist
- name: Upload to GH Release
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
run: |
gh release upload "${{ github.ref_name }}" dist/*.tar.gz
gh release upload "${{ github.ref_name }}" dist/*.whl
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1