-
Notifications
You must be signed in to change notification settings - Fork 3
120 lines (117 loc) · 4.45 KB
/
build-doc.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
name: Build doc
on:
workflow_call:
inputs:
doc-artifact-name:
description: "Name of the artifact containing the built doc"
required: false
default: "doc"
type: string
doc-path:
description: "Path where to extract the built doc"
required: false
default: "docs/build/html"
type: string
notebooks-repo-url:
description: |
Url of the repository containing the notebooks, used to generate github and colab links.
By default, the current repository url.
required: false
default: ""
type: string
notebooks-branch:
description: |
Branch containing the notebooks, used to generate github and colab links.
By default, the current branch.
required: false
default: ""
type: string
outputs:
doc-version:
description: "Version name of the generated doc. Correspond to the verrsion name used by Sphinx."
value: ${{ jobs.build-doc.outputs.doc_version }}
jobs:
build-doc:
outputs:
doc_version: ${{ steps.sphinx-build.outputs.doc_version }}
runs-on: ubuntu-latest
env:
python-version: "3.9"
steps:
- name: Set env variables for github links in doc
run: |
# notebooks source repo and branch. First try to use workflow inputs
AUTODOC_NOTEBOOKS_REPO_URL=${{ inputs.notebooks-repo-url }}
AUTODOC_NOTEBOOKS_BRANCH=${{ inputs.notebooks-branch }}
# use github context if not defined in inputs
if [[ $GITHUB_REF == refs/pull* ]];
then
if [ -z "${AUTODOC_NOTEBOOKS_REPO_URL}" ]; then
AUTODOC_NOTEBOOKS_REPO_URL="${GITHUB_SERVER_URL}/${{ github.event.pull_request.head.repo.full_name }}"
fi
if [ -z "${AUTODOC_NOTEBOOKS_BRANCH}" ]; then
AUTODOC_NOTEBOOKS_BRANCH=${GITHUB_HEAD_REF}
fi
elif [[ $GITHUB_REF == refs/heads* ]];
then
if [ -z "${AUTODOC_NOTEBOOKS_REPO_URL}" ]; then
AUTODOC_NOTEBOOKS_REPO_URL=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}
fi
if [ -z "${AUTODOC_NOTEBOOKS_BRANCH}" ]; then
AUTODOC_NOTEBOOKS_BRANCH=${GITHUB_REF/refs\/heads\//}
fi
elif [[ $GITHUB_REF == refs/tags* ]];
then
if [ -z "${AUTODOC_NOTEBOOKS_REPO_URL}" ]; then
AUTODOC_NOTEBOOKS_REPO_URL=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}
fi
if [ -z "${AUTODOC_NOTEBOOKS_BRANCH}" ]; then
AUTODOC_NOTEBOOKS_BRANCH=${GITHUB_REF/refs\/tags\//}
fi
fi
# export in GITHUB_ENV for next steps
echo "AUTODOC_NOTEBOOKS_REPO_URL=${AUTODOC_NOTEBOOKS_REPO_URL}" >> $GITHUB_ENV
echo "AUTODOC_NOTEBOOKS_BRANCH=${AUTODOC_NOTEBOOKS_BRANCH}" >> $GITHUB_ENV
# check computed variables
echo "Notebooks source: ${AUTODOC_NOTEBOOKS_REPO_URL}/tree/${AUTODOC_NOTEBOOKS_BRANCH}"
- uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: ${{ env.python-version }}
cache: "pip"
cache-dependency-path: |
pyproject.toml
docs/requirements.txt
- name: Install doc dependencies
run: |
python -m pip install -U pip setuptools
pip install .
pip install -r docs/requirements.txt
- name: generate documentation
id: sphinx-build
run: |
# move to documentation directory
cd docs
# generate api doc source files
sphinx-apidoc -o source/api -f -T ../src/decomon
# generate available notebooks list
python generate_nb_index.py
# build doc html pages
sphinx-build -M html source build
# specify it is a nojekyll site
touch build/html/.nojekyll
# store version name found by sphinx
doc_version=$(python -c '
import os
import sphinx.config
config = sphinx.config.Config.read(os.path.abspath("source"))
config.init_values()
print(config.version)
')
echo doc_version=${doc_version} >> $GITHUB_OUTPUT
- name: upload as artifact
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.doc-artifact-name }}
path: ${{ inputs.doc-path }}