-
-
Notifications
You must be signed in to change notification settings - Fork 262
184 lines (163 loc) · 5.24 KB
/
deploy_docs.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
name: Deploy documentation
# Check for reference:
# https://github.com/s1rius/ezlog/blob/20dce11e6d324bb18f57dc7c7c6d4a8bf40064de/.github/workflows/publish_pages.yml
on:
schedule:
- cron: "40 03 */2 * *" # Runs at 03:40, every 2 days
push:
branches:
- main
paths:
- docs/**/*.md
- docs/**/*.png
- docs/**/*.jpg
- docs/**/*.jpeg
- docs/**/*.po
- .github/workflows/deploy_docs.yml
- .github/workflows/install-mdbook/action.yml
- README*.md
- docs/book.toml
pull_request:
branches:
- main
paths:
- docs/**/*.md
- docs/**/*.png
- docs/**/*.jpg
- docs/**/*.jpeg
- docs/**/*.po
- .github/workflows/deploy_docs.yml
- .github/workflows/install-mdbook/action.yml
- README*.md
- docs/book.toml
workflow_dispatch:
concurrency:
group: pages
cancel-in-progress: true
env:
runner: ubuntu-latest
cache-mdbook-name: cache-mdbook-bins
EXTRA_LANGUAGES:
SITE_URL: /bazzite/
MDBOOK_output__html__git_repository_url: "${{ github.server_url }}/${{ github.repository }}"
MDBOOK_output__html__edit_url_template: "${{ github.server_url }}/${{ github.repository }}/edit/${{ github.ref_name }}/docs/{path}"
jobs:
deploy:
permissions:
contents: read # To push a branch
pages: write # To push to a GitHub Pages site
id-token: write # To update the deployment status
runs-on: ubuntu-latest
# environment:
# name: github-pages
# url: ${{ steps.deployment.outputs.page_url }}
defaults:
run:
working-directory: ./docs
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install python dependencies
run: |
pip install --user requests
- name: Cache mdbook
id: cache-mdbook
uses: actions/cache@v4
with:
path: |
~/.cargo/bin
~/.local/share/headless-chrome
key: ${{ runner.os }}-build-${{ env.cache-mdbook-name }}-${{ hashFiles('.github/workflows/install-mdbook/action.yml') }}
- name: Add mdbook to PATH
if: steps.cache-mdbook.outputs.cache-hit == 'true'
run: |
echo ~/.cargo/bin:$PATH >> $GITHUB_PATH
- name: Install mdbook
if: steps.cache-mdbook.outputs.cache-hit != 'true'
uses: ./.github/workflows/install-mdbook
# Necessary in order to have fetch_discourse_md.py available for mdbook-cmd
- name: Add docs/utils to PATH
run: |
echo $PWD/utils:$PATH >> $GITHUB_PATH
- name: Test fetch_discourse_md.py
run: |
echo "::group::Try fetching a post from discourse"
fetch_discourse_md.py -d "https://universal-blue.discourse.group/docs?topic=31" 2>&1 >/dev/null
echo "::endgroup::"
- name: Build book in English
env:
MDBOOK_output__html__site_url: ${{ env.SITE_URL }}
DEBUG: "1"
run: |
# This assumes your book is in the root of your repository.
# Just add a `cd` here if you need to change to another directory.
mdbook build -d $GITHUB_WORKSPACE/book
(
cd $GITHUB_WORKSPACE/book
shopt -s dotglob
mv {html,pdf}/* ./
)
- name: Build all translations
env:
DEBUG: "1"
run: |
for po_lang in ${{ env.EXTRA_LANGUAGES }}; do
echo "::group::Building $po_lang translation"
MDBOOK_BOOK__LANGUAGE=$po_lang \
MDBOOK_OUTPUT__HTML__SITE_URL=${{ env.SITE_URL }}$po_lang/ \
mdbook build -d $GITHUB_WORKSPACE/book/$po_lang
(
cd $GITHUB_WORKSPACE/book/$po_lang
shopt -s dotglob
mv {html,pdf}/* ./
)
echo "::endgroup::"
done
- name: Generate translation progress report
if: env.EXTRA_LANGUAGES != ''
continue-on-error: true
run: |
i18n-report report $GITHUB_WORKSPACE/book/i18n_report.html po/*.po
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ${{ github.workspace }}/book
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
with:
token: ${{ github.token }}
clean_cache:
needs: deploy
runs-on: ubuntu-latest
permissions:
contents: read
actions: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache Cleanup
env:
GH_TOKEN: ${{ github.token }}
run: |
set -x
old_caches=($(gh cache list \
--repo ${{ github.repository }} \
--key "${{ runner.os }}-build-${{ env.cache-mdbook-name }}-" \
--sort created_at -O asc --json id | jq '.[:-1][].id'))
for id in "${old_caches[@]}"; do
gh cache delete $id
done
- name: Remove Page Artifacts
uses: remagpie/gha-remove-artifact@v1
with:
only-name: github-pages
max-age: 7776000 # 90 days
max-count: 50