|
| 1 | +name: Build Documents |
| 2 | + |
| 3 | +env: |
| 4 | + TZ: UTC |
| 5 | + I10N_VERSION: 4.3 |
| 6 | + DOC_VERSION: 4.3 |
| 7 | + GH_TOKEN: ${{ github.token }} |
| 8 | + TARGET_LANGUAGE: ${{ vars.TARGET_LANGUAGE || 'zh_CN' }} |
| 9 | + |
| 10 | +on: |
| 11 | + workflow_dispatch: |
| 12 | + schedule: |
| 13 | + - cron: "5 4 */7 * *" |
| 14 | + |
| 15 | +jobs: |
| 16 | + setup: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + RUNNER-LABEL: ${{ steps.runner.outputs.LABEL }} |
| 20 | + MATRIX-LANGUAGES: ${{ steps.precheck.outputs.LANGS }} |
| 21 | + steps: |
| 22 | + - name: Choose runner |
| 23 | + id: runner |
| 24 | + run: | |
| 25 | + echo "LABEL=${{ vars.RUNNER_LABEL || 'ubuntu-latest' }}" >> $GITHUB_OUTPUT |
| 26 | +
|
| 27 | + - name: Precheck |
| 28 | + id: precheck |
| 29 | + run: | |
| 30 | + mkdir version |
| 31 | + LANGS=() |
| 32 | + for lang in ${TARGET_LANGUAGE//,/ }; do |
| 33 | + if [[ "$lang" == 'zh_CN' ]]; then |
| 34 | + lang_weblate='zh_Hans' |
| 35 | + elif [[ "$lang" == 'zh_TW' ]]; then |
| 36 | + lang_weblate='zh_Hant' |
| 37 | + else |
| 38 | + lang_weblate=$lang |
| 39 | + fi |
| 40 | + version=$(curl -s "https://hosted.weblate.org/api/translations/godot-engine/godot-docs/$lang_weblate/statistics/" | jq -r '.last_change') |
| 41 | + last_version=$(curl -s "https://raw.githubusercontent.com/ignimutos/godot-docs-offline/$DOC_VERSION/version/$lang") |
| 42 | + if [[ "$last_version" == '404*' ]]; then |
| 43 | + last_version='1970-01-01T00:00:00+0000' |
| 44 | + fi |
| 45 | + if [[ $(date -d "$last_version" '+%s') == $(date -d "$version" '+%s') ]]; then |
| 46 | + echo "language $lang no update detected" |
| 47 | + else |
| 48 | + echo "$lang: $last_version -> $version" |
| 49 | + echo $version > version/$lang |
| 50 | + LANGS+=($lang) |
| 51 | + fi |
| 52 | + done |
| 53 | +
|
| 54 | + JSON=$(jq -c -n '$ARGS.positional' --args "${LANGS[@]}") |
| 55 | + echo "LANGS=$JSON" |
| 56 | + echo "LANGS=$JSON" >> $GITHUB_OUTPUT |
| 57 | +
|
| 58 | + - name: Upload version |
| 59 | + uses: actions/upload-artifact@v4 |
| 60 | + with: |
| 61 | + name: version |
| 62 | + path: | |
| 63 | + version/* |
| 64 | +
|
| 65 | + build: |
| 66 | + needs: setup |
| 67 | + runs-on: ${{ needs.setup.outputs.RUNNER-LABEL }} |
| 68 | + permissions: |
| 69 | + contents: write |
| 70 | + strategy: |
| 71 | + max-parallel: 1 |
| 72 | + fail-fast: false |
| 73 | + matrix: |
| 74 | + language: ${{ fromJSON(needs.setup.outputs.MATRIX-LANGUAGES) }} |
| 75 | + env: |
| 76 | + READTHEDOCS_LANGUAGE: ${{ matrix.language }} |
| 77 | + steps: |
| 78 | + - name: Checkout l10n |
| 79 | + uses: actions/checkout@v4 |
| 80 | + with: |
| 81 | + repository: godotengine/godot-docs-l10n |
| 82 | + ref: ${{ env.I10N_VERSION }} |
| 83 | + |
| 84 | + - name: Checkout Doc |
| 85 | + uses: actions/checkout@v4 |
| 86 | + with: |
| 87 | + repository: godotengine/godot-docs |
| 88 | + ref: ${{ env.DOC_VERSION }} |
| 89 | + path: docs |
| 90 | + |
| 91 | + - name: Copy zh_CN class reference translate |
| 92 | + if: ${{ env.READTHEDOCS_LANGUAGE == 'zh_CN' }} |
| 93 | + run: | |
| 94 | + cp -rf classes/zh_CN/* docs/classes/ |
| 95 | +
|
| 96 | + - name: Get Python version |
| 97 | + id: pythonv |
| 98 | + run: | |
| 99 | + echo "PYTHON_VERSION=$(python3 --version)" >> $GITHUB_OUTPUT |
| 100 | +
|
| 101 | + - name: Restore cached virtualenv |
| 102 | + id: restore_cache |
| 103 | + uses: actions/cache/restore@v4 |
| 104 | + with: |
| 105 | + key: venv-${{ needs.setup.outputs.RUNNER-LABEL }}-${{ steps.pythonv.outputs.PYTHON_VERSION }}-${{ hashFiles('docs/requirements.txt') }} |
| 106 | + path: docs/.venv |
| 107 | + |
| 108 | + - name: Install dependencies |
| 109 | + run: | |
| 110 | + cd docs |
| 111 | + python3 -m venv .venv |
| 112 | + source .venv/bin/activate |
| 113 | + python3 -m pip install setuptools |
| 114 | + python3 -m pip install -r requirements.txt |
| 115 | + echo "$VIRTUAL_ENV/bin" >> $GITHUB_PATH |
| 116 | + echo "VIRTUAL_ENV=$VIRTUAL_ENV" >> $GITHUB_ENV |
| 117 | + sudo apt-get update |
| 118 | + sudo apt-get install -y parallel libwebp7 imagemagick zip |
| 119 | +
|
| 120 | + - name: Save virtualenv cache |
| 121 | + if: steps.restore_cache.outputs.cache-hit != 'true' |
| 122 | + uses: actions/cache/save@v4 |
| 123 | + with: |
| 124 | + key: venv-${{ needs.setup.outputs.RUNNER-LABEL }}-${{ steps.pythonv.outputs.PYTHON_VERSION }}-${{ hashFiles('docs/requirements.txt') }} |
| 125 | + path: docs/.venv |
| 126 | + |
| 127 | + - name: Sphinx - Build html |
| 128 | + run: | |
| 129 | + mkdir artifact |
| 130 | + cd docs |
| 131 | + make SPHINXOPTS='--color -j 8' html |
| 132 | + cd _build/html |
| 133 | + zip -qr GodotEngine-$READTHEDOCS_LANGUAGE.zip . -x '.venv/*' |
| 134 | + mv GodotEngine-$READTHEDOCS_LANGUAGE.zip ../../../artifact/ |
| 135 | +
|
| 136 | + - name: Sphinx - Build epub |
| 137 | + run: | |
| 138 | + cd docs |
| 139 | + # Convert WebP images to PNG and replace references, so that ePub readers can display those images. |
| 140 | + # The ePub 3.0 specification has WebP support, but it's not widely supported by apps and e-readers yet. |
| 141 | + shopt -s globstar nullglob |
| 142 | + parallel --will-cite convert {} {.}.png ::: {about,community,contributing,getting_started,img,tutorials}/**/*.webp |
| 143 | + parallel --will-cite sed -i "s/\\.webp$/\\.png/g" ::: {about,community,contributing,getting_started,tutorials}/**/*.rst |
| 144 | +
|
| 145 | + # Remove banners at the top of each page when building `latest`. |
| 146 | + sed -i 's/"godot_is_latest": True/"godot_is_latest": False/' conf.py |
| 147 | + sed -i 's/"godot_show_article_status": True/"godot_show_article_status": False/' conf.py |
| 148 | +
|
| 149 | + make SPHINXOPTS='--color -j 8' epub |
| 150 | + mv _build/epub/GodotEngine.epub ../artifact/GodotEngine-$READTHEDOCS_LANGUAGE.epub |
| 151 | +
|
| 152 | + - name: Upload artifact |
| 153 | + uses: actions/upload-artifact@v4 |
| 154 | + with: |
| 155 | + name: build-${{ env.READTHEDOCS_LANGUAGE }} |
| 156 | + path: | |
| 157 | + artifact/* |
| 158 | +
|
| 159 | + update: |
| 160 | + runs-on: ubuntu-latest |
| 161 | + needs: [setup, build] |
| 162 | + permissions: |
| 163 | + contents: write |
| 164 | + steps: |
| 165 | + - name: Download build |
| 166 | + uses: actions/download-artifact@v4 |
| 167 | + with: |
| 168 | + pattern: build-* |
| 169 | + path: build |
| 170 | + merge-multiple: true |
| 171 | + |
| 172 | + - name: Display structure of build files |
| 173 | + run: ls -R |
| 174 | + |
| 175 | + - name: Checkout repo |
| 176 | + uses: actions/checkout@v4 |
| 177 | + with: |
| 178 | + path: repo |
| 179 | + |
| 180 | + - name: Override version |
| 181 | + uses: actions/download-artifact@v4 |
| 182 | + with: |
| 183 | + name: version |
| 184 | + path: repo/version |
| 185 | + |
| 186 | + - name: Generate update info |
| 187 | + run: | |
| 188 | + cat << EOF > release_body.md |
| 189 | + # Translate changelog |
| 190 | + $(echo '') |
| 191 | + | Language | LastUpdate | |
| 192 | + | :------- | :-------- | |
| 193 | + EOF |
| 194 | +
|
| 195 | + for file in repo/version/*; do |
| 196 | + name=${file##*/} |
| 197 | + content=$(date -d $(cat $file) '+%Y-%m-%d %H:%M:%S') |
| 198 | + echo "| $name | $content |" >> release_body.md |
| 199 | + done |
| 200 | +
|
| 201 | + - name: Add Tag |
| 202 | + run: | |
| 203 | + cd repo |
| 204 | + git tag 4.3 -f |
| 205 | + git push --tag |
| 206 | +
|
| 207 | + - name: Release |
| 208 | + uses: softprops/action-gh-release@v2 |
| 209 | + with: |
| 210 | + tag_name: ${{ env.DOC_VERSION }} |
| 211 | + body_path: release_body.md |
| 212 | + files: "build/*" |
| 213 | + |
| 214 | + - name: Update repository version |
| 215 | + run: | |
| 216 | + cd repo |
| 217 | + git config user.name "github-actions[bot]" |
| 218 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 219 | + git add . |
| 220 | + git commit -m "chore: bump translate version" |
| 221 | + git push |
0 commit comments