@@ -2,6 +2,11 @@ name: Release
22
33on :
44 workflow_dispatch :
5+ inputs :
6+ locales :
7+ description : ' Comma-separated list of locales to deploy (e.g., en,zh-hans). Leave empty to deploy all enabled locales.'
8+ required : false
9+ type : string
510 push :
611 branches :
712 - main
@@ -10,14 +15,62 @@ jobs:
1015 check-changes :
1116 runs-on : ubuntu-latest
1217 outputs :
13- matrix-include : ${{ steps.generate-matrix.outputs.include }}
18+ matrix-include : ${{ github.event_name == 'workflow_dispatch' && steps.generate-matrix-manual.outputs.include || steps.generate-matrix-auto .outputs.include }}
1419 steps :
1520 - name : Checkout code
1621 uses : actions/checkout@v3
1722 with :
18- fetch-depth : 0
23+ fetch-depth : ${{ github.event_name == 'push' && 0 || 1 }}
1924
20- - name : Generate dynamic files config
25+ - name : Generate deployment matrix (manual trigger)
26+ if : github.event_name == 'workflow_dispatch'
27+ id : generate-matrix-manual
28+ shell : bash
29+ run : |
30+ # Read locale config
31+ locale_config=$(cat .github/locales-config.json)
32+
33+ # Initialize matrix
34+ matrix_include="[]"
35+
36+ # Get manual input
37+ manual_locales="${{ github.event.inputs.locales }}"
38+
39+ if [ -z "$manual_locales" ]; then
40+ echo "No specific locales provided, deploying all enabled locales"
41+ # Deploy all enabled locales
42+ for locale in $(echo "$locale_config" | jq -r 'keys[]'); do
43+ enabled=$(echo "$locale_config" | jq -r ".[\"$locale\"].enabled")
44+ secret_project_id=$(echo "$locale_config" | jq -r ".[\"$locale\"].secret_project_id")
45+
46+ if [ "$enabled" == "true" ]; then
47+ echo "Adding $locale to deployment matrix"
48+ matrix_include=$(echo "$matrix_include" | jq --arg locale "$locale" --arg secret_id "$secret_project_id" '. + [{"locale": $locale, "secret_project_id": $secret_id}]')
49+ fi
50+ done
51+ else
52+ echo "Manual locales specified: $manual_locales"
53+ # Parse comma-separated locales
54+ IFS=',' read -ra LOCALE_ARRAY <<< "$manual_locales"
55+ for locale in "${LOCALE_ARRAY[@]}"; do
56+ # Trim whitespace
57+ locale=$(echo "$locale" | xargs)
58+
59+ # Check if locale exists and is enabled
60+ enabled=$(echo "$locale_config" | jq -r ".[\"$locale\"].enabled // \"false\"")
61+ secret_project_id=$(echo "$locale_config" | jq -r ".[\"$locale\"].secret_project_id // \"\"")
62+
63+ if [ "$enabled" == "true" ] && [ -n "$secret_project_id" ]; then
64+ echo "Adding $locale to deployment matrix"
65+ matrix_include=$(echo "$matrix_include" | jq --arg locale "$locale" --arg secret_id "$secret_project_id" '. + [{"locale": $locale, "secret_project_id": $secret_id}]')
66+ else
67+ echo "Skipping $locale (not enabled or not found in config)"
68+ fi
69+ done
70+ fi
71+
72+ - name : Generate dynamic files config (automatic trigger)
73+ if : github.event_name == 'push'
2174 id : generate-files-config
2275 shell : bash
2376 run : |
@@ -54,14 +107,16 @@ jobs:
54107 echo "EOF"
55108 } >> $GITHUB_OUTPUT
56109
57- - name : Get changed files with dynamic config
110+ - name : Get changed files with dynamic config (automatic trigger)
111+ if : github.event_name == 'push'
58112 id : changes
59113 uses : tj-actions/changed-files@v41
60114 with :
61115 files_yaml : ${{ steps.generate-files-config.outputs.files_yaml }}
62116
63- - name : Generate deployment matrix
64- id : generate-matrix
117+ - name : Generate deployment matrix (automatic trigger)
118+ if : github.event_name == 'push'
119+ id : generate-matrix-auto
65120 shell : bash
66121 run : |
67122 # Read locale config
@@ -108,7 +163,17 @@ jobs:
108163 # Ensure the matrix is properly formatted as a single line
109164 matrix_output=$(echo "$matrix_include" | jq -c '.')
110165 echo "Matrix output (compact): $matrix_output"
111- echo "include=$matrix_output" >> $GITHUB_OUTPUT
166+
167+ # Debug: Check if it's valid JSON
168+ echo "Validating JSON..."
169+ if echo "$matrix_output" | jq . >/dev/null 2>&1; then
170+ echo "JSON is valid"
171+ echo "include=$matrix_output" >> $GITHUB_OUTPUT
172+ else
173+ echo "Invalid JSON generated: $matrix_output"
174+ echo "Outputting empty array instead"
175+ echo "include=[]" >> $GITHUB_OUTPUT
176+ fi
112177
113178 deploy-and-update-index :
114179 needs : check-changes
0 commit comments