Skip to content

Commit 38a8751

Browse files
committed
laboratory
1 parent 7b21154 commit 38a8751

File tree

3 files changed

+381
-18
lines changed

3 files changed

+381
-18
lines changed

.github/actions/build-docs/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ inputs:
99
description: 'Cache key suffix for isolation'
1010
required: false
1111
default: 'default'
12+
skip-checkout:
13+
description: 'Skip documentation repo checkout (docs already present)'
14+
required: false
15+
default: 'false'
1216
outputs:
1317
docs-sha:
1418
description: 'SHA of documentation repository'
@@ -21,6 +25,7 @@ runs:
2125
using: composite
2226
steps:
2327
- name: Checkout documentation repo
28+
if: inputs.skip-checkout != 'true'
2429
uses: actions/checkout@v4
2530
with:
2631
repository: rocky-linux/documentation

.github/workflows/lab.yml

Lines changed: 358 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,358 @@
1+
---
2+
name: Multi-Language Matrix Build
3+
4+
concurrency:
5+
group: laboratory
6+
cancel-in-progress: true
7+
8+
on:
9+
push:
10+
branches:
11+
- lab
12+
workflow_dispatch:
13+
inputs:
14+
docs-ref:
15+
description: 'Documentation repository ref to build'
16+
required: false
17+
default: 'main'
18+
languages:
19+
description: 'Comma-separated list of languages to build (empty = all enabled)'
20+
required: false
21+
default: ''
22+
test_mode:
23+
description: 'Test mode - skip deployment steps'
24+
type: boolean
25+
required: false
26+
default: true
27+
28+
# env:
29+
# Language control flags - dynamically loaded from repository variables
30+
# Set vars.BUILD_<LANG>=false to disable specific languages
31+
# Languages are auto-detected from mkdocs.yml
32+
33+
jobs:
34+
prepare:
35+
name: Prepare Build Matrix
36+
runs-on: ubuntu-latest
37+
container:
38+
image: ghcr.io/rocky-linux/docs-builder:latest
39+
outputs:
40+
matrix: ${{ steps.matrix.outputs.matrix }}
41+
docs-sha: ${{ steps.docs-info.outputs.docs-sha }}
42+
all-languages: ${{ steps.extract-languages.outputs.all-languages }}
43+
steps:
44+
- name: Checkout mkdocs config
45+
uses: actions/checkout@v4
46+
47+
- name: Extract all languages from mkdocs.yml
48+
id: extract-languages
49+
run: |
50+
# Extract all available languages from mkdocs.yml (run once)
51+
ALL_LANGUAGES=$(yq -r '.plugins[] | select(type == "object" and has("i18n")) | .i18n.languages[].locale' < mkdocs.yml | jq -R . | jq -s -c .)
52+
echo "all-languages=$ALL_LANGUAGES" >> $GITHUB_OUTPUT
53+
echo "Available languages from mkdocs.yml: $ALL_LANGUAGES"
54+
55+
- name: Get documentation SHA
56+
id: docs-info
57+
run: |
58+
# Get the SHA of the documentation repo at the specified ref
59+
DOCS_SHA=$(git ls-remote https://github.com/rocky-linux/documentation.git ${{ inputs.docs-ref || 'main' }} | cut -f1)
60+
echo "docs-sha=$DOCS_SHA" >> $GITHUB_OUTPUT
61+
62+
- name: Generate build matrix
63+
id: matrix
64+
run: |
65+
# Use pre-extracted languages
66+
ALL_LANGUAGES='${{ steps.extract-languages.outputs.all-languages }}'
67+
echo "Using extracted languages: $ALL_LANGUAGES"
68+
69+
# Check if specific languages were requested
70+
REQUESTED_LANGUAGES="${{ inputs.languages }}"
71+
72+
if [ -n "$REQUESTED_LANGUAGES" ]; then
73+
# Convert comma-separated input to JSON array
74+
MATRIX_LANGUAGES=$(echo "$REQUESTED_LANGUAGES" | sed 's/,/","/g' | sed 's/^/["/' | sed 's/$/"]/')
75+
echo "Using requested languages: $MATRIX_LANGUAGES"
76+
else
77+
# Filter languages based on environment variables
78+
ENABLED_LANGUAGES='['
79+
80+
# Create a JSON object of all repository variables for dynamic lookup
81+
VARS_JSON='${{ toJson(vars) }}'
82+
echo "Repository variables: $VARS_JSON"
83+
84+
# Dynamically check each language from mkdocs.yml
85+
for locale in $(echo "$ALL_LANGUAGES" | jq -r '.[]'); do
86+
# Convert locale to environment variable name (e.g., pt-BR -> BUILD_PT_BR)
87+
env_var="BUILD_$(echo "$locale" | tr '[:lower:]' '[:upper:]' | tr '-' '_')"
88+
89+
# Check if the repository variable is set to 'false', otherwise default to 'true'
90+
env_value=$(echo "$VARS_JSON" | jq -r --arg key "$env_var" '.[$key] // "true"')
91+
92+
if [ "$env_value" != "false" ]; then
93+
ENABLED_LANGUAGES+="\"$locale\","
94+
echo "Including language: $locale (${env_var}=${env_value})"
95+
else
96+
echo "Excluding language: $locale (${env_var}=false)"
97+
fi
98+
done
99+
100+
# Remove trailing comma and close array
101+
ENABLED_LANGUAGES=$(echo "$ENABLED_LANGUAGES" | sed 's/,$//')']'
102+
103+
MATRIX_LANGUAGES="$ENABLED_LANGUAGES"
104+
fi
105+
106+
# Ensure English is always included (required for fallbacks)
107+
if ! echo "$MATRIX_LANGUAGES" | grep -q '"en"'; then
108+
MATRIX_LANGUAGES=$(echo "$MATRIX_LANGUAGES" | sed 's/\[/["en",/')
109+
echo "Added English as fallback language"
110+
fi
111+
112+
# Remove English from the matrix since it has its own dedicated job
113+
MATRIX_LANGUAGES_NO_EN=$(echo "$MATRIX_LANGUAGES" | jq 'map(select(. != "en"))')
114+
115+
# Create final matrix for language builds (excluding English)
116+
MATRIX=$(echo "{\"language\": $MATRIX_LANGUAGES_NO_EN}" | jq -c .)
117+
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
118+
119+
echo "Final generated matrix (excluding English): $MATRIX"
120+
121+
build-english:
122+
name: Build English (Fallback Base)
123+
runs-on: ubuntu-latest
124+
container:
125+
image: ghcr.io/rocky-linux/docs-builder:latest
126+
needs: prepare
127+
outputs:
128+
cache-key: ${{ steps.build.outputs.cache-key }}
129+
steps:
130+
- name: Checkout mkdocs config
131+
uses: actions/checkout@v4
132+
133+
- name: Checkout documentation repo
134+
uses: actions/checkout@v4
135+
with:
136+
repository: rocky-linux/documentation
137+
ref: ${{ inputs.docs-ref || 'main' }}
138+
path: docs
139+
fetch-depth: 0
140+
141+
- name: Remove language-specific files for English build
142+
run: |
143+
# Use pre-extracted languages and filter out English
144+
ALL_LANGUAGES='${{ needs.prepare.outputs.all-languages }}'
145+
locales=$(echo "$ALL_LANGUAGES" | jq -r '.[] | select(. != "en")' | jq -R . | jq -s .)
146+
echo "Non-English locales: $locales"
147+
148+
# Convert JSON array to bash array and remove language-specific files
149+
for locale in $(echo "$locales" | jq -r '.[]'); do
150+
echo "Removing files for locale: $locale"
151+
find docs/docs -name "*.$locale.md" -type f -delete
152+
find docs/docs -name "*.$locale.yml" -type f -delete
153+
find docs/docs -name "*.$locale.yaml" -type f -delete
154+
# Also handle directories with locale suffixes if they exist
155+
find docs/docs -type d -name "*.$locale" -exec rm -rf {} + 2>/dev/null || true
156+
done
157+
158+
echo "Remaining files after cleanup:"
159+
find docs/docs -name "*.md" | head -20
160+
161+
- name: Set all languages environment variables for English build
162+
run: |
163+
# Use pre-extracted languages
164+
ALL_LANGUAGES='${{ needs.prepare.outputs.all-languages }}'
165+
166+
echo "Setting all languages to true for English build (full structure):"
167+
168+
# Enable all languages for complete site structure
169+
for locale in $(echo "$ALL_LANGUAGES" | jq -r '.[]'); do
170+
env_var="BUILD_$(echo "$locale" | tr '[:lower:]' '[:upper:]' | tr '-' '_')"
171+
echo "${env_var}=true" >> $GITHUB_ENV
172+
echo "${env_var}=true"
173+
done
174+
175+
- name: Build English Documentation (full structure, no lang files)
176+
id: build
177+
uses: ./.github/actions/build-docs
178+
with:
179+
docs-ref: ${{ inputs.docs-ref || 'main' }}
180+
cache-suffix: 'en-base'
181+
skip-checkout: 'true'
182+
183+
- name: Set cache key output
184+
run: echo "cache-key=cache-docs-en-base-${{ needs.prepare.outputs.docs-sha }}" >> $GITHUB_OUTPUT
185+
186+
- name: Archive English build
187+
uses: actions/upload-artifact@v4
188+
with:
189+
name: build-en-base
190+
path: build/minified
191+
192+
build-languages:
193+
name: Build ${{ matrix.language }}
194+
runs-on: ubuntu-latest
195+
container:
196+
image: ghcr.io/rocky-linux/docs-builder:latest
197+
needs: [prepare]
198+
strategy:
199+
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}
200+
fail-fast: false
201+
max-parallel: 7
202+
steps:
203+
- name: Skip if English (safety check)
204+
if: matrix.language == 'en'
205+
run: |
206+
echo "Skipping English build - handled by dedicated English job"
207+
exit 0
208+
209+
- name: Checkout mkdocs config
210+
uses: actions/checkout@v4
211+
212+
- name: Restore English base cache
213+
uses: actions/cache/restore@v4
214+
with:
215+
path: ${{ github.workspace }}/build/minified
216+
key: ${{ needs.build-english.outputs.cache-key }}
217+
enableCrossOsArchive: true
218+
219+
- name: Download English base build
220+
if: steps.restore-cache.outputs.cache-hit != 'true'
221+
uses: actions/download-artifact@v4
222+
with:
223+
name: build-en-base
224+
path: build/minified-en-base
225+
226+
- name: Set language environment variables
227+
id: lang-env
228+
run: |
229+
# Use pre-extracted languages
230+
ALL_LANGUAGES='${{ needs.prepare.outputs.all-languages }}'
231+
232+
# Set environment variables for this build
233+
echo "Setting environment variables for ${{ matrix.language }} build:"
234+
235+
# Always enable English
236+
echo "BUILD_EN=true" >> $GITHUB_ENV
237+
echo "BUILD_EN=true"
238+
239+
# Set all other languages to false, except the target language
240+
for locale in $(echo "$ALL_LANGUAGES" | jq -r '.[]'); do
241+
if [ "$locale" != "en" ]; then
242+
env_var="BUILD_$(echo "$locale" | tr '[:lower:]' '[:upper:]' | tr '-' '_')"
243+
if [ "$locale" = "${{ matrix.language }}" ]; then
244+
echo "${env_var}=true" >> $GITHUB_ENV
245+
echo "${env_var}=true"
246+
else
247+
echo "${env_var}=false" >> $GITHUB_ENV
248+
echo "${env_var}=false"
249+
fi
250+
fi
251+
done
252+
253+
- name: Build ${{ matrix.language }} Documentation (with English fallback)
254+
uses: ./.github/actions/build-docs
255+
with:
256+
docs-ref: ${{ inputs.docs-ref || 'main' }}
257+
cache-suffix: ${{ matrix.language }}
258+
259+
- name: Archive ${{ matrix.language }} build
260+
uses: actions/upload-artifact@v4
261+
with:
262+
name: build-${{ matrix.language }}
263+
path: build/minified
264+
265+
summary:
266+
name: Build Summary
267+
runs-on: ubuntu-latest
268+
needs: [prepare, build-english, build-languages]
269+
if: always()
270+
steps:
271+
- name: Download all artifacts
272+
uses: actions/download-artifact@v4
273+
with:
274+
path: all-builds
275+
276+
- name: Generate summary
277+
run: |
278+
echo "# Laboratory Multi-Language Build Summary" >> $GITHUB_STEP_SUMMARY
279+
echo "" >> $GITHUB_STEP_SUMMARY
280+
echo "## Build Configuration" >> $GITHUB_STEP_SUMMARY
281+
echo "- **Documentation Ref**: ${{ inputs.docs-ref || 'main' }}" >> $GITHUB_STEP_SUMMARY
282+
echo "- **Documentation SHA**: ${{ needs.prepare.outputs.docs-sha }}" >> $GITHUB_STEP_SUMMARY
283+
echo "- **Test Mode**: ${{ inputs.test_mode }}" >> $GITHUB_STEP_SUMMARY
284+
echo "" >> $GITHUB_STEP_SUMMARY
285+
286+
echo "## Language Matrix" >> $GITHUB_STEP_SUMMARY
287+
echo '```json' >> $GITHUB_STEP_SUMMARY
288+
echo '${{ needs.prepare.outputs.matrix }}' | jq . >> $GITHUB_STEP_SUMMARY
289+
echo '```' >> $GITHUB_STEP_SUMMARY
290+
echo "" >> $GITHUB_STEP_SUMMARY
291+
292+
echo "## Build Artifacts" >> $GITHUB_STEP_SUMMARY
293+
for dir in all-builds/*/; do
294+
if [ -d "$dir" ]; then
295+
artifact_name=$(basename "$dir")
296+
file_count=$(find "$dir" -type f | wc -l)
297+
total_size=$(du -sh "$dir" | cut -f1)
298+
echo "- **$artifact_name**: $file_count files, $total_size" >> $GITHUB_STEP_SUMMARY
299+
fi
300+
done
301+
302+
echo "" >> $GITHUB_STEP_SUMMARY
303+
echo "## Job Status" >> $GITHUB_STEP_SUMMARY
304+
echo "- **English Build**: ${{ needs.build-english.result }}" >> $GITHUB_STEP_SUMMARY
305+
echo "- **Language Builds**: ${{ needs.build-languages.result }}" >> $GITHUB_STEP_SUMMARY
306+
307+
# Optional deployment step (disabled in test mode)
308+
deploy-test:
309+
name: Deploy Test Collections
310+
runs-on: ubuntu-latest
311+
container:
312+
image: ghcr.io/rocky-linux/docs-builder:latest
313+
needs: [prepare, build-english, build-languages]
314+
if: inputs.test_mode != true && success()
315+
strategy:
316+
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}
317+
fail-fast: false
318+
max-parallel: 3
319+
environment: laboratory
320+
steps:
321+
- name: Checkout repository
322+
uses: actions/checkout@v4
323+
324+
- name: Setup Node.js
325+
uses: actions/setup-node@v4
326+
with:
327+
node-version: 20
328+
329+
- name: Download ${{ matrix.language }} build
330+
uses: actions/download-artifact@v4
331+
with:
332+
name: build-${{ matrix.language == 'en' && 'en-base' || matrix.language }}
333+
path: build/minified
334+
335+
- name: Install Dependencies
336+
run: npm install
337+
working-directory: ./compute-js
338+
339+
- name: Build Compute Package for ${{ matrix.language }}
340+
run: npm run build
341+
working-directory: ./compute-js
342+
env:
343+
FASTLY_API_TOKEN: ${{ secrets.FASTLY_API_TOKEN }}
344+
345+
- name: Deploy ${{ matrix.language }} to Lab Collection
346+
run: |
347+
npx @fastly/compute-js-static-publish publish-content \
348+
--collection-name=lab-${{ matrix.language }} \
349+
--expires-in=24h
350+
working-directory: ./compute-js
351+
env:
352+
FASTLY_API_TOKEN: ${{ secrets.FASTLY_API_TOKEN }}
353+
354+
- name: Output deployment info
355+
run: |
356+
echo ">� Laboratory deployment completed for ${{ matrix.language }}!"
357+
echo "=� Collection: lab-${{ matrix.language }}"
358+
echo "� Expires: 24 hours"

0 commit comments

Comments
 (0)