Skip to content

Commit

Permalink
build: log npm run postinstall steps to STDOUT so they are visible …
Browse files Browse the repository at this point in the history
…in CI (openedx#33142)

Without this change, `npm run postinstall` (aka
scripts/copy-node-modules.sh) uses `set -x`, which echo steps to STDERR.
By default, it seems that GitHub Actions doesn't show STDERR.

Having the steps visible in CI was very useful while debugging some
Tutor build improvements, so I figured it would be good to upstream the
change.
  • Loading branch information
kdmccormick authored Oct 4, 2023
1 parent 32c2798 commit c116371
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions scripts/copy-node-modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,33 @@ log ( ) {
echo -e "${COL_LOG}$* $COL_OFF"
}

# Print a command (prefixed with '+') and then run it, to aid in debugging.
# This is just like `set -x`, except that `set -x` prints to STDERR, which is hidden
# by GitHub Actions logs. This functions prints to STDOUT, which is visible.
log_and_run ( ) {
log "+$*"
"$@" # Joins arguments to form a command (quoting as necessary) and runs the command.
}

log "====================================================================================="
log "Copying required assets from node_modules..."
log "-------------------------------------------------------------------------------"

# Start echoing all commands back to user for ease of debugging.
set -x

log "Ensuring vendor directories exist..."
mkdir -p "$vendor_js"
mkdir -p "$vendor_css"
log_and_run mkdir -p "$vendor_js"
log_and_run mkdir -p "$vendor_css"

log "Copying studio-frontend JS & CSS from node_modules into vendor directores..."
while read -r -d $'\0' src_file ; do
if [[ "$src_file" = *.css ]] || [[ "$src_file" = *.css.map ]] ; then
cp --force "$src_file" "$vendor_css"
log_and_run cp --force "$src_file" "$vendor_css"
else
cp --force "$src_file" "$vendor_js"
log_and_run cp --force "$src_file" "$vendor_js"
fi
done < <(find "$node_modules/@edx/studio-frontend/dist" -type f -print0)

log "Copying certain JS modules from node_modules into vendor directory..."
cp --force \
log_and_run cp --force \
"$node_modules/backbone.paginator/lib/backbone.paginator.js" \
"$node_modules/backbone/backbone.js" \
"$node_modules/bootstrap/dist/js/bootstrap.bundle.js" \
Expand All @@ -66,8 +71,8 @@ cp --force \

log "Copying certain JS developer modules into vendor directory..."
if [[ "${NODE_ENV:-production}" = development ]] ; then
cp --force "$node_modules/sinon/pkg/sinon.js" "$vendor_js"
cp --force "$node_modules/squirejs/src/Squire.js" "$vendor_js"
log_and_run cp --force "$node_modules/sinon/pkg/sinon.js" "$vendor_js"
log_and_run cp --force "$node_modules/squirejs/src/Squire.js" "$vendor_js"
else
# TODO: https://github.com/openedx/edx-platform/issues/31768
# In the old implementation of this scipt (pavelib/assets.py), these two
Expand All @@ -77,13 +82,10 @@ else
# However, in the future, it would be good to only copy them for dev
# builds. Furthermore, these libraries should not be `npm install`ed
# into prod builds in the first place.
cp --force "$node_modules/sinon/pkg/sinon.js" "$vendor_js" || true # "|| true" means "tolerate errors"; in this case,
cp --force "$node_modules/squirejs/src/Squire.js" "$vendor_js" || true # that's "tolerate if these files don't exist."
log_and_run cp --force "$node_modules/sinon/pkg/sinon.js" "$vendor_js" || true # "|| true" means "tolerate errors"; in this case,
log_and_run cp --force "$node_modules/squirejs/src/Squire.js" "$vendor_js" || true # that's "tolerate if these files don't exist."
fi

# Done echoing.
set +x

log "-------------------------------------------------------------------------------"
log " Done copying required assets from node_modules."
log "====================================================================================="
Expand Down

0 comments on commit c116371

Please sign in to comment.