Skip to content

Commit e345a47

Browse files
committed
Improve buildActions.sh script
1 parent ecd8610 commit e345a47

1 file changed

Lines changed: 28 additions & 29 deletions

File tree

.github/scripts/buildActions.sh

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,39 @@
44
# This bundles them with their dependencies into a single executable node.js script.
55

66
# 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
209

2110
# This stores all the process IDs of the ncc commands so they can run in parallel
22-
declare ASYNC_BUILDS
11+
ASYNC_BUILDS=()
2312

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
2719

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
3126
done
3227

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
3636

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
3941

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

Comments
 (0)