|
| 1 | +# ==================================================================================================================== # |
| 2 | +# Authors: # |
| 3 | +# Patrick Lehmann # |
| 4 | +# # |
| 5 | +# ==================================================================================================================== # |
| 6 | +# Copyright 2020-2026 The pyTooling Authors # |
| 7 | +# # |
| 8 | +# Licensed under the Apache License, Version 2.0 (the "License"); # |
| 9 | +# you may not use this file except in compliance with the License. # |
| 10 | +# You may obtain a copy of the License at # |
| 11 | +# # |
| 12 | +# http://www.apache.org/licenses/LICENSE-2.0 # |
| 13 | +# # |
| 14 | +# Unless required by applicable law or agreed to in writing, software # |
| 15 | +# distributed under the License is distributed on an "AS IS" BASIS, # |
| 16 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # |
| 17 | +# See the License for the specific language governing permissions and # |
| 18 | +# limitations under the License. # |
| 19 | +# # |
| 20 | +# SPDX-License-Identifier: Apache-2.0 # |
| 21 | +# ==================================================================================================================== # |
| 22 | +name: Documentation |
| 23 | + |
| 24 | +on: |
| 25 | + workflow_call: |
| 26 | + inputs: |
| 27 | + ubuntu_image_version: |
| 28 | + description: 'Ubuntu image version.' |
| 29 | + required: false |
| 30 | + default: '24.04' |
| 31 | + type: string |
| 32 | + python_version: |
| 33 | + description: 'Python version.' |
| 34 | + required: false |
| 35 | + default: '3.14' |
| 36 | + type: string |
| 37 | + requirements: |
| 38 | + description: 'Python dependencies to be installed through pip.' |
| 39 | + required: false |
| 40 | + default: '-r doc/requirements.txt' |
| 41 | + type: string |
| 42 | + doc_directory: |
| 43 | + description: 'Path to the directory containing documentation (Sphinx working directory).' |
| 44 | + required: false |
| 45 | + default: 'doc' |
| 46 | + type: string |
| 47 | + html_artifact: |
| 48 | + description: 'Name of the HTML documentation artifact.' |
| 49 | + required: false |
| 50 | + default: '' |
| 51 | + type: string |
| 52 | + latex_artifact: |
| 53 | + description: 'Name of the LaTeX documentation artifact.' |
| 54 | + required: false |
| 55 | + default: '' |
| 56 | + type: string |
| 57 | + |
| 58 | +jobs: |
| 59 | + Sphinx-HTML: |
| 60 | + name: 📓 HTML Documentation using Sphinx and Python ${{ inputs.python_version }} |
| 61 | + runs-on: "ubuntu-${{ inputs.ubuntu_image_version }}" |
| 62 | + if: inputs.html_artifact != '' |
| 63 | + |
| 64 | + steps: |
| 65 | + - name: ⏬ Checkout repository |
| 66 | + uses: actions/checkout@v6 |
| 67 | + with: |
| 68 | + lfs: true |
| 69 | + submodules: true |
| 70 | + |
| 71 | + - name: 🔧 Install tcllib |
| 72 | + run: sudo apt-get install -y --no-install-recommends tcllib |
| 73 | + |
| 74 | + - name: 🔧 Install Ruff! |
| 75 | + run: | |
| 76 | + export TCLLIBPATH="$(pwd)/myTCLLibrary" |
| 77 | + |
| 78 | + curl -L --output ruff.zip https://github.com/apnadkarni/ruff/archive/refs/heads/master.zip |
| 79 | + unzip -q ruff.zip |
| 80 | + |
| 81 | + mkdir -p ${TCLLIBPATH}/ruff |
| 82 | + cp -R ruff-master/src/* ${TCLLIBPATH}/ruff |
| 83 | + tree ${TCLLIBPATH} |
| 84 | + |
| 85 | + tclsh - << EOF |
| 86 | + puts "auto_path:" |
| 87 | + foreach path \$auto_path { |
| 88 | + puts " \$path" |
| 89 | + } |
| 90 | + puts "" |
| 91 | + puts "Loading Ruff ..." |
| 92 | + puts "Ruff version: [package require ruff]" |
| 93 | + EOF |
| 94 | + |
| 95 | + printf -- "\n" |
| 96 | + printf -- "Export environment variables:\n" |
| 97 | + tee --append $GITHUB_ENV << EOF |
| 98 | + TCLLIBPATH=${TCLLIBPATH} |
| 99 | + EOF |
| 100 | +
|
| 101 | +# - name: 🔧 Install graphviz |
| 102 | +# run: sudo apt-get install -y --no-install-recommends graphviz |
| 103 | + |
| 104 | + - name: 🐍 Setup Python ${{ inputs.python_version }} |
| 105 | + uses: actions/setup-python@v6 |
| 106 | + with: |
| 107 | + python-version: ${{ inputs.python_version }} |
| 108 | + |
| 109 | + - name: 🔧 Install wheel and pip dependencies (native) |
| 110 | + run: | |
| 111 | + python -m pip install --disable-pip-version-check -U wheel |
| 112 | + python -m pip install --disable-pip-version-check ${{ inputs.requirements }} |
| 113 | +
|
| 114 | + - name: ☑ Generate HTML documentation |
| 115 | + run: | |
| 116 | + export PYTHONPATH=$(pwd) |
| 117 | + |
| 118 | + cd "${{ inputs.doc_directory || '.' }}" |
| 119 | + ./build.sh --verbose --all --html |
| 120 | + |
| 121 | + printf "::group::${ANSI_LIGHT_BLUE}%s${ANSI_NOCOLOR}\n" "Generated documentation ..." |
| 122 | + tree _build |
| 123 | + printf "::endgroup::\n" |
| 124 | +
|
| 125 | + - name: 📤 Upload 'HTML Documentation' artifact |
| 126 | + uses: pyTooling/upload-artifact@v6 |
| 127 | + continue-on-error: true |
| 128 | + with: |
| 129 | + name: ${{ inputs.html_artifact }} |
| 130 | + working-directory: ${{ inputs.doc_directory }}/_build/html |
| 131 | + path: '*' |
| 132 | + if-no-files-found: error |
| 133 | + retention-days: 1 |
| 134 | + |
| 135 | + Sphinx-LaTeX: |
| 136 | + name: 📓 LaTeX Documentation using Sphinx and Python ${{ inputs.python_version }} |
| 137 | + runs-on: "ubuntu-${{ inputs.ubuntu_image_version }}" |
| 138 | + if: inputs.latex_artifact != '' |
| 139 | + |
| 140 | + steps: |
| 141 | + - name: ⏬ Checkout repository |
| 142 | + uses: actions/checkout@v6 |
| 143 | + with: |
| 144 | + lfs: true |
| 145 | + submodules: true |
| 146 | + |
| 147 | + - name: 🔧 Install tcllib |
| 148 | + run: sudo apt-get install -y --no-install-recommends tcllib |
| 149 | + |
| 150 | + - name: 🔧 Install Ruff! |
| 151 | + run: | |
| 152 | + export TCLLIBPATH="$(pwd)/myTCLLibrary" |
| 153 | + |
| 154 | + curl -L --output ruff.zip https://github.com/apnadkarni/ruff/archive/refs/heads/master.zip |
| 155 | + unzip -q ruff.zip |
| 156 | + |
| 157 | + mkdir -p ${TCLLIBPATH}/ruff |
| 158 | + cp -R ruff-master/src/* ${TCLLIBPATH}/ruff |
| 159 | + tree ${TCLLIBPATH} |
| 160 | + |
| 161 | + tclsh - << EOF |
| 162 | + puts "auto_path:" |
| 163 | + foreach path \$auto_path { |
| 164 | + puts " \$path" |
| 165 | + } |
| 166 | + puts "" |
| 167 | + puts "Loading Ruff ..." |
| 168 | + puts "Ruff version: [package require ruff]" |
| 169 | + EOF |
| 170 | + |
| 171 | + printf -- "\n" |
| 172 | + printf -- "Export environment variables:\n" |
| 173 | + tee --append $GITHUB_ENV << EOF |
| 174 | + TCLLIBPATH=${TCLLIBPATH} |
| 175 | + EOF |
| 176 | +
|
| 177 | +# - name: 🔧 Install graphviz |
| 178 | +# run: sudo apt-get install -y --no-install-recommends graphviz |
| 179 | + |
| 180 | + - name: 🐍 Setup Python ${{ inputs.python_version }} |
| 181 | + uses: actions/setup-python@v6 |
| 182 | + with: |
| 183 | + python-version: ${{ inputs.python_version }} |
| 184 | + |
| 185 | + - name: 🔧 Install wheel and pip dependencies (native) |
| 186 | + run: | |
| 187 | + python -m pip install --disable-pip-version-check -U wheel |
| 188 | + python -m pip install --disable-pip-version-check ${{ inputs.requirements }} |
| 189 | +
|
| 190 | + - name: ☑ Generate LaTeX documentation |
| 191 | + run: | |
| 192 | + export PYTHONPATH=$(pwd) |
| 193 | + |
| 194 | + cd "${{ inputs.doc_directory || '.' }}" |
| 195 | + ./build.sh --verbose --all --latex |
| 196 | + |
| 197 | + printf "::group::${ANSI_LIGHT_BLUE}%s${ANSI_NOCOLOR}\n" "Generated documentation ..." |
| 198 | + tree _build |
| 199 | + printf "::endgroup::\n" |
| 200 | +
|
| 201 | + - name: Workaround I - https://github.com/sphinx-doc/sphinx/issues/13190 |
| 202 | + run: | |
| 203 | + printf "Changing directory to '${{ inputs.doc_directory || '.' }}/_build/latex' ...\n" |
| 204 | + cd ${{ inputs.doc_directory || '.' }}/_build/latex |
| 205 | +
|
| 206 | + MIMETYPE_EXTENSIONS=( |
| 207 | + "image/png:png" |
| 208 | + "image/jpeg:jpg" |
| 209 | + "image/svg+xml:svg" |
| 210 | + ) |
| 211 | +
|
| 212 | + printf "Changing file extension according to MIME type ...\n" |
| 213 | + while IFS=$'\n' read -r file; do |
| 214 | + printf " Checking '%s' ... " "${file}" |
| 215 | + mime="$(file --mime-type -b "${file}")" |
| 216 | + printf "[%s]\n" "${mime}" |
| 217 | +
|
| 218 | + found=0 |
| 219 | + for MIME in "${MIMETYPE_EXTENSIONS[@]}"; do |
| 220 | + mimetype="${MIME%%:*}" |
| 221 | + extension="${MIME#*:}" |
| 222 | +
|
| 223 | + if [[ "${mime}" == "${mimetype}" && "${file##*.}" != "${extension}" ]]; then |
| 224 | + printf " Rename file to '%s' " "${file}.${extension}" |
| 225 | + mv "${file}" "${file}.${extension}" |
| 226 | + if [[ $? -eq 0 ]]; then |
| 227 | + printf "[OK]\n" |
| 228 | + else |
| 229 | + printf "[FAILED]\n" |
| 230 | + fi |
| 231 | +
|
| 232 | + printf " Patching LaTeX file for '%s' " "${file}" |
| 233 | + sed -i "s:{{${file%.*}}\.${file##*.}}:{{${file}}.${extension}}:g" *.tex |
| 234 | + if [[ $? -eq 0 ]]; then |
| 235 | + printf "[OK]\n" |
| 236 | + else |
| 237 | + printf "[FAILED]\n" |
| 238 | + fi |
| 239 | +
|
| 240 | + found=1 |
| 241 | + break |
| 242 | + fi |
| 243 | + done |
| 244 | + if [[ $found -eq 0 ]]; then |
| 245 | + printf "[SKIPPED]\n" |
| 246 | + fi |
| 247 | + done < <(find . -type f -not -iname "*.cls" -not -iname "*.sty" -not -iname "*.xdy" -not -iname "*.svg" -not -iname "*.png" -not -iname "*.jpg" | sed 's:./::') |
| 248 | +
|
| 249 | + - name: Workaround II - https://github.com/sphinx-doc/sphinx/issues/13189 |
| 250 | + run: | |
| 251 | + printf "Changing directory to '${{ inputs.doc_directory || '.' }}/_build/latex' ...\n" |
| 252 | + cd ${{ inputs.doc_directory || '.' }}/_build/latex |
| 253 | +
|
| 254 | + printf "Searching for downloaded images, that need normalization ...\n" |
| 255 | + for imageExt in png svg jpg jpeg; do |
| 256 | + printf " Processing '%s' ...\n" "${imageExt}" |
| 257 | + while IFS=$'\n' read -r imageFile; do |
| 258 | + newFile="${imageFile//%/_}"; |
| 259 | +
|
| 260 | + printf " %s\n" "$imageFile"; |
| 261 | + if [[ "${imageFile}" != "${newFile}" ]]; then |
| 262 | + printf " Rename file to '%s' " "${newFile}" |
| 263 | + mv "${imageFile}" "${newFile}" |
| 264 | + if [[ $? -eq 0 ]]; then |
| 265 | + printf "[OK]\n" |
| 266 | + else |
| 267 | + printf "[FAILED]\n" |
| 268 | + fi |
| 269 | +
|
| 270 | + printf " Patching LaTeX file for '%s' " "${newFile}" |
| 271 | + sed -i "s:{{${imageFile%.*}}\.${imageFile##*.}}:{{${newFile%.*}}.${newFile##*.}}:g" *.tex |
| 272 | + if [[ $? -eq 0 ]]; then |
| 273 | + printf "[OK]\n" |
| 274 | + else |
| 275 | + printf "[FAILED]\n" |
| 276 | + fi |
| 277 | + fi |
| 278 | + done < <(find . -type f -iname "*.$imageExt" | sed 's:./::') |
| 279 | + done |
| 280 | +
|
| 281 | + - name: 📤 Upload 'LaTeX Documentation' artifact |
| 282 | + uses: pyTooling/upload-artifact@v6 |
| 283 | + continue-on-error: true |
| 284 | + with: |
| 285 | + name: ${{ inputs.latex_artifact }} |
| 286 | + working-directory: ${{ inputs.doc_directory }}/_build/latex |
| 287 | + path: '*' |
| 288 | + if-no-files-found: error |
| 289 | + retention-days: 1 |
0 commit comments