1
1
#! /bin/bash
2
2
3
3
# Script to generate locale deployment matrix based on trigger type and changes
4
- # Usage: ./generate-locale-matrix.sh <trigger-type> [manual-locales] [changes-json]
4
+ # Usage: ./generate-locale-matrix.sh <trigger-type> [manual-locales] [changes-json-file ]
5
5
#
6
6
# trigger-type: "manual", "auto", or "docs-pr"
7
7
# manual-locales: comma-separated list of locales (for manual trigger)
8
- # changes-json: JSON output from changed-files action (for auto/docs-pr triggers)
8
+ # changes-json-file: File path containing JSON output from changed-files action (for auto/docs-pr triggers)
9
9
10
10
set -e
11
11
@@ -20,17 +20,17 @@ LOCALE_CONFIG_FILE="$ROOT_DIR/.github/locales-config.json"
20
20
21
21
# Function to print usage
22
22
usage () {
23
- echo " Usage: $0 <trigger-type> [manual-locales] [changes-json]"
23
+ echo " Usage: $0 <trigger-type> [manual-locales] [changes-json-file ]"
24
24
echo " "
25
25
echo " Arguments:"
26
- echo " trigger-type Type of trigger: 'manual', 'auto', or 'docs-pr'"
27
- echo " manual-locales Comma-separated list of locales (optional, for manual trigger)"
28
- echo " changes-json JSON output from changed-files action (for auto/docs-pr triggers)"
26
+ echo " trigger-type Type of trigger: 'manual', 'auto', or 'docs-pr'"
27
+ echo " manual-locales Comma-separated list of locales (optional, for manual trigger)"
28
+ echo " changes-json-file File path containing JSON output from changed-files action (for auto/docs-pr triggers)"
29
29
echo " "
30
30
echo " Examples:"
31
31
echo " $0 manual"
32
32
echo " $0 manual 'en,zh-hans'"
33
- echo " $0 docs-pr '{ \" core_any_changed \" : \" true \" , \" en_any_changed \" : \" false \" } '"
33
+ echo " $0 docs-pr '/tmp/changes.json '"
34
34
exit 1
35
35
}
36
36
@@ -186,7 +186,7 @@ process_auto_trigger() {
186
186
main () {
187
187
local trigger_type=" $1 "
188
188
local manual_locales=" $2 "
189
- local changes_json =" $3 "
189
+ local changes_json_file =" $3 "
190
190
191
191
# Validate arguments
192
192
if [ -z " $trigger_type " ]; then
@@ -231,15 +231,28 @@ main() {
231
231
matrix_include=" $RESULT_MATRIX_INCLUDE "
232
232
has_changes=" $RESULT_HAS_CHANGES "
233
233
else
234
- # For auto and docs-pr triggers, changes_json is required
235
- if [ -z " $changes_json " ]; then
236
- echo " Error: changes-json is required for auto/docs-pr triggers" >&2
234
+ # For auto and docs-pr triggers, changes_json_file is required
235
+ if [ -z " $changes_json_file " ]; then
236
+ echo " Error: changes-json-file is required for auto/docs-pr triggers" >&2
237
237
usage
238
238
fi
239
239
240
+ # Check if changes JSON file exists
241
+ if [ ! -f " $changes_json_file " ]; then
242
+ echo " Error: Changes JSON file not found: $changes_json_file " >&2
243
+ exit 1
244
+ fi
245
+
246
+ # Read changes JSON from file
247
+ local changes_json
248
+ if ! changes_json=$( cat " $changes_json_file " ) ; then
249
+ echo " Error: Failed to read changes JSON file: $changes_json_file " >&2
250
+ exit 1
251
+ fi
252
+
240
253
# Validate changes JSON
241
254
if ! validate_json " $changes_json " ; then
242
- echo " Error: Invalid changes JSON provided " >&2
255
+ echo " Error: Invalid changes JSON in file: $changes_json_file " >&2
243
256
exit 1
244
257
fi
245
258
0 commit comments