194 lines (184 loc) · 5.22 KB
/
ci.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
---
name: Continuous Integration
# Trigger this workflow manually, by pushing commits to any branch, or
# by filing a pull request.
on:
workflow_dispatch:
push:
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
setup:
runs-on: ubuntu-latest
steps:
- id: cache-workdir
uses: actions/cache@v3
with:
key: workdir-${{ github.sha }}
path: .
- if: steps.cache-workdir.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: pip
- run: python -m pip install .
lint:
needs: setup
runs-on: ubuntu-latest
steps:
- uses: actions/cache/restore@v3
with:
key: workdir-${{ github.sha }}
path: .
- uses: pre-commit/action@v3.0.0
test-matrix:
needs: lint
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- '3.10'
- '3.11'
- '3.12'
steps:
- uses: actions/cache/restore@v3
with:
key: workdir-${{ github.sha }}
path: .
# Computer science has only 3 hard problems: naming things,
# cache invaconcurrency, lidation, and off-by-one errors.
- id: hash-sources
run: |
echo "hash=$(find src tests -type f -exec cat '{}' \; | sha512sum | awk '{print $1}')" >> $GITHUB_OUTPUT
shell: bash
- id: cache-pytest
uses: actions/cache@v3
with:
key: pytest-${{ matrix.python-version }}-${{ steps.hash-sources.outputs.hash }}
lookup-only: true
path: pytest.out
- if: steps.cache-pytest.outputs.cache-hit != 'true'
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
- if: steps.cache-pytest.outputs.cache-hit != 'true'
name: Install test infrastructure
run: |
sudo make build-deps
pip install .[psycopg2cffi,test]
USER_SITE=`python -m site --user-site`
mkdir -p "${USER_SITE}"
echo "from psycopg2cffi import compat" > "${USER_SITE}/psycopg2.py"
echo "compat.register()" >> "${USER_SITE}/psycopg2.py"
- if: steps.cache-pytest.outputs.cache-hit != 'true'
uses: pavelzw/pytest-action@v2
with:
custom-arguments: --cov=lethbridge --report-log=pytest.out
release:
needs: test-matrix
if:
github.repository == 'irtnog/lethbridge' &&
github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/cache/restore@v3
with:
key: workdir-${{ github.sha }}
path: .
- id: release
uses: python-semantic-release/python-semantic-release@v8.3.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/cache/save@v3
with:
key: release-${{ github.sha }}
path: .
outputs:
released: ${{ steps.release.outputs.released }}
tag: ${{ steps.release.outputs.tag }}
build:
needs: release
if: needs.release.outputs.released == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/cache/restore@v3
with:
key: release-${{ github.sha }}
path: .
- run: pip install build && python -m build
- uses: actions/cache/save@v3
with:
key: build-${{ github.sha }}
path: .
testpypi:
needs:
- release
- build
if: needs.release.outputs.released == 'true'
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/lethbridge
permissions:
id-token: write
steps:
- uses: actions/cache/restore@v3
with:
key: build-${{ github.sha }}
path: .
- name: Publish package distributions to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
print-hash: true
repository-url: https://test.pypi.org/legacy/
verbose: true
pypi:
needs:
- release
- build
- testpypi
if: needs.release.outputs.released == 'true'
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/lethbridge
permissions:
id-token: write
steps:
- uses: actions/cache/restore@v3
with:
key: build-${{ github.sha }}
path: .
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
print-hash: true
verbose: true
github:
needs:
- release
- build
if: needs.release.outputs.released == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/cache/restore@v3
with:
key: build-${{ github.sha }}
path: .
- name: Publish package distributions to GitHub Releases
uses: python-semantic-release/upload-to-gh-release@main
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ needs.release.outputs.tag }}