Skip to content

Commit 2ccfc74

Browse files
DEV: added scripts for building and uploading docs (#111)
* Update .readthedocs.yaml * Update .readthedocs.yaml * Update .readthedocs.yaml * Update .readthedocs.yaml * Update .readthedocs.yaml * Update .readthedocs.yaml * DEV: added GHA for building docs * Update build_docs.yml * Update build_docs.yml * Update build_docs.yml * Update build_docs.yml * Update build_docs.yml * Update build_docs.yml * Update build_docs.yml * Update build_docs.yml * DEV: update doc yaml's * DEV: more tweaks * added python script for downloading docs * debug * debug * fix url error * MAINT: added a comment about usage of the python script * STY: fix linting issues with doc script * DEV: use cached iqtree build when making docs * DEV: use iqtree/piqtree2 for api url --------- Co-authored-by: Robert McArthur <robert.mcarthur@anu.edu.au>
1 parent 992c1f0 commit 2ccfc74

File tree

3 files changed

+117
-11
lines changed

3 files changed

+117
-11
lines changed

.github/workflows/build_docs.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Build docs
2+
3+
on: [workflow_dispatch]
4+
5+
jobs:
6+
build-iqtree:
7+
name: Fetch or Build IQ-TREE 2 Static Library
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: "actions/checkout@v4"
11+
with:
12+
fetch-depth: 0
13+
submodules: recursive
14+
15+
- name: Get IQ-TREE 2 SHA
16+
run: |
17+
cd iqtree2
18+
IQ_TREE_2_SHA=$(git rev-parse HEAD)
19+
echo "IQ_TREE_2_SHA=${IQ_TREE_2_SHA}" >> $GITHUB_ENV
20+
21+
- uses: actions/cache@v4
22+
id: cache
23+
with:
24+
key: libiqtree-${{ matrix.os }}-${{ env.IQ_TREE_2_SHA }}
25+
path: src/piqtree2/_libiqtree/libiqtree2.a
26+
lookup-only: true
27+
28+
- name: Build IQ-TREE
29+
if: steps.cache.outputs.cache-hit != 'true'
30+
run: |
31+
sudo ./build_tools/before_all_linux.sh
32+
33+
build-docs:
34+
runs-on: ubuntu-latest
35+
needs: build-iqtree
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v4
39+
with:
40+
fetch-depth: 0
41+
submodules: recursive
42+
43+
- uses: actions/cache/restore@v4
44+
with:
45+
key: libiqtree-ubuntu-latest-${{ env.IQ_TREE_2_SHA }}
46+
path: src/piqtree2/_libiqtree/libiqtree2.a
47+
fail-on-cache-miss: true
48+
49+
- name: Set up Python
50+
uses: actions/setup-python@v5
51+
with:
52+
python-version: "3.12"
53+
54+
- name: Install Docs Dependencies
55+
run: |
56+
pip install .[doc]
57+
58+
- name: Build documentation
59+
run: |
60+
echo `pwd`
61+
mkdocs build
62+
working-directory: ${{ github.workspace }}
63+
64+
- name: Upload documentation artifact
65+
uses: actions/upload-artifact@v4
66+
with:
67+
name: piqtree-docs-html
68+
path: site

.readthedocs.yaml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@ build:
1010
os: ubuntu-22.04
1111
tools:
1212
python: "3.12"
13-
jobs:
14-
post_checkout:
15-
- git submodule update --init --recursive
13+
commands:
14+
# Install the required dependencies
15+
- pip install requests
16+
# Run the script to download and extract the pre-built docs
17+
- python rtd_get_docs.py
18+
- echo "Documentation downloaded and extracted"
1619

17-
mkdocs:
18-
configuration: mkdocs.yml
20+
# Disable the default build processes since we're using pre-built docs
21+
sphinx:
22+
configuration: null
1923

20-
# Optionally declare the Python requirements required to build your docs
2124
python:
22-
install:
23-
- method: pip
24-
path: .
25-
extra_requirements:
26-
- doc
25+
install: []

rtd_get_docs.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# this file
2+
# is directly used by .readthedocs.yaml
3+
# it extracts the built docs from the github artefact
4+
# created by the build_docs.yml github action
5+
import os
6+
import pathlib
7+
import zipfile
8+
9+
import requests
10+
11+
12+
def download_and_extract_docs() -> None:
13+
token = os.environ.get("GITHUB_TOKEN")
14+
headers = {"Authorization": f"token {token}"}
15+
api_url = "https://api.github.com/repos/iqtree/piqtree2/actions/runs"
16+
response = requests.get(api_url, headers=headers, timeout=10)
17+
got = response.json()
18+
runs = got["workflow_runs"]
19+
latest_run = next(
20+
run
21+
for run in runs
22+
if run["name"] == "Build docs" and run["conclusion"] == "success"
23+
)
24+
artifacts_url = latest_run["artifacts_url"]
25+
response = requests.get(artifacts_url, headers=headers, timeout=10)
26+
artifacts = response.json()["artifacts"]
27+
docs_artifact = next(
28+
artifact for artifact in artifacts if artifact["name"] == "piqtree-docs-html"
29+
)
30+
download_url = docs_artifact["archive_download_url"]
31+
response = requests.get(download_url, headers=headers, timeout=10)
32+
out = pathlib.Path("piqtree-docs-html.zip")
33+
out.write_bytes(response.content)
34+
with zipfile.ZipFile("piqtree-docs-html.zip", "r") as zip_ref:
35+
zip_ref.extractall("_readthedocs/html/")
36+
37+
38+
if __name__ == "__main__":
39+
download_and_extract_docs()

0 commit comments

Comments
 (0)