-
Notifications
You must be signed in to change notification settings - Fork 4
255 lines (210 loc) · 8.74 KB
/
deploy-site.yml
File metadata and controls
255 lines (210 loc) · 8.74 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# Workflow for deploying versioned documentation to GitHub Pages
name: Deploy Documentation
on:
# Runs on pushes targeting the default branch (publishes to /snapshot/)
push:
branches: ["main"]
paths:
- 'pom.xml'
- 'src/**'
- '.github/**'
# Runs on release publish (publishes to /latest/ and /vX.Y.Z/)
release:
types: [published]
# Allows manual trigger
workflow_dispatch:
inputs:
version:
description: 'Specific version/tag to build (leave empty for snapshot from main)'
type: string
default: ''
publish_as_latest:
description: 'Also publish as latest?'
type: boolean
default: false
rebuild_all_versions:
description: 'Rebuild documentation for all release tags?'
type: boolean
default: false
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
pages: write
id-token: write
# Allow only one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build-and-deploy:
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v5
with:
java-version: '17'
distribution: 'temurin'
- name: Checkout gh-pages branch
uses: actions/checkout@v6
with:
ref: gh-pages
path: site
continue-on-error: true
- name: Initialize site if needed
run: |
if [ ! -d "site/.git" ]; then
rm -rf site
mkdir -p site
cd site
git init
git checkout -b gh-pages
git remote add origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
fi
- name: Get all release tags
id: tags
run: |
# Get all tags that look like version numbers (v1.0.0 or 1.0.0)
TAGS=$(git tag -l | grep -E '^v?[0-9]+\.[0-9]+' | sort -Vr)
echo "all_tags<<EOF" >> $GITHUB_OUTPUT
echo "$TAGS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# Get the latest tag
LATEST_TAG=$(echo "$TAGS" | head -n 1)
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
# Determine what to build
if [[ "${{ github.event_name }}" == "release" ]]; then
echo "build_tag=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
echo "is_release=true" >> $GITHUB_OUTPUT
elif [[ -n "${{ inputs.version }}" ]]; then
# Manual trigger with specific version
VERSION="${{ inputs.version }}"
# Add 'v' prefix if not present for tag lookup
if [[ ! "$VERSION" =~ ^v ]]; then
TAG="v$VERSION"
else
TAG="$VERSION"
fi
echo "build_tag=$TAG" >> $GITHUB_OUTPUT
echo "is_release=true" >> $GITHUB_OUTPUT
else
echo "build_tag=" >> $GITHUB_OUTPUT
echo "is_release=false" >> $GITHUB_OUTPUT
fi
- name: Build snapshot documentation (main branch)
if: steps.tags.outputs.is_release == 'false' && inputs.rebuild_all_versions != true
run: |
./mvnw clean site -DskipTests -Dcheckstyle.skip=true
rm -rf "site/snapshot"
mkdir -p "site/snapshot"
cp -r target/site/* "site/snapshot/"
- name: Build documentation for specific version
if: steps.tags.outputs.is_release == 'true' && inputs.rebuild_all_versions != true
run: |
TAG="${{ steps.tags.outputs.build_tag }}"
VERSION="${TAG#v}" # Remove 'v' prefix
echo "Building documentation for $TAG (version $VERSION)"
git checkout "$TAG"
./mvnw clean site -DskipTests -Dcheckstyle.skip=true
rm -rf "site/$VERSION"
mkdir -p "site/$VERSION"
cp -r target/site/* "site/$VERSION/"
# Update /latest/ if this is a release event or publish_as_latest is true
if [[ "${{ github.event_name }}" == "release" ]] || [[ "${{ inputs.publish_as_latest }}" == "true" ]]; then
rm -rf "site/latest"
mkdir -p "site/latest"
cp -r target/site/* "site/latest/"
fi
git checkout main
- name: Build documentation for all release tags
if: inputs.rebuild_all_versions == true
run: |
LATEST_TAG="${{ steps.tags.outputs.latest_tag }}"
while IFS= read -r TAG; do
if [[ -z "$TAG" ]]; then continue; fi
VERSION="${TAG#v}" # Remove 'v' prefix
echo "Building documentation for $TAG (version $VERSION)"
git checkout "$TAG"
./mvnw clean site -DskipTests -Dcheckstyle.skip=true
rm -rf "site/$VERSION"
mkdir -p "site/$VERSION"
cp -r target/site/* "site/$VERSION/"
# If this is the latest tag, also update /latest/
if [[ "$TAG" == "$LATEST_TAG" ]]; then
rm -rf "site/latest"
mkdir -p "site/latest"
cp -r target/site/* "site/latest/"
fi
done <<< "${{ steps.tags.outputs.all_tags }}"
# Return to main and build snapshot
git checkout main
./mvnw clean site -DskipTests -Dcheckstyle.skip=true
rm -rf "site/snapshot"
mkdir -p "site/snapshot"
cp -r target/site/* "site/snapshot/"
- name: Copy version index page
run: |
cp .github/templates/versions.html site/index.html
- name: Update version list from git tags
run: |
cd site
# Get versions from git tags (already sorted by version, descending)
VERSIONS=$(git -C .. tag -l | grep -E '^v?[0-9]+\.[0-9]+' | sed 's/^v//' | sort -Vr)
HAS_SNAPSHOT=$([ -d "snapshot" ] && echo "true" || echo "false")
# Generate version links
VERSION_HTML=""
IS_FIRST_VERSION="true"
# Add snapshot if exists
if [ "$HAS_SNAPSHOT" = "true" ]; then
VERSION_HTML+='<li><a href="./snapshot/">Development (main branch)</a><span class="badge snapshot">snapshot</span></li>'
fi
# Add versioned releases from tags (first one is latest)
for v in $VERSIONS; do
if [ -d "$v" ]; then
if [ "$IS_FIRST_VERSION" = "true" ]; then
VERSION_HTML+="<li class=\"latest-version\"><a href=\"./$v/\">Version $v</a><span class=\"badge latest\">latest</span></li>"
IS_FIRST_VERSION="false"
else
VERSION_HTML+="<li><a href=\"./$v/\">Version $v</a><span class=\"badge archived\">$v</span></li>"
fi
fi
done
# Update the index.html using the placeholder
sed -i "s|<!-- VERSION_LIST_PLACEHOLDER -->|$VERSION_HTML|" index.html
- name: Deploy to GitHub Pages
run: |
cd site
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Set remote URL with token for authentication
git remote set-url origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" 2>/dev/null || \
git remote add origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
git add -A
# Create descriptive commit message
if [[ "${{ inputs.rebuild_all_versions }}" == "true" ]]; then
COMMIT_MSG="Rebuild documentation for all versions"
elif [[ "${{ steps.tags.outputs.is_release }}" == "true" ]]; then
COMMIT_MSG="Deploy documentation: ${{ steps.tags.outputs.build_tag }}"
else
COMMIT_MSG="Deploy documentation: snapshot"
fi
git diff --staged --quiet || git commit -m "$COMMIT_MSG"
# Push, creating the branch if it doesn't exist
git push -u origin gh-pages --force
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v4
with:
path: 'site'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4