-
-
Notifications
You must be signed in to change notification settings - Fork 94
205 lines (168 loc) · 7.75 KB
/
docs-site.yml
File metadata and controls
205 lines (168 loc) · 7.75 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
# Generates and deploys static site to GitHub Pages
# https://docs.github.com/en/pages/getting-started-with-github-pages/using-custom-workflows-with-github-pages
# Reference workflow: https://github.com/actions/starter-workflows/blob/main/pages/jekyll-gh-pages.yml
name: Metro Docs Site
on:
push:
branches: ["main"]
tags:
- '*.*.*' # Matches semantic versioning tags
# PR trigger for docs dry run when requirements change
pull_request:
paths:
- '.github/workflows/mkdocs-requirements.txt'
# Allows manual deployements (if needed)
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow pushing to `gh-pages` branch
permissions:
contents: write
pages: write
id-token: write
# Only allow one docs deployment at a time per type, prioritize tagged releases
concurrency:
group: ${{ startsWith(github.ref, 'refs/tags/') && 'pages-release' || 'pages-dev' }}
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }}
jobs:
# Metro docs site build job
docs-site:
runs-on: ubuntu-latest
if: github.repository == 'zacsweers/metro' && github.event_name != 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0 # Full history needed for git-revision-date-localized plugin
- name: Setup Gradle
uses: ./.github/actions/setup-gradle
with:
encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
cache-read-only: ${{ github.ref != 'refs/heads/main' }}
- name: Generate API docs
# NOTE: The `dokkaPublications.html` task is pre-configured to generate HTML in `/docs/api`.
run: ./scripts/generate_docs_dokka.sh
env:
GRADLE_OPTS: -Xmx4g # Dokka can be memory intensive, so we increase the heap size
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Install docs dependencies
run: |
pip install --requirement .github/workflows/mkdocs-requirements.txt
- name: Copy documentation files
run: ./scripts/copy_docs_files.sh
- name: Validate documentation file mappings
run: ./scripts/copy_docs_files_mapping_validator.sh
- name: Extract Metro version from gradle.properties
id: version
run: |
METRO_VERSION=$(grep "VERSION_NAME=" gradle.properties | cut -d'=' -f2)
echo "METRO_VERSION=$METRO_VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $METRO_VERSION"
- name: Validate version format
run: |
VERSION="${{ steps.version.outputs.METRO_VERSION }}"
# Check if version is empty
if [[ -z "$VERSION" ]]; then
echo "ERROR: VERSION_NAME is empty in gradle.properties"
exit 1
fi
# Check if version matches x.y.z, x.y.z-SNAPSHOT, or x.y.z-<prerelease> pattern
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-(SNAPSHOT|[a-zA-Z]+[0-9]*))?$ ]]; then
echo "ERROR: VERSION_NAME '$VERSION' does not match expected format:"
echo " Expected: x.y.z, x.y.z-SNAPSHOT, or x.y.z-<prerelease> (e.g., 1.2.3, 1.2.3-SNAPSHOT, 1.0.0-RC1)"
echo " Actual: $VERSION"
exit 1
fi
echo "Version format is valid: $VERSION"
- name: Configure Git for Mike
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
- name: Fetch gh-pages branch
run: |
# Fetch the gh-pages branch to ensure we have the latest state
git fetch origin gh-pages:gh-pages || echo "gh-pages branch doesn't exist yet (first deployment)"
- name: Show current mike versions
run: |
echo "Current mike versions available:"
mike list || echo "No docs site versions found (likely first deployment)"
- name: Validate docs build with Zensical
run: |
echo "Building docs for validation with Zensical..."
zensical build
echo "Validating directory URL structure..."
# Check that use_directory_urls: true is working correctly
# This setting converts installation.md -> installation/index.html
# enabling clean URLs like /installation/ instead of /installation.html
if [ -f "site/installation/index.html" ]; then
echo "✔ Directory URLs are working correctly (installation/index.html exists)"
else
echo "✖ Directory URLs validation failed - installation/index.html not found"
echo "This suggests use_directory_urls: true is not working properly"
exit 1
fi
echo "Cleaning up build directory..."
rm -rf site
echo "Docs validation completed successfully"
- name: Re-sync gh-pages branch before deployment
run: |
# Safely update local gh-pages to match remote state to avoid push conflicts
git fetch origin gh-pages
git update-ref refs/heads/gh-pages origin/gh-pages
- name: Deploy SNAPSHOT Docs with mike
if: ${{ success() && contains(steps.version.outputs.METRO_VERSION, 'SNAPSHOT') }}
run: mike deploy --update-aliases --push ${{ steps.version.outputs.METRO_VERSION }} snapshot
- name: Deploy Release Docs with mike
if: ${{ success() && !contains(steps.version.outputs.METRO_VERSION, 'SNAPSHOT') }}
run: mike deploy --update-aliases --push ${{ steps.version.outputs.METRO_VERSION }} latest
- name: Delete old doc versions
run: |
git fetch origin gh-pages --depth=1
./scripts/delete_old_version_docs.sh
# Docs dry run job for PRs that change requirements.txt
docs-dry-run:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0 # Full history needed for git-revision-date-localized plugin
- name: Setup Gradle
uses: ./.github/actions/setup-gradle
with:
encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
cache-read-only: true
- name: Generate API docs
run: ./scripts/generate_docs_dokka.sh
env:
GRADLE_OPTS: -Xmx4g # Dokka can be memory intensive, so we increase the heap size
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Install docs dependencies
run: |
pip install --requirement .github/workflows/mkdocs-requirements.txt
- name: Copy documentation files
run: ./scripts/copy_docs_files.sh
- name: Validate documentation file mappings
run: ./scripts/copy_docs_files_mapping_validator.sh
- name: Build docs (dry run with Zensical)
run: |
echo "Building docs as a dry run to verify requirements and other configs are working..."
zensical build
echo "Validating directory URL structure..."
# Verify that use_directory_urls: true configuration is effective
# This creates installation/index.html from installation.md, enabling
# clean URLs (/installation/) instead of file URLs (/installation.html)
if [ -f "site/installation/index.html" ]; then
echo "✔ Directory URLs are working correctly (installation/index.html exists)"
else
echo "✖ Directory URLs validation failed - installation/index.html not found"
exit 1
fi
echo "Cleaning up build directory..."
rm -rf site
echo "✔ Docs build and validation completed successfully!"