@@ -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
1722 with :
1823 fetch-depth : 0
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+ echo "Final matrix: $matrix_include"
73+
74+ # Ensure the matrix is properly formatted as a single line
75+ matrix_output=$(echo "$matrix_include" | jq -c '.')
76+ echo "Matrix output (compact): $matrix_output"
77+ echo "include=$matrix_output" >> $GITHUB_OUTPUT
78+
79+ - name : Generate dynamic files config (automatic trigger)
80+ if : github.event_name == 'push'
2181 id : generate-files-config
2282 shell : bash
2383 run : |
@@ -54,14 +114,16 @@ jobs:
54114 echo "EOF"
55115 } >> $GITHUB_OUTPUT
56116
57- - name : Get changed files with dynamic config
117+ - name : Get changed files with dynamic config (automatic trigger)
118+ if : github.event_name == 'push'
58119 id : changes
59120 uses : tj-actions/changed-files@v41
60121 with :
61122 files_yaml : ${{ steps.generate-files-config.outputs.files_yaml }}
62123
63- - name : Generate deployment matrix
64- id : generate-matrix
124+ - name : Generate deployment matrix (automatic trigger)
125+ if : github.event_name == 'push'
126+ id : generate-matrix-auto
65127 shell : bash
66128 run : |
67129 # Read locale config
@@ -110,6 +172,16 @@ jobs:
110172 echo "Matrix output (compact): $matrix_output"
111173 echo "include=$matrix_output" >> $GITHUB_OUTPUT
112174
175+ - name : Set final matrix output
176+ id : generate-matrix
177+ shell : bash
178+ run : |
179+ if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
180+ echo "include=${{ steps.generate-matrix-manual.outputs.include }}" >> $GITHUB_OUTPUT
181+ else
182+ echo "include=${{ steps.generate-matrix-auto.outputs.include }}" >> $GITHUB_OUTPUT
183+ fi
184+
113185 deploy-and-update-index :
114186 needs : check-changes
115187 if : needs.check-changes.outputs.matrix-include != '[]'
0 commit comments