-
Notifications
You must be signed in to change notification settings - Fork 1
221 lines (185 loc) · 7.48 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
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
name: Test, build and publish artefacts and documentation
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.[0-9]+-beta[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@v3
- 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 }},'beta')
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@v3
- name: Setup python
uses: actions/setup-python@v4
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: "matrix.os == 'ubuntu-20.04' && matrix.python-version == '3.8'"
run: |
source .venv/bin/activate
coverage html -d dist/tests/
rm dist/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: "matrix.os == 'ubuntu-20.04' && matrix.python-version == '3.8'"
run: |
source .venv/bin/activate
pip install -e .[doc]
pdoc3 --html --output-dir dist/ rok4
cp README.md CHANGELOG.md dist/
- name: Upload packages, tests results and documentation
if: "matrix.os == 'ubuntu-20.04' && matrix.python-version == '3.8'"
uses: actions/upload-artifact@v3
with:
name: dist-py3
path: dist/
if-no-files-found: error
retention-days: 1
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@v3
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-${{ github.ref_name }}-py3-none-any.whl
asset_name: rok4-${{ 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-${{ github.ref_name }}.tar.gz
asset_name: rok4-${{ github.ref_name }}.tar.gz
asset_content_type: application/zip
- name: Isolate wheel and tarball
run: |
mkdir to_publish
cp ./dist/rok4-${{ github.ref_name }}* to_publish/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
packages_dir: to_publish/
commit_documentation:
name: Add documentation and unit tests results into gh-pages branch
needs: build_and_test
if: "!(contains(${{ github.ref_name }},'beta'))&&(needs.create_release.outputs.job_status=='success')&&(needs.build_and_test.outputs.job_status=='success')"
runs-on: ubuntu-latest
steps:
- name: Checkout project on gh-pages
uses: actions/checkout@v3
with:
ref: 'gh-pages'
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/download-artifact@v3
with:
name: dist-py3
path: artifact/
- name: Copy version elements to final location
run: |
mkdir -p docs/versions/${{ github.ref_name }}
cp -r artifact/rok4 docs/versions/${{ github.ref_name }}/
cp -r artifact/tests docs/versions/${{ github.ref_name }}/
- name: Add pages from templates
run: |
sed "s#__version__#${{ github.ref_name }}#" templates/mkdocs.template.yml >mkdocs.yml
sed "s#__version__#${{ github.ref_name }}#" templates/unit-tests.template.md >docs/versions/${{ github.ref_name }}/unit-tests.md
sed "s#__version__#${{ github.ref_name }}#" templates/documentation.template.md >docs/versions/${{ github.ref_name }}/documentation.md
sed "s#__version__#${{ github.ref_name }}#" templates/index-version.template.md >docs/versions/${{ github.ref_name }}/index.md
cat artifact/README.md >>docs/versions/${{ github.ref_name }}/index.md
sed -i "s#x.y.z#${{ github.ref_name }}#g" docs/versions/${{ github.ref_name }}/index.md
cp templates/index-versions.template.md docs/versions/index.md
sed "s/^## \(.*\)$/## \1 \n\n[➔ Lien vers la documentation](\1\/index.md) /" artifact/CHANGELOG.md >>docs/versions/index.md
sed "s#__version__#${{ github.ref_name }}#" templates/latest.template.html >docs/versions/latest/index.html
rm -r artifact
- name: Publish on gh-pages branch
run: |
git config user.name github-actions
git config user.email [email protected]
git add -v docs/versions/${{ github.ref_name }}/ docs/versions/latest/ docs/versions/index.md mkdocs.yml
git commit -m "Add documentation for version ${{ github.ref_name }}"
git push
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 }}