Skip to content

Commit e099cb2

Browse files
author
cezary.maszczyk
committed
build: Github action to automate documentation generation after new release
1 parent c437503 commit e099cb2

File tree

98 files changed

+70
-26382
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+70
-26382
lines changed

.github/workflows/build_docs_on_new_release.yml

+13-4
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,39 @@ on:
44
release:
55
types: [published]
66

7+
permissions:
8+
contents: write
9+
710
jobs:
811
release-build:
912
runs-on: ubuntu-latest
1013

1114
steps:
1215
- name: Checkout code
1316
uses: actions/checkout@v4
17+
with:
18+
token: ${{ secrets.PAT }}
1419

1520
- name: Set up Python
1621
uses: actions/setup-python@v5
1722
with:
1823
python-version: "3.12"
1924

20-
- name: Build documentation
25+
- name: Download test resources
26+
run: |
27+
pip install requests
28+
python ./tests/resources.py download
29+
30+
- name: Build documentation and update badges
2131
run: |
2232
python -m pip install --upgrade pip
2333
pip install -r ./docs/requirements.txt
34+
pip install .
2435
python ./docs/build.py ${{ github.event.release.name }}
25-
26-
- name: Update README.md badges
27-
run: |
2836
python ./docs/generate_readme_badges.py
2937
3038
- name: Commit updated documentation and badges
3139
uses: "stefanzweifel /git-auto-commit-action@v5"
3240
with:
3341
commit_message: Documentation for version ${{ github.event.release.name }}
42+
branch: main

docs/build.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
def build_docs_using_sphinx(version_number: str):
1313
print(f"Building docs for version v{version_number}")
14-
python_path: str = sys.executable
1514
output_path: str = f'{curr_dir_path}/serve/v{version_number}'
16-
run_command(
17-
f"{python_path} -m sphinx.cmd.build -M html source {output_path}"
15+
run_command([
16+
sys.executable, '-m', 'sphinx.cmd.build', '-M', 'html', 'source', output_path,
17+
],
18+
cwd=curr_dir_path,
19+
raise_on_error=False
1820
)
1921
tmp_path: str = f'{output_path}@'
2022
shutil.move(output_path, tmp_path)

docs/generate_readme_badges.py

+33-25
Original file line numberDiff line numberDiff line change
@@ -9,62 +9,70 @@
99

1010

1111
# Documentation will be automatically generated on new version release
12-
def generate_tests_coverage_badge(python_path: str, cwd: str):
13-
run_command(
14-
f"{python_path} -m coverage run -m unittest discover ./tests",
12+
def generate_tests_coverage_badge(cwd: str):
13+
run_command([
14+
sys.executable, "-m", "coverage", "run", "-m", "unittest", "discover", "./tests"
15+
],
1516
cwd=cwd
1617
)
17-
run_command(
18-
f"{python_path} -m coverage xml -o ./docs/reports/coverage/coverage.xml",
18+
run_command([
19+
sys.executable, "-m", "coverage", "xml", "-o", "./docs/reports/coverage/coverage.xml"
20+
],
1921
cwd=cwd
2022
)
21-
run_command(
22-
f"{python_path} -m coverage html -d ./docs/reports/coverage/",
23+
run_command([
24+
sys.executable, "-m", "coverage", "html", "-d", "./docs/reports/coverage/"
25+
],
2326
cwd=cwd
2427
)
25-
run_command(
26-
"genbadge coverage -i ./docs/reports/coverage/coverage.xml -o ./docs/badges/coverage-badge.svg",
28+
run_command([
29+
"genbadge", "coverage", "-i", "./docs/reports/coverage/coverage.xml", "-o", "./docs/badges/coverage-badge.svg"
30+
],
2731
cwd=cwd
2832
)
2933

3034

31-
def generate_test_badge(python_path: str, cwd: str):
35+
def generate_test_badge(cwd: str):
3236
test_report_path = pathlib.Path(curr_dir_path / 'reports' / 'junit')
3337
shutil.rmtree(test_report_path)
3438
os.makedirs(test_report_path, exist_ok=True)
35-
run_command(
36-
f"{python_path} -m junitxml.main --o ./docs/reports/junit/junit.xml",
39+
run_command([
40+
sys.executable, "-m", "junitxml.main", "--o", "./docs/reports/junit/junit.xml"
41+
],
3742
cwd=cwd
3843
)
39-
run_command(
40-
f"{python_path} -m junit2htmlreport ./docs/reports/junit/junit.xml ./docs/reports/junit/report.html",
44+
run_command([
45+
sys.executable, "-m", "junit2htmlreport", "./docs/reports/junit/junit.xml", "./docs/reports/junit/report.html"
46+
],
4147
cwd=cwd
4248
)
43-
run_command(
44-
"genbadge tests -i ./docs/reports/junit/junit.xml -o ./docs/badges/test-badge.svg",
49+
run_command([
50+
"genbadge", "tests", "-i", "./docs/reports/junit/junit.xml", "-o", "./docs/badges/test-badge.svg"
51+
],
4552
cwd=cwd
4653
)
4754

4855

49-
def generate_flake8_badge(python_path: str, cwd: str):
50-
run_command(
51-
f"{python_path} -m flake8 ./rulekit --exit-zero --format=html --htmldir ./docs/reports/flake8 --statistics --tee --output-file ./docs/reports/flake8/flake8stats.txt",
56+
def generate_flake8_badge(cwd: str):
57+
run_command([
58+
sys.executable, "-m", "flake8", "./rulekit", "--exit-zero", "--format=html", "--htmldir", "./docs/reports/flake8", "--statistics", "--tee", "--output-file", "./docs/reports/flake8/flake8stats.txt"
59+
],
5260
cwd=cwd
5361
)
54-
run_command(
55-
"genbadge flake8 -i ./docs/reports/flake8/flake8stats.txt -o ./docs/badges/flake8-badge.svg",
62+
run_command([
63+
"genbadge", "flake8", "-i", "./docs/reports/flake8/flake8stats.txt", "-o", "./docs/badges/flake8-badge.svg"
64+
],
5665
cwd=cwd
5766
)
5867

5968

6069
def main():
6170
print('Updating badges')
6271
cwd = pathlib.Path(curr_dir_path / '..') # root repo dir
63-
python_path: str = sys.executable
6472

65-
generate_tests_coverage_badge(python_path, cwd)
66-
generate_test_badge(python_path, cwd)
67-
generate_flake8_badge(python_path, cwd)
73+
generate_tests_coverage_badge(cwd)
74+
generate_test_badge(cwd)
75+
generate_flake8_badge(cwd)
6876

6977
print('Badges generated successfully!')
7078

docs/helpers.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
from typing import Optional
33

44

5-
def run_command(command: str, cwd: Optional[str] = None):
6-
output = subprocess.check_output(command, cwd=cwd)
5+
def run_command(command: list[str], cwd: Optional[str] = None, raise_on_error: bool = True):
6+
process = subprocess.Popen(
7+
command,
8+
stdout=subprocess.PIPE,
9+
stderr=subprocess.PIPE,
10+
cwd=cwd
11+
)
12+
output, error = process.communicate()
13+
if process.returncode != 0 and raise_on_error:
14+
raise Exception("File handling failed %d %s %s" %
15+
(process.returncode, output, error)
16+
)
17+
718
print(output.decode())

docs/requirements.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
Jinja2<3.1
21
Sphinx==7.2.6
32
sphinx-rtd-theme==2.0.0
43
nbsphinx==0.9.3
54
sphinx-copybutton==0.5.2
65
ipykernel==5.5.0
76
pandoc~=2.3
7+
coverage~=7.6.4
88
ipython_genutils~=0.2.0
9-
../
10-
9+
flake8
10+
junitxml==0.7
11+
junit2html~=31.0.2
12+
genbadge[all]~=1.1.1

docs/serve/index.html

+1-18
Original file line numberDiff line numberDiff line change
@@ -116,27 +116,10 @@ <h1>
116116

117117
<li class="toctree-l1">
118118
<a class="reference internal" href="v2.1.18.0/index.html">
119-
v2.1.18.0
119+
v2.1.18.0 (latest)
120120
</a>
121121
</li>
122122

123-
<li class="toctree-l1">
124-
<a class="reference internal" href="v2.1.18.0/index.html">
125-
v2.1.18.0
126-
</a>
127-
</li>
128-
129-
<li class="toctree-l1">
130-
<a class="reference internal" href="v2.18.0.0/index.html">
131-
v2.18.0.0
132-
</a>
133-
</li>
134-
135-
<li class="toctree-l1">
136-
<a class="reference internal" href="v2.18.0.0/index.html">
137-
v2.18.0.0 (latest)
138-
</a>
139-
</li>
140123
<!-- LATEST VERSION PLACEHOLDER -->
141124

142125

docs/serve/v2.18.0.0/.buildinfo

-4
This file was deleted.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

docs/serve/v2.18.0.0/_sources/index.rst.txt

-25
This file was deleted.

docs/serve/v2.18.0.0/_sources/rst/autodoc.rst.txt

-17
This file was deleted.

docs/serve/v2.18.0.0/_sources/rst/autodoc/classification.rst.txt

-11
This file was deleted.

docs/serve/v2.18.0.0/_sources/rst/autodoc/params.rst.txt

-93
This file was deleted.

docs/serve/v2.18.0.0/_sources/rst/autodoc/regression.rst.txt

-10
This file was deleted.

docs/serve/v2.18.0.0/_sources/rst/autodoc/rules.rst.txt

-5
This file was deleted.

0 commit comments

Comments
 (0)