|
| 1 | +# GitHub Actions Locale Workflow Enhancement - Summary |
| 2 | + |
| 3 | +## 🎯 Task Completed: Extract Common Logic to Reusable, Testable Components |
| 4 | + |
| 5 | +### What We Started With |
| 6 | +- GitHub Actions workflows with significant code duplication |
| 7 | +- Inline bash logic that was difficult to test locally |
| 8 | +- Hardcoded locale matrices and configurations |
| 9 | +- Manual workflow trigger issue where `branches` filter wasn't working correctly |
| 10 | + |
| 11 | +### What We Accomplished |
| 12 | + |
| 13 | +#### ✅ 1. Fixed Original GitHub Actions Trigger Issue |
| 14 | +- **Problem**: `branches` filter wasn't working for PRs from `docs/*` branches to `main` |
| 15 | +- **Solution**: Changed trigger to target `main` branch with `startsWith(github.head_ref, 'docs/')` condition for source branch filtering |
| 16 | + |
| 17 | +#### ✅ 2. Created Reusable GitHub Action Component |
| 18 | +- **File**: `/.github/actions/check-locale-changes/action.yml` |
| 19 | +- **Features**: |
| 20 | + - Supports multiple trigger types: `manual`, `auto`, `docs-pr` |
| 21 | + - Dynamic locale detection from JSON configuration |
| 22 | + - Clean, modular design with proper inputs/outputs |
| 23 | + - Now uses external bash scripts instead of inline code |
| 24 | + |
| 25 | +#### ✅ 3. Centralized Configuration Management |
| 26 | +- **File**: `/.github/locales-config.json` |
| 27 | +- **Features**: |
| 28 | + - Single source of truth for all locale configurations |
| 29 | + - Added `orama_private_api_key` field for all locales |
| 30 | + - Easy maintenance and updates |
| 31 | + |
| 32 | +#### ✅ 4. Extracted Testable Bash Scripts |
| 33 | + |
| 34 | +**Scripts Created:** |
| 35 | +1. **`generate-files-config.sh`** - Generates dynamic file patterns for change detection |
| 36 | +2. **`generate-locale-matrix.sh`** - Creates deployment matrix based on changes and trigger type |
| 37 | +3. **`test-locale-scripts.sh`** - Comprehensive test suite with 10 test scenarios |
| 38 | + |
| 39 | +**Script Features:** |
| 40 | +- Comprehensive error handling and validation |
| 41 | +- Detailed logging and debugging capabilities |
| 42 | +- JSON validation and formatting |
| 43 | +- Support for all trigger scenarios |
| 44 | +- Modular, reusable functions |
| 45 | + |
| 46 | +#### ✅ 5. Updated GitHub Action to Use Scripts |
| 47 | +- **Before**: 150+ lines of inline bash code |
| 48 | +- **After**: Clean, concise action that calls external scripts |
| 49 | +- **Benefits**: |
| 50 | + - Much easier to read and maintain |
| 51 | + - Logic can be tested locally |
| 52 | + - Scripts can be reused in other contexts |
| 53 | + - Better separation of concerns |
| 54 | + |
| 55 | +#### ✅ 6. Comprehensive Testing Suite |
| 56 | +- **10 test scenarios** covering all trigger types and edge cases: |
| 57 | + - Files config generation |
| 58 | + - Manual triggers (all locales, specific locales) |
| 59 | + - Auto triggers (no changes, core changes, locale changes) |
| 60 | + - Docs PR triggers |
| 61 | + - Error handling (invalid triggers, missing parameters) |
| 62 | + - JSON validation |
| 63 | + |
| 64 | +#### ✅ 7. Documentation and Maintenance |
| 65 | +- Created detailed README for the scripts directory |
| 66 | +- Inline documentation and comments in all scripts |
| 67 | +- Usage examples and integration guidelines |
| 68 | + |
| 69 | +### Technical Improvements |
| 70 | + |
| 71 | +#### Before Extraction: |
| 72 | +```yaml |
| 73 | +# Massive inline bash block with 100+ lines |
| 74 | +run: | |
| 75 | + locale_config=$(cat .github/locales-config.json) |
| 76 | + matrix_include="[]" |
| 77 | + # ... 100+ more lines of complex logic |
| 78 | +``` |
| 79 | +
|
| 80 | +#### After Extraction: |
| 81 | +```yaml |
| 82 | +# Clean, simple action call |
| 83 | +run: | |
| 84 | + trigger_type="${{ inputs.trigger-type }}" |
| 85 | + manual_locales="${{ inputs.manual-locales }}" |
| 86 | + |
| 87 | + if [ "$trigger_type" == "manual" ]; then |
| 88 | + output=$(.github/scripts/generate-locale-matrix.sh "$trigger_type" "$manual_locales") |
| 89 | + else |
| 90 | + changes_json='${{ toJSON(steps.changes.outputs) }}' |
| 91 | + output=$(.github/scripts/generate-locale-matrix.sh "$trigger_type" "" "$changes_json") |
| 92 | + fi |
| 93 | + |
| 94 | + echo "$output" >> $GITHUB_OUTPUT |
| 95 | +``` |
| 96 | +
|
| 97 | +### Local Testing Capabilities |
| 98 | +
|
| 99 | +You can now test the locale logic locally: |
| 100 | +
|
| 101 | +```bash |
| 102 | +# Test files config generation |
| 103 | +./.github/scripts/generate-files-config.sh |
| 104 | + |
| 105 | +# Test manual deployment matrix |
| 106 | +./.github/scripts/generate-locale-matrix.sh manual "en,zh-hans" |
| 107 | + |
| 108 | +# Test auto deployment with changes |
| 109 | +./.github/scripts/generate-locale-matrix.sh auto "" '{"core_any_changed": "true"}' |
| 110 | + |
| 111 | +# Run comprehensive test suite |
| 112 | +./.github/scripts/test-locale-scripts.sh |
| 113 | +``` |
| 114 | + |
| 115 | +### Impact and Benefits |
| 116 | + |
| 117 | +1. **Maintainability**: Centralized, modular components that are easier to update |
| 118 | +2. **Testability**: All logic can be tested locally without GitHub Actions |
| 119 | +3. **Reliability**: Comprehensive test coverage with automated validation |
| 120 | +4. **Reusability**: Scripts can be used in other workflows or contexts |
| 121 | +5. **Debugging**: Better logging and error messages for troubleshooting |
| 122 | +6. **Performance**: More efficient with proper error handling and validation |
| 123 | + |
| 124 | +### Files Modified/Created |
| 125 | + |
| 126 | +**Modified:** |
| 127 | +- `/.github/workflows/release.yml` - Uses reusable action |
| 128 | +- `/.github/workflows/update-docs-ci.yml` - Uses reusable action |
| 129 | +- `/.github/locales-config.json` - Added orama_private_api_key fields |
| 130 | + |
| 131 | +**Created:** |
| 132 | +- `/.github/actions/check-locale-changes/action.yml` - Reusable action |
| 133 | +- `/.github/scripts/generate-files-config.sh` - Files config generator |
| 134 | +- `/.github/scripts/generate-locale-matrix.sh` - Matrix generator |
| 135 | +- `/.github/scripts/test-locale-scripts.sh` - Test suite |
| 136 | +- `/.github/scripts/README.md` - Documentation |
| 137 | + |
| 138 | +### Validation |
| 139 | + |
| 140 | +✅ All tests pass (10/10) |
| 141 | +✅ Scripts work correctly for all trigger types |
| 142 | +✅ JSON output is properly formatted and valid |
| 143 | +✅ Error handling works as expected |
| 144 | +✅ Workflows integrate successfully with the reusable action |
| 145 | + |
| 146 | +The extraction is complete and the system is now much more maintainable, testable, and reliable! 🚀 |
0 commit comments