Repository navigation
98 lines (90 loc) · 3.32 KB
/
Copy pathdocs.yml
File metadata and controls
98 lines (90 loc) · 3.32 KB
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
name: Deploy Docs
on:
push:
branches: [main]
paths:
- "docs/**"
- ".github/workflows/docs.yml"
workflow_dispatch:
# Only needs to read this repo, the push to the hub uses HUB_DEPLOY_TOKEN.
permissions:
contents: read
concurrency:
group: docs-deploy
cancel-in-progress: true
jobs:
deploy:
name: Build and publish docs
runs-on: ubuntu-latest
steps:
- name: Checkout MenuAPI
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install dependencies
run: |
set -e
for site in docs/fivem docs/redm docs/archive/legacy-v3; do
(cd "$site" && npm ci)
done
# Astro bakes the base into every URL, so each site is built once per prefix. /mapi is the old
# prefix, kept so links from the old docs keep working.
- name: Build all sites
run: |
set -e
build() {
echo "== building $1 with base $2 =="
(cd "$1" && DOCS_BASE="$2" npm run build)
mkdir -p "_site$2"
cp -r "$1/dist/." "_site$2/"
}
rm -rf _site
for P in menuapi mapi; do
build docs/fivem "/$P/fivem"
build docs/redm "/$P/redm"
build docs/archive/legacy-v3 "/$P/legacy"
node docs/tools/forward-pages.mjs "_site/$P/fivem" "_site/$P/enhanced" "/$P/fivem"
cp docs/landing/index.html "_site/$P/index.html"
cp docs/fivem/public/favicon.png "_site/$P/favicon.png"
done
# GitHub Pages serves a project site at the case sensitive /RepoName/ path, so lowercase /menuapi/
# (and the old /mapi/) come from pushing the built site into the hub site instead.
- name: Publish to hub site
env:
HUB_TOKEN: ${{ secrets.HUB_DEPLOY_TOKEN }}
run: |
set -euo pipefail
if [ -z "${HUB_TOKEN}" ]; then
echo "::error::HUB_DEPLOY_TOKEN secret is not set. See docs/README.md for setup."
exit 1
fi
git clone --depth 1 --branch main \
"https://x-access-token:${HUB_TOKEN}@github.com/TomGrobbe/TomGrobbe.github.io.git" hub
# Only the two MenuAPI folders are replaced. The hub's own index.html, CNAME, .nojekyll and the
# other products' folders stay untouched.
for P in menuapi mapi; do
rm -rf "hub/$P"
cp -r "_site/$P" "hub/$P"
done
# Without this Jekyll skips Astro's _astro asset folder.
touch hub/.nojekyll
cd hub
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
if git diff --cached --quiet; then
echo "No documentation changes to publish."
else
git commit -m "Deploy MenuAPI docs"
# The vMenu docs push to the same hub, so a push can lose the race and needs a rebase.
for attempt in 1 2 3; do
if git push origin main; then
exit 0
fi
git pull --rebase origin main
done
echo "::error::Could not push to the hub after 3 attempts."
exit 1
fi