Skip to content

Commit 5163faf

Browse files
committed
docs: update GHA locale workflow doc
1 parent 8c57a27 commit 5163faf

File tree

3 files changed

+323
-250
lines changed

3 files changed

+323
-250
lines changed

.github/README.md

Lines changed: 323 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,323 @@
1+
# GitHub Actions Locale Workflow System
2+
3+
This document provides comprehensive documentation for the locale-based GitHub Actions workflow system, including the scripts, actions, and the enhancement process that led to the current implementation.
4+
5+
## 🎯 Overview
6+
7+
This system provides automated, locale-aware deployment workflows for internationalized documentation. It intelligently determines which locales need to be deployed based on file changes and supports multiple trigger types for different deployment scenarios.
8+
9+
## 📁 System Components
10+
11+
### Core Files
12+
13+
- **`/.github/locales-config.json`** - Central configuration for all locales
14+
- **`/.github/actions/check-locale-changes/action.yml`** - Reusable GitHub Action
15+
- **`/.github/scripts/`** - Executable bash scripts for locale logic
16+
17+
### Workflow Integration
18+
19+
- **`/.github/workflows/release.yml`** - Production deployment workflow
20+
- **`/.github/workflows/update-docs-ci.yml`** - Documentation update workflow
21+
22+
## 🔧 Scripts Reference
23+
24+
### 1. `generate-files-config.sh`
25+
26+
Generates dynamic file configuration for the `changed-files` action based on locales defined in the configuration.
27+
28+
**Usage:**
29+
```bash
30+
./generate-files-config.sh
31+
```
32+
33+
**Output:**
34+
YAML configuration for file pattern matching, with separate patterns for core files and each locale's content/messages.
35+
36+
**Example Output:**
37+
```yaml
38+
core:
39+
- 'apps/docs/**'
40+
- 'packages/**'
41+
- '!apps/docs/content/**'
42+
- '!apps/docs/messages/**'
43+
en:
44+
- 'apps/docs/content/en/**'
45+
- 'apps/docs/messages/en.json'
46+
zh-hans:
47+
- 'apps/docs/content/zh-hans/**'
48+
- 'apps/docs/messages/zh-hans.json'
49+
```
50+
51+
### 2. `generate-locale-matrix.sh`
52+
53+
Generates deployment matrix for GitHub Actions based on locale changes and trigger type.
54+
55+
**Usage:**
56+
```bash
57+
# Manual trigger (all enabled locales)
58+
./generate-locale-matrix.sh manual
59+
60+
# Manual trigger (specific locales)
61+
./generate-locale-matrix.sh manual "en,zh-hans"
62+
63+
# Auto/docs-pr trigger (with changes JSON file)
64+
echo '{"core_any_changed": "true", "en_any_changed": "false"}' > changes.json
65+
./generate-locale-matrix.sh auto "" "changes.json"
66+
./generate-locale-matrix.sh docs-pr "" "changes.json"
67+
```
68+
69+
**Output:**
70+
- `include=<JSON array>` - Matrix of locales with their configuration
71+
- `has-changes=<boolean>` - Whether any changes were detected
72+
73+
**Example Output:**
74+
```
75+
include=[{"locale":"en","secret_project_id":"VERCEL_PROJECT_EN_ID","orama_private_api_key":"ORAMA_PRIVATE_API_KEY_EN"}]
76+
has-changes=true
77+
```
78+
79+
### 3. `test-locale-scripts.sh`
80+
81+
Comprehensive test suite for validating all locale scripts functionality.
82+
83+
**Usage:**
84+
```bash
85+
./test-locale-scripts.sh
86+
```
87+
88+
**Features:**
89+
- Tests all trigger types and scenarios
90+
- Validates JSON output format
91+
- Tests error handling and edge cases
92+
- Provides detailed test reports (10 test scenarios)
93+
94+
## ⚙️ Configuration
95+
96+
### Locale Configuration (`/.github/locales-config.json`)
97+
98+
All scripts read from this centralized configuration file:
99+
100+
```json
101+
{
102+
"en": {
103+
"enabled": true,
104+
"secret_project_id": "VERCEL_PROJECT_EN_ID",
105+
"orama_private_api_key": "ORAMA_PRIVATE_API_KEY_EN"
106+
},
107+
"zh-hans": {
108+
"enabled": true,
109+
"secret_project_id": "VERCEL_PROJECT_ZH_HANS_ID",
110+
"orama_private_api_key": "ORAMA_PRIVATE_API_KEY_ZH_HANS"
111+
}
112+
}
113+
```
114+
115+
**Fields:**
116+
- `enabled` - Whether the locale is active for deployment
117+
- `secret_project_id` - GitHub secret name for the Vercel project ID
118+
- `orama_private_api_key` - GitHub secret name for the Orama search API key
119+
120+
## 🔄 GitHub Action Integration
121+
122+
The reusable action `/.github/actions/check-locale-changes/action.yml` orchestrates the entire process:
123+
124+
### Inputs
125+
126+
```yaml
127+
inputs:
128+
trigger-type:
129+
description: 'Type of trigger: manual, auto, or docs-pr'
130+
required: true
131+
manual-locales:
132+
description: 'Comma-separated list of locales for manual trigger'
133+
required: false
134+
```
135+
136+
### Outputs
137+
138+
```yaml
139+
outputs:
140+
matrix:
141+
description: 'JSON matrix of locales to deploy'
142+
has-changes:
143+
description: 'Whether any changes were detected'
144+
```
145+
146+
### Workflow Process
147+
148+
1. **Generate Files Config** - Creates dynamic file patterns for change detection
149+
2. **Detect Changes** - Uses `changed-files` action with generated patterns
150+
3. **Generate Matrix** - Determines which locales to deploy based on changes and trigger type
151+
4. **Return Results** - Provides matrix configuration for downstream jobs
152+
153+
## 🚀 Usage Examples
154+
155+
### In GitHub Workflows
156+
157+
```yaml
158+
jobs:
159+
check-changes:
160+
runs-on: ubuntu-latest
161+
outputs:
162+
matrix: ${{ steps.changes.outputs.matrix }}
163+
has-changes: ${{ steps.changes.outputs.has-changes }}
164+
steps:
165+
- uses: actions/checkout@v4
166+
167+
- name: Check locale changes
168+
id: changes
169+
uses: ./.github/actions/check-locale-changes
170+
with:
171+
trigger-type: 'auto'
172+
173+
deploy:
174+
needs: check-changes
175+
if: needs.check-changes.outputs.has-changes == 'true'
176+
strategy:
177+
matrix:
178+
include: ${{ fromJSON(needs.check-changes.outputs.matrix) }}
179+
runs-on: ubuntu-latest
180+
steps:
181+
- name: Deploy ${{ matrix.locale }}
182+
run: echo "Deploying locale: ${{ matrix.locale }}"
183+
```
184+
185+
### Local Testing
186+
187+
```bash
188+
# Make scripts executable
189+
chmod +x .github/scripts/*.sh
190+
191+
# Test files config generation
192+
./.github/scripts/generate-files-config.sh
193+
194+
# Test manual deployment matrix
195+
./.github/scripts/generate-locale-matrix.sh manual "en,zh-hans"
196+
197+
# Test auto deployment with changes
198+
echo '{"core_any_changed": "true"}' > /tmp/changes.json
199+
./.github/scripts/generate-locale-matrix.sh auto "" /tmp/changes.json
200+
201+
# Run comprehensive test suite
202+
./.github/scripts/test-locale-scripts.sh
203+
```
204+
205+
## 🛠️ Technical Improvements & Enhancement History
206+
207+
### What We Started With
208+
- GitHub Actions workflows with significant code duplication
209+
- Inline bash logic that was difficult to test locally
210+
- Hardcoded locale matrices and configurations
211+
- Manual workflow trigger issues
212+
- "Argument list too long" errors with large file lists
213+
214+
### What We Accomplished
215+
216+
#### ✅ 1. Fixed "Argument list too long" Error
217+
- **Problem**: Large JSON strings with extensive file lists exceeded system ARG_MAX limit
218+
- **Solution**: Implemented file-based approach using temporary files to pass JSON data
219+
220+
#### ✅ 2. Created Reusable Components
221+
- **Extracted** 150+ lines of inline bash into modular, testable scripts
222+
- **Created** reusable GitHub Action with clean inputs/outputs
223+
- **Centralized** configuration in single JSON file
224+
225+
#### ✅ 3. Enhanced Testability
226+
- **Local testing** - All logic can be tested without GitHub Actions
227+
- **Comprehensive test suite** - 10 test scenarios covering all cases
228+
- **Error handling** - Robust validation and error reporting
229+
230+
#### ✅ 4. Improved Maintainability
231+
- **Modular design** - Separate concerns into focused scripts
232+
- **Documentation** - Comprehensive inline and external documentation
233+
- **Logging optimization** - Reduced unnecessary logs while maintaining debugging capability
234+
235+
### Before vs After
236+
237+
#### Before:
238+
```yaml
239+
# Massive inline bash block
240+
run: |
241+
locale_config=$(cat .github/locales-config.json)
242+
matrix_include="[]"
243+
# ... 150+ lines of complex logic with ARG_MAX issues
244+
```
245+
246+
#### After:
247+
```yaml
248+
# Clean, file-based approach
249+
run: |
250+
if [ "$trigger_type" == "manual" ]; then
251+
output=$(.github/scripts/generate-locale-matrix.sh "$trigger_type" "$manual_locales")
252+
else
253+
changes_json='${{ toJSON(steps.changes.outputs) }}'
254+
temp_file=$(mktemp)
255+
echo "$changes_json" > "$temp_file"
256+
output=$(.github/scripts/generate-locale-matrix.sh "$trigger_type" "" "$temp_file")
257+
rm -f "$temp_file"
258+
fi
259+
```
260+
261+
## 📋 Dependencies
262+
263+
- **`jq`** - JSON processing and validation
264+
- **Standard Unix utilities** - `sed`, `tr`, `mktemp`, `cat`, `echo`
265+
- **GitHub Actions** - `changed-files` action for file change detection
266+
267+
## 🧪 Testing
268+
269+
The test suite validates:
270+
- Files config generation
271+
- Matrix generation for all trigger types
272+
- JSON output validity and formatting
273+
- Error handling and edge cases
274+
- File-based argument passing
275+
- Boundary conditions and invalid inputs
276+
277+
**Run tests:**
278+
```bash
279+
./.github/scripts/test-locale-scripts.sh
280+
```
281+
282+
**Expected output:**
283+
```
284+
✅ All tests pass (10/10)
285+
✅ Scripts work correctly for all trigger types
286+
✅ JSON output is properly formatted and valid
287+
✅ Error handling works as expected
288+
```
289+
290+
## 🎯 Benefits
291+
292+
1. **Scalability** - Handles arbitrarily large file lists without system limitations
293+
2. **Maintainability** - Centralized, modular components
294+
3. **Testability** - Complete local testing capability
295+
4. **Reliability** - Comprehensive error handling and validation
296+
5. **Reusability** - Scripts can be used in other workflows
297+
6. **Performance** - Optimized logging and efficient processing
298+
7. **Debugging** - Clear error messages and optional verbose logging
299+
300+
## 📝 Files Created/Modified
301+
302+
**Created:**
303+
- `/.github/actions/check-locale-changes/action.yml` - Reusable action
304+
- `/.github/scripts/generate-files-config.sh` - Files config generator
305+
- `/.github/scripts/generate-locale-matrix.sh` - Matrix generator
306+
- `/.github/scripts/test-locale-scripts.sh` - Test suite
307+
- `/.github/README.md` - This documentation
308+
309+
**Modified:**
310+
- `/.github/workflows/release.yml` - Uses reusable action
311+
- `/.github/workflows/update-docs-ci.yml` - Uses reusable action
312+
- `/.github/locales-config.json` - Added orama_private_api_key fields
313+
314+
## 🚀 Status
315+
316+
✅ **System is production-ready**
317+
- All components tested and validated
318+
- No more "Argument list too long" errors
319+
- Clean, maintainable codebase
320+
- Comprehensive documentation
321+
- Full test coverage
322+
323+
The locale workflow system is now robust, scalable, and ready for production use! 🎉

0 commit comments

Comments
 (0)