Skip to content

Commit cdf05f9

Browse files
committed
laboratory
1 parent 7b21154 commit cdf05f9

File tree

2 files changed

+368
-18
lines changed

2 files changed

+368
-18
lines changed

.github/workflows/lab.yml

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

0 commit comments

Comments
 (0)