-
Notifications
You must be signed in to change notification settings - Fork 7
234 lines (198 loc) · 6.4 KB
/
test.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
---
name: Test
on:
push:
branches: [main]
tags: ['v*.*.*']
pull_request:
branches: [main]
jobs:
test:
permissions:
contents: read
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python:
- '3.8'
- '3.9'
- '3.10'
- '3.11'
env:
PYTEST_ADDOPTS: '--color=yes'
outputs:
relver: ${{ steps.setvars.outputs.relver }}
branch: ${{ steps.setvars.outputs.branch }}
changelogver: ${{ steps.setvars.outputs.changelogver }}
steps:
- uses: actions/checkout@v4
with:
show-progress: false
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
cache: pip
- name: Requirements
run: |
pip install --upgrade pip setuptools wheel
pip install .[tests]
- name: Pytest
run: pytest tests/
- name: Set vars
id: setvars
run: |
VER_TAG=${GITHUB_REF/refs\/tags\/v/}
echo "relver=${VER_TAG}" | tee --append $GITHUB_OUTPUT
echo "branch=${GITHUB_REF#refs/heads/}" | tee --append $GITHUB_OUTPUT
echo "changelogver=v${VER_TAG//\./-}" | tee --append $GITHUB_OUTPUT
- name: Coverage
uses: codecov/codecov-action@v3
build-container:
permissions:
contents: read
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform: [arm64, amd64]
outputs:
container-description: ${{ steps.description.outputs.container-description }}
steps:
- uses: actions/checkout@v4
with:
show-progress: false
- name: Set up QEMU
if: matrix.platform == 'arm64'
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: matrix.platform == 'arm64'
uses: docker/setup-buildx-action@v3
- name: Build amd64
uses: docker/build-push-action@v5
with:
push: false
context: .
load: true
platforms: linux/${{ matrix.platform }}
tags: galactory:latest
- name: Run container
run: docker run --platform ${{ matrix.platform }} --rm galactory --help
- name: Extract container description
id: description
run: |
DESC=$(docker inspect --format '{{ index .Config.Labels "org.opencontainers.image.description" }}' galactory)
echo "container-description=$DESC" | tee --append $GITHUB_OUTPUT
build-python:
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
show-progress: false
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Pre-reqs
run: pip install --upgrade pip setuptools build twine
- name: Build
run: python -m build
- name: Test build
run: python -m twine check dist/*
- name: Check version
id: checkver
if: startsWith(github.ref, 'refs/tags/')
run: |
VER_TAG=${GITHUB_REF/refs\/tags\/v/}
expected_sdist=galactory-${VER_TAG}.tar.gz
expected_wheel=galactory-${VER_TAG}-py3-none-any.whl
if [ ! -f "dist/${expected_sdist}" ] || [ ! -f "dist/${expected_wheel}" ]
then
exit 1
fi
- uses: actions/upload-artifact@v3
with:
name: dist
path: dist
retention-days: ${{ github.event_name == 'push' && 90 || 7 }}
if-no-files-found: error
container_release:
needs: [test, build-container]
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: read
# ^ checkout
packages: write
# ^ ghcr
env:
UPSTREAM: ghcr.io/${{ github.repository_owner }}/galactory
steps:
- uses: actions/checkout@v4
with:
show-progress: false
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to registry
if: github.event_name == 'push'
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build & Push
uses: docker/build-push-action@v5
with:
push: ${{ github.event_name == 'push' }}
context: .
platforms: linux/amd64,linux/arm64
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
tags: |
${{ env.UPSTREAM }}:${{ startsWith(github.ref, 'refs/tags/') && 'latest' || needs.test.outputs.branch }}
${{ env.UPSTREAM }}:${{ startsWith(github.ref, 'refs/tags/') && needs.test.outputs.relver || github.sha }}
outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=${{ needs.build-container.outputs.container-description }}
pypi_release:
needs: [test, build-python]
if: >-
github.event_name == 'push'
&& startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
permissions:
id-token: write
# ^ PyPI OIDC
steps:
- uses: actions/download-artifact@v3
with:
name: dist
path: dist
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@b7f401de30cb6434a1e19f805ff006643653240e
github_release:
needs:
- test
- build-container
- build-python
- container_release
- pypi_release
if: >-
github.event_name == 'push'
&& startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
permissions:
contents: write
# ^ GitHub tag and release
steps:
- uses: actions/download-artifact@v3
with:
name: dist
path: dist
- uses: softprops/action-gh-release@c9b46fe7aad9f02afd89b12450b780f52dacfb2d
with:
generate_release_notes: true
fail_on_unmatched_files: true
files: dist/*
body: |
PyPI: https://pypi.org/project/galactory/${{ needs.test.outputs.relver }}/
Container: `ghcr.io/${{ github.repository }}:${{ needs.test.outputs.relver }}`
Browse container tags: https://github.com/briantist/galactory/pkgs/container/galactory
Changelog: https://github.com/briantist/galactory/blob/main/CHANGELOG.rst#${{ needs.test.outputs.changelogver }}