Repository navigation
164 lines (146 loc) · 5.78 KB
/
Copy pathDocs.yml
File metadata and controls
164 lines (146 loc) · 5.78 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
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
name: Docs
on:
push:
branches:
- main
release:
types: [published]
workflow_dispatch:
permissions:
contents: write
concurrency:
group: pages
cancel-in-progress: false
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
# Determine deploy target from ref
- name: Set deploy version
id: version
run: |
if [ "${{ github.event_name }}" = "release" ]; then
VERSION="${{ github.event.release.tag_name }}"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "is_release=true" >> "$GITHUB_OUTPUT"
else
echo "version=dev" >> "$GITHUB_OUTPUT"
echo "is_release=false" >> "$GITHUB_OUTPUT"
fi
# Build docs
- uses: julia-actions/setup-julia@v3
with:
version: '1'
- uses: julia-actions/cache@v3
- name: Install OpenGL dependencies
run: |
sudo apt-get update
sudo apt-get install -y xorg-dev mesa-utils xvfb libgl1 freeglut3-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev xsettingsd x11-xserver-utils
- name: Install docs dependencies
run: DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' julia --project=docs -e 'using Pkg; Pkg.develop(path="."); Pkg.instantiate()'
- name: Install lcov
run: sudo apt-get install -y lcov
- name: Fetch benchmark results
run: git fetch origin benchmark-results || true
- uses: quarto-dev/quarto-actions/setup@v2
- name: Set build date
run: sed -i "s/__BUILD_DATE__/$(date -u +'%Y-%m-%d')/" docs/_quarto.yml
- name: Render docs
run: DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' quarto render docs
env:
QUARTO_JULIA_PROJECT: docs
# Deploy to gh-pages branch
- name: Deploy to gh-pages
env:
VERSION: ${{ steps.version.outputs.version }}
IS_RELEASE: ${{ steps.version.outputs.is_release }}
REPO_NAME: ${{ github.event.repository.name }}
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# Clone gh-pages branch or create orphan
if git ls-remote --exit-code origin gh-pages; then
git clone --branch gh-pages --single-branch "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git" gh-pages-deploy
else
mkdir gh-pages-deploy
cd gh-pages-deploy
git init
git checkout --orphan gh-pages
git commit --allow-empty -m "Initialize gh-pages"
cd ..
fi
# Copy built docs to version directory
rm -rf "gh-pages-deploy/${VERSION}"
cp -r docs/_site "gh-pages-deploy/${VERSION}"
cd gh-pages-deploy
# If release tag: update versions.json and stable redirect
if [ "$IS_RELEASE" = "true" ]; then
# Update versions.json
if [ -f versions.json ]; then
# Add new version and sort by semver descending
python3 -c "
import json, re
with open('versions.json') as f:
versions = json.load(f)
ver = '${VERSION}'
if ver not in versions:
versions.append(ver)
def semver_key(v):
nums = re.findall(r'\d+', v)
return tuple(int(n) for n in nums)
versions.sort(key=semver_key, reverse=True)
with open('versions.json', 'w') as f:
json.dump(versions, f, indent=2)
"
else
echo "[\"${VERSION}\"]" > versions.json
fi
# Update stable redirect
mkdir -p stable
cat > stable/index.html << STABLE_EOF
<!DOCTYPE html>
<html>
<head><meta http-equiv="refresh" content="0; url=/${REPO_NAME}/${VERSION}/"></head>
<body>Redirecting to <a href="/${REPO_NAME}/${VERSION}/">latest stable</a>...</body>
</html>
STABLE_EOF
fi
# Create stable placeholder if no releases yet
if [ ! -d stable ]; then
mkdir -p stable
cat > stable/index.html << PLACEHOLDER_EOF
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>${REPO_NAME} — No Stable Release Yet</title>
<meta http-equiv="refresh" content="5; url=/${REPO_NAME}/dev/">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="d-flex align-items-center justify-content-center min-vh-100 bg-light">
<div class="text-center p-5">
<h1 class="mb-3">${REPO_NAME}</h1>
<p class="lead text-muted">No stable version has been released yet.<br>Redirecting to the <a href="/${REPO_NAME}/dev/">development docs</a> in 5 seconds...</p>
</div>
</body>
</html>
PLACEHOLDER_EOF
fi
# Always update root redirect to stable
cat > index.html << ROOT_EOF
<!DOCTYPE html>
<html>
<head><meta http-equiv="refresh" content="0; url=/${REPO_NAME}/stable/"></head>
<body>Redirecting to <a href="/${REPO_NAME}/stable/">stable docs</a>...</body>
</html>
ROOT_EOF
touch .nojekyll
git add -A
if git diff --cached --quiet; then
echo "No changes to deploy"
else
git commit -m "Deploy docs: ${VERSION}"
git push "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git" HEAD:gh-pages
fi