11#! /bin/bash
22
33# 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 ]
55#
66# trigger-type: "manual", "auto", or "docs-pr"
77# 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)
99
1010set -e
1111
@@ -20,17 +20,17 @@ LOCALE_CONFIG_FILE="$ROOT_DIR/.github/locales-config.json"
2020
2121# Function to print usage
2222usage () {
23- echo " Usage: $0 <trigger-type> [manual-locales] [changes-json]"
23+ echo " Usage: $0 <trigger-type> [manual-locales] [changes-json-file ]"
2424 echo " "
2525 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)"
2929 echo " "
3030 echo " Examples:"
3131 echo " $0 manual"
3232 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 '"
3434 exit 1
3535}
3636
@@ -186,7 +186,7 @@ process_auto_trigger() {
186186main () {
187187 local trigger_type=" $1 "
188188 local manual_locales=" $2 "
189- local changes_json =" $3 "
189+ local changes_json_file =" $3 "
190190
191191 # Validate arguments
192192 if [ -z " $trigger_type " ]; then
@@ -231,15 +231,28 @@ main() {
231231 matrix_include=" $RESULT_MATRIX_INCLUDE "
232232 has_changes=" $RESULT_HAS_CHANGES "
233233 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
237237 usage
238238 fi
239239
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+
240253 # Validate changes JSON
241254 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
243256 exit 1
244257 fi
245258
0 commit comments