-
-
Notifications
You must be signed in to change notification settings - Fork 70
244 lines (227 loc) · 8.75 KB
/
run-tests.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
235
236
237
238
239
240
241
242
243
244
# SPDX-FileCopyrightText: 2024 2024 Nicco Kunzmann and Open Web Calendar Contributors <https://open-web-calendar.quelltext.eu/>
#
# SPDX-License-Identifier: GPL-2.0-only
# Run pytest for each commit.
# See also
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#running-tests-with-tox
name: "Build, Test & Publish"
on: [push, pull_request]
# cancel builds in progress if a new push has been made to the same ref
# see https://stackoverflow.com/a/70972844/1320237
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref_name != 'master' }}
jobs:
run-tests:
name: "Build & Run Tests"
runs-on: ubuntu-latest
strategy:
matrix:
# deprecate python versions also in
# - tox.ini
# - pyproject.toml
# - README.md
python: ["3.9", "3.10", "3.11", "3.12"]
tox_env: ["py"]
# see https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#expanding-or-adding-matrix-configurations
include:
# run Firefox
- python: "3.11"
tox_env: web
# run Chrome
# - python: "3.11"
# tox_env: "web -- -D browser=chrome"
# run Firefox in iPhone 11 responsive layout
- python: "3.11"
tox_env: "web -- -D window=375x812"
# Licensing REUSE
- python: "3.12"
tox_env: "reuse"
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Install tox
run: pip install tox
- name: Run tests
# Run tox using the version of Python in `PATH`
run: tox -e ${{ matrix.tox_env }}
- name: Upload screenshots
# run even if tests fail
# see https://stackoverflow.com/a/58859404/1320237
if: always()
uses: actions/upload-artifact@v4
with:
name: screenshots-${{ matrix.python }}-${{ matrix.tox_env }}
path: screenshots
if-no-files-found: ignore
retention-days: 14
compression-level: 0
gh-pages:
name: "Publish Documentation to GitHub Pages"
runs-on: ubuntu-latest
if: ${{ github.ref_name == 'master' }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # required for mkdocs git date, see https://github.com/timvink/mkdocs-git-revision-date-localized-plugin?tab=readme-ov-file#note-when-using-build-environments
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install tox
run: pip install tox
- name: mkdocs
# Run tox using the version of Python in `PATH`
run: tox -e docs -- gh-deploy
link-check:
name: "Check Links in Documentation"
runs-on: ubuntu-latest
if: ${{ ! startsWith(github.ref, 'refs/tags/v')}}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # required for mkdocs git date, see https://github.com/timvink/mkdocs-git-revision-date-localized-plugin?tab=readme-ov-file#note-when-using-build-environments
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install tox
run: pip install tox linkchecker
- name: Check Links
run: scripts/check-links-in-documentation.sh
- uses: actions/upload-artifact@v4
with:
name: checked-links.html
path: linkchecker-out.html
dockerhub:
name: Publish Docker Image on Docker Hub
runs-on: ubuntu-latest
if: ${{ github.ref_name == 'master' || startsWith(github.ref, 'refs/tags/v') }}
# This environment stores the DOCKERHUB_USERNAME and DOCKERHUB_TOKEN
# see https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment
environment:
name: dockerhub
url: https://hub.docker.com/r/niccokunzmann/open-web-calendar
needs:
- run-tests
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Create Version Information
run: |
python -m pip install --upgrade pip
pip install --upgrade build
if [ "$GITHUB_REF_NAME" == "master" ]; then
echo "Adding commit hash to build information"
sed -i 's/^local_scheme/#local_scheme/g' pyproject.toml
else
echo "Using version information from tag"
fi
python -m build
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@1f36f5b7a2d2f7bfd524795fc966e6d88c37baa9
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: niccokunzmann/open-web-calendar
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/386,linux/arm/v6
labels: ${{ steps.meta.outputs.labels }}
deploy-tag-to-pypi:
name: Publish Package on PyPI
# only deploy on tags, see https://stackoverflow.com/a/58478262/1320237
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
needs:
- run-tests
runs-on: ubuntu-latest
# This environment stores the TWINE_USERNAME and TWINE_PASSWORD
# see https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment
environment:
name: PyPI
url: https://pypi.org/project/open-web-calendar/
# after using the environment, we need to make the secrets available
# see https://docs.github.com/en/actions/security-guides/encrypted-secrets#example-using-bash
env:
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade wheel twine build
# - name: Check the tag
# run: |
# PACKAGE_VERSION=`python setup.py --version`
# TAG_NAME=v$PACKAGE_VERSION
# echo "Package version $PACKAGE_VERSION with possible tag name $TAG_NAME on $GITHUB_REF_NAME"
# # test that the tag represents the version
# # see https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
# # see https://docs.github.com/en/actions/learn-github-actions/environment-variables
# if [ "$TAG_NAME" != "$GITHUB_REF_NAME" ]; then
# echo "ERROR: This tag is for the wrong version. Got \"$GITHUB_REF_NAME\" expected \"$TAG_NAME\"."
# exit 1
# fi
- name: remove old files
run: rm -rf dist/*
- name: build distribution files
run: python -m build
- name: deploy to pypi
run: |
# You will have to set the variables TWINE_USERNAME and TWINE_PASSWORD
# You can use a token specific to your project by setting the user name to
# __token__ and the password to the token given to you by the PyPI project.
# sources:
# - https://shambu2k.hashnode.dev/gitlab-to-pypi
# - http://blog.octomy.org/2020/11/deploying-python-pacakges-to-pypi-using.html?m=1
# Also, set the tags as protected to allow the secrets to be used.
# see https://docs.gitlab.com/ee/user/project/protected_tags.html
if [ -z "$TWINE_USERNAME" ]; then
echo "WARNING: TWINE_USERNAME not set!"
fi
if [ -z "$TWINE_PASSWORD" ]; then
echo "WARNING: TWINE_PASSWORD not set!"
fi
twine check dist/*
twine upload dist/*
github-release:
name: "Publish GitHub Release"
# only deploy on tags, see https://stackoverflow.com/a/58478262/1320237
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
needs:
- run-tests
- dockerhub
- deploy-tag-to-pypi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: create release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
body: "For a list of changes, please refer to the [Changelog](https://open-web-calendar.quelltext.eu/changelog/)."
generateReleaseNotes: false