|
4 | 4 | # This bundles them with their dependencies into a single executable node.js script. |
5 | 5 |
|
6 | 6 | # In order for this script to be safely run from anywhere, we cannot use the raw relative path '../actions'. |
7 | | -declare ACTIONS_DIR |
8 | | -ACTIONS_DIR="$(dirname "$(dirname "$0")")/actions/javascript" |
9 | | - |
10 | | -# List of paths to all JS files that implement our GH Actions |
11 | | -declare -r GITHUB_ACTIONS=( |
12 | | - "$ACTIONS_DIR/validateReassureOutput/validateReassureOutput.ts" |
13 | | -) |
14 | | - |
15 | | -# This will be inserted at the top of all compiled files as a warning to devs. |
16 | | -declare -r NOTE_DONT_EDIT='/** |
17 | | - * NOTE: This is a compiled file. DO NOT directly edit this file. |
18 | | - */ |
19 | | -' |
| 7 | +ACTIONS_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../actions/javascript" &>/dev/null && pwd)" |
| 8 | +readonly ACTIONS_DIR |
20 | 9 |
|
21 | 10 | # This stores all the process IDs of the ncc commands so they can run in parallel |
22 | | -declare ASYNC_BUILDS |
| 11 | +ASYNC_BUILDS=() |
23 | 12 |
|
24 | | -for ((i=0; i < ${#GITHUB_ACTIONS[@]}; i++)); do |
25 | | - ACTION=${GITHUB_ACTIONS[$i]} |
26 | | - ACTION_DIR=$(dirname "$ACTION") |
| 13 | +# Build all the actions in the background |
| 14 | +for ACTION in "$ACTIONS_DIR"/*/*.ts; do |
| 15 | + ACTION_DIR=$(dirname "$ACTION") |
| 16 | + npx ncc build --transpile-only --external encoding "$ACTION" -o "$ACTION_DIR" & |
| 17 | + ASYNC_BUILDS+=($!) |
| 18 | +done |
27 | 19 |
|
28 | | - # Build the action in the background |
29 | | - npx ncc build --transpile-only --external encoding "$ACTION" -o "$ACTION_DIR" & |
30 | | - ASYNC_BUILDS[i]=$! |
| 20 | +# Wait for the background build to finish |
| 21 | +EXIT_CODE=0 |
| 22 | +for PID in "${ASYNC_BUILDS[@]}"; do |
| 23 | + if ! wait "$PID"; then |
| 24 | + EXIT_CODE=1 |
| 25 | + fi |
31 | 26 | done |
32 | 27 |
|
33 | | -for ((i=0; i < ${#GITHUB_ACTIONS[@]}; i++)); do |
34 | | - ACTION=${GITHUB_ACTIONS[$i]} |
35 | | - ACTION_DIR=$(dirname "$ACTION") |
| 28 | +# Prepend this note at the top of all compiled files as a warning to devs. |
| 29 | +readonly NOTE_DONT_EDIT='/** |
| 30 | + * NOTE: This is a compiled file. DO NOT directly edit this file. |
| 31 | + */ |
| 32 | +' |
| 33 | +for OUTPUT_FILE in "$ACTIONS_DIR"/*/index.js; do |
| 34 | + echo "$NOTE_DONT_EDIT$(cat "$OUTPUT_FILE")" > "$OUTPUT_FILE" |
| 35 | +done |
36 | 36 |
|
37 | | - # Wait for the background build to finish |
38 | | - wait "${ASYNC_BUILDS[$i]}" |
| 37 | +if [[ EXIT_CODE -ne 0 ]]; then |
| 38 | + echo "❌ One or more builds failed" |
| 39 | + exit 1 |
| 40 | +fi |
39 | 41 |
|
40 | | - # Prepend the warning note to the top of the compiled file |
41 | | - OUTPUT_FILE="$ACTION_DIR/index.js" |
42 | | - echo "$NOTE_DONT_EDIT$(cat "$OUTPUT_FILE")" > "$OUTPUT_FILE" |
43 | | -done |
| 42 | +echo "✅ All builds succeeded" |
0 commit comments