Skip to content

Commit af35beb

Browse files
committed
laboratory
1 parent 7b21154 commit af35beb

File tree

2 files changed

+367
-18
lines changed

2 files changed

+367
-18
lines changed

.github/workflows/lab.yml

Lines changed: 349 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,349 @@
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+
# 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 .)
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: Remove language-specific files for English build
134+
run: |
135+
# Use pre-extracted languages and filter out English
136+
ALL_LANGUAGES='${{ needs.prepare.outputs.all-languages }}'
137+
locales=$(echo "$ALL_LANGUAGES" | jq -r '.[] | select(. != "en")' | jq -R . | jq -s .)
138+
echo "Non-English locales: $locales"
139+
140+
# Convert JSON array to bash array and remove language-specific files
141+
for locale in $(echo "$locales" | jq -r '.[]'); do
142+
echo "Removing files for locale: $locale"
143+
find docs/docs -name "*.$locale.md" -type f -delete
144+
find docs/docs -name "*.$locale.yml" -type f -delete
145+
find docs/docs -name "*.$locale.yaml" -type f -delete
146+
# Also handle directories with locale suffixes if they exist
147+
find docs/docs -type d -name "*.$locale" -exec rm -rf {} + 2>/dev/null || true
148+
done
149+
150+
echo "Remaining files after cleanup:"
151+
find docs/docs -name "*.md" | head -20
152+
153+
- name: Set all languages environment variables for English build
154+
run: |
155+
# Use pre-extracted languages
156+
ALL_LANGUAGES='${{ needs.prepare.outputs.all-languages }}'
157+
158+
echo "Setting all languages to true for English build (full structure):"
159+
160+
# Enable all languages for complete site structure
161+
for locale in $(echo "$ALL_LANGUAGES" | jq -r '.[]'); do
162+
env_var="BUILD_$(echo "$locale" | tr '[:lower:]' '[:upper:]' | tr '-' '_')"
163+
echo "${env_var}=true" >> $GITHUB_ENV
164+
echo "${env_var}=true"
165+
done
166+
167+
- name: Build English Documentation (full structure, no lang files)
168+
id: build
169+
uses: ./.github/actions/build-docs
170+
with:
171+
docs-ref: ${{ inputs.docs-ref || 'main' }}
172+
cache-suffix: 'en-base'
173+
174+
- name: Set cache key output
175+
run: echo "cache-key=cache-docs-en-base-${{ needs.prepare.outputs.docs-sha }}" >> $GITHUB_OUTPUT
176+
177+
- name: Archive English build
178+
uses: actions/upload-artifact@v4
179+
with:
180+
name: build-en-base
181+
path: build/minified
182+
183+
build-languages:
184+
name: Build ${{ matrix.language }}
185+
runs-on: ubuntu-latest
186+
container:
187+
image: ghcr.io/rocky-linux/docs-builder:latest
188+
needs: [prepare, build-english]
189+
strategy:
190+
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}
191+
fail-fast: false
192+
max-parallel: 7
193+
steps:
194+
- name: Skip if English (safety check)
195+
if: matrix.language == 'en'
196+
run: |
197+
echo "Skipping English build - handled by dedicated English job"
198+
exit 0
199+
200+
- name: Checkout mkdocs config
201+
uses: actions/checkout@v4
202+
203+
- name: Restore English base cache
204+
uses: actions/cache/restore@v4
205+
with:
206+
path: ${{ github.workspace }}/build/minified
207+
key: ${{ needs.build-english.outputs.cache-key }}
208+
enableCrossOsArchive: true
209+
210+
- name: Download English base build
211+
if: steps.restore-cache.outputs.cache-hit != 'true'
212+
uses: actions/download-artifact@v4
213+
with:
214+
name: build-en-base
215+
path: build/minified-en-base
216+
217+
- name: Set language environment variables
218+
id: lang-env
219+
run: |
220+
# Use pre-extracted languages
221+
ALL_LANGUAGES='${{ needs.prepare.outputs.all-languages }}'
222+
223+
# Set environment variables for this build
224+
echo "Setting environment variables for ${{ matrix.language }} build:"
225+
226+
# Always enable English
227+
echo "BUILD_EN=true" >> $GITHUB_ENV
228+
echo "BUILD_EN=true"
229+
230+
# Set all other languages to false, except the target language
231+
for locale in $(echo "$ALL_LANGUAGES" | jq -r '.[]'); do
232+
if [ "$locale" != "en" ]; then
233+
env_var="BUILD_$(echo "$locale" | tr '[:lower:]' '[:upper:]' | tr '-' '_')"
234+
if [ "$locale" = "${{ matrix.language }}" ]; then
235+
echo "${env_var}=true" >> $GITHUB_ENV
236+
echo "${env_var}=true"
237+
else
238+
echo "${env_var}=false" >> $GITHUB_ENV
239+
echo "${env_var}=false"
240+
fi
241+
fi
242+
done
243+
244+
- name: Build ${{ matrix.language }} Documentation (with English fallback)
245+
uses: ./.github/actions/build-docs
246+
with:
247+
docs-ref: ${{ inputs.docs-ref || 'main' }}
248+
cache-suffix: ${{ matrix.language }}
249+
250+
- name: Archive ${{ matrix.language }} build
251+
uses: actions/upload-artifact@v4
252+
with:
253+
name: build-${{ matrix.language }}
254+
path: build/minified
255+
256+
summary:
257+
name: Build Summary
258+
runs-on: ubuntu-latest
259+
needs: [prepare, build-english, build-languages]
260+
if: always()
261+
steps:
262+
- name: Download all artifacts
263+
uses: actions/download-artifact@v4
264+
with:
265+
path: all-builds
266+
267+
- name: Generate summary
268+
run: |
269+
echo "# Laboratory Multi-Language Build Summary" >> $GITHUB_STEP_SUMMARY
270+
echo "" >> $GITHUB_STEP_SUMMARY
271+
echo "## Build Configuration" >> $GITHUB_STEP_SUMMARY
272+
echo "- **Documentation Ref**: ${{ inputs.docs-ref || 'main' }}" >> $GITHUB_STEP_SUMMARY
273+
echo "- **Documentation SHA**: ${{ needs.prepare.outputs.docs-sha }}" >> $GITHUB_STEP_SUMMARY
274+
echo "- **Test Mode**: ${{ inputs.test_mode }}" >> $GITHUB_STEP_SUMMARY
275+
echo "" >> $GITHUB_STEP_SUMMARY
276+
277+
echo "## Language Matrix" >> $GITHUB_STEP_SUMMARY
278+
echo '```json' >> $GITHUB_STEP_SUMMARY
279+
echo '${{ needs.prepare.outputs.matrix }}' | jq . >> $GITHUB_STEP_SUMMARY
280+
echo '```' >> $GITHUB_STEP_SUMMARY
281+
echo "" >> $GITHUB_STEP_SUMMARY
282+
283+
echo "## Build Artifacts" >> $GITHUB_STEP_SUMMARY
284+
for dir in all-builds/*/; do
285+
if [ -d "$dir" ]; then
286+
artifact_name=$(basename "$dir")
287+
file_count=$(find "$dir" -type f | wc -l)
288+
total_size=$(du -sh "$dir" | cut -f1)
289+
echo "- **$artifact_name**: $file_count files, $total_size" >> $GITHUB_STEP_SUMMARY
290+
fi
291+
done
292+
293+
echo "" >> $GITHUB_STEP_SUMMARY
294+
echo "## Job Status" >> $GITHUB_STEP_SUMMARY
295+
echo "- **English Build**: ${{ needs.build-english.result }}" >> $GITHUB_STEP_SUMMARY
296+
echo "- **Language Builds**: ${{ needs.build-languages.result }}" >> $GITHUB_STEP_SUMMARY
297+
298+
# Optional deployment step (disabled in test mode)
299+
deploy-test:
300+
name: Deploy Test Collections
301+
runs-on: ubuntu-latest
302+
container:
303+
image: ghcr.io/rocky-linux/docs-builder:latest
304+
needs: [prepare, build-english, build-languages]
305+
if: inputs.test_mode != true && success()
306+
strategy:
307+
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}
308+
fail-fast: false
309+
max-parallel: 3
310+
environment: laboratory
311+
steps:
312+
- name: Checkout repository
313+
uses: actions/checkout@v4
314+
315+
- name: Setup Node.js
316+
uses: actions/setup-node@v4
317+
with:
318+
node-version: 20
319+
320+
- name: Download ${{ matrix.language }} build
321+
uses: actions/download-artifact@v4
322+
with:
323+
name: build-${{ matrix.language == 'en' && 'en-base' || matrix.language }}
324+
path: build/minified
325+
326+
- name: Install Dependencies
327+
run: npm install
328+
working-directory: ./compute-js
329+
330+
- name: Build Compute Package for ${{ matrix.language }}
331+
run: npm run build
332+
working-directory: ./compute-js
333+
env:
334+
FASTLY_API_TOKEN: ${{ secrets.FASTLY_API_TOKEN }}
335+
336+
- name: Deploy ${{ matrix.language }} to Lab Collection
337+
run: |
338+
npx @fastly/compute-js-static-publish publish-content \
339+
--collection-name=lab-${{ matrix.language }} \
340+
--expires-in=24h
341+
working-directory: ./compute-js
342+
env:
343+
FASTLY_API_TOKEN: ${{ secrets.FASTLY_API_TOKEN }}
344+
345+
- name: Output deployment info
346+
run: |
347+
echo ">� Laboratory deployment completed for ${{ matrix.language }}!"
348+
echo "=� Collection: lab-${{ matrix.language }}"
349+
echo "� Expires: 24 hours"

0 commit comments

Comments
 (0)