-
Notifications
You must be signed in to change notification settings - Fork 1
195 lines (169 loc) · 6.52 KB
/
build-and-release.yaml
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
name: Test, build and publish artefacts and documentation
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.[0-9]+b[0-9]+'
jobs:
create_release:
name: Create Release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
job_status: ${{ job.status }}
steps:
- name: Checkout project
uses: actions/checkout@v4
- name: Create Release
id: create_release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
generateReleaseNotes: true
draft: false
prerelease: ${{ contains(github.ref_name ,'b') }}
build_and_test:
name: Test and build artefacts
needs: create_release
outputs:
job_status: ${{ job.status }}
strategy:
max-parallel: 2
fail-fast: true
matrix:
include:
- os: ubuntu-20.04
python-version: "3.8"
- os: ubuntu-22.04
python-version: "3.10"
runs-on: ${{ matrix.os }}
steps:
- name: Checkout project
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: '**/pyproject.toml'
- name: Install system dependencies
run: |
sudo apt update
sudo apt -y install python3-rados python3-gdal
- name: Install python dependencies
run: |
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install --upgrade build bump2version
bump2version --current-version 0.0.0 --new-version ${{ github.ref_name }} patch
pip install -e .
echo "/usr/lib/python3/dist-packages/" >.venv/lib/python${{ matrix.python-version }}/site-packages/system.pth
- name: Run unit tests
run: |
source .venv/bin/activate
pip install -e .[test]
coverage run -m pytest
coverage report -m
- name: Build unit tests report
if: "! contains(github.ref_name,'b') && matrix.os == 'ubuntu-20.04' && matrix.python-version == '3.8'"
run: |
source .venv/bin/activate
coverage html -d target/docs/tests/
rm target/docs/tests/.gitignore
- name: Build package
if: "matrix.os == 'ubuntu-20.04' && matrix.python-version == '3.8'"
run: |
source .venv/bin/activate
python3 -m build
- name: Build documentation
if: "! contains(github.ref_name,'b') && matrix.os == 'ubuntu-20.04' && matrix.python-version == '3.8'"
run: |
source .venv/bin/activate
pip install -e .[doc]
pdoc3 --html --output-dir target/docs/ rok4_tools
cp docs/mkdocs.yml target/mkdocs.yml
cp -r docs/overrides target/
cp -r docs/images target/docs/
cp docs/unit-tests.md target/docs/unit-tests.md
cp docs/documentation.md target/docs/documentation.md
cp docs/README.hdr.md target/docs/README.md
cp docs/CHANGELOG.hdr.md target/docs/CHANGELOG.md
cp docs/CONTRIBUTING.hdr.md target/docs/CONTRIBUTING.md
sed "s#x.y.z#${{ github.ref_name }}#g" README.md >>target/docs/README.md
sed -i "s#](./docs/images/#](./images/#g" target/docs/README.md
cat CHANGELOG.md >>target/docs/CHANGELOG.md
cat CONTRIBUTING.md >>target/docs/CONTRIBUTING.md
- name: Upload packages
if: "matrix.os == 'ubuntu-20.04' && matrix.python-version == '3.8'"
uses: actions/upload-artifact@v4
with:
name: dist-py3
path: dist/
if-no-files-found: error
retention-days: 1
- name: Publish documentation
if: "! contains(github.ref_name,'b') && matrix.os == 'ubuntu-20.04' && matrix.python-version == '3.8'"
run: |
source .venv/bin/activate
pip install -r docs/requirements.txt
git config user.name github-actions
git config user.email [email protected]
cd target/
mike deploy --push --update-aliases --branch gh-pages -t "Version ${{ github.ref_name }}" ${{ github.ref_name }} latest
mike set-default --push --branch gh-pages ${{ github.ref_name }}
publish_artefacts:
name: Add built artefacts to release and PyPI
needs: [create_release, build_and_test]
if: "always() && needs.create_release.outputs.job_status == 'success' && needs.build_and_test.outputs.job_status == 'success'"
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: dist-py3
path: dist/
- name: Add wheel package to release
id: upload-release-whl
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ./dist/rok4_tools-${{ github.ref_name }}-py3-none-any.whl
asset_name: rok4_tools-${{ github.ref_name }}-py3-none-any.whl
asset_content_type: application/zip
- name: Add tarball package to release
id: upload-release-targz
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ./dist/rok4_tools-${{ github.ref_name }}.tar.gz
asset_name: rok4_tools-${{ github.ref_name }}.tar.gz
asset_content_type: application/zip
- name: Isolate wheel and tarball
run: |
mkdir to_publish
cp ./dist/*.whl ./dist/*.tar.gz to_publish/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
packages_dir: to_publish/
delete_version:
name: Remove release and tag if error occured
needs: build_and_test
if: "always() && needs.create_release.outputs.job_status == 'success' && needs.build_and_test.outputs.job_status != 'success'"
runs-on: ubuntu-latest
steps:
- name: Remove release and tag
uses: dev-drprasad/[email protected]
with:
tag_name: ${{ github.ref_name }}
delete_release: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}