Skip to content

Commit 95e4f5a

Browse files
committed
laboratory
1 parent 7b21154 commit 95e4f5a

File tree

2 files changed

+370
-18
lines changed

2 files changed

+370
-18
lines changed

.github/workflows/lab.yml

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

0 commit comments

Comments
 (0)