From 4dc6da42e92ee87f376bb6c72c18cbf28718eb73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrich=20Kr=C3=A4mer?= Date: Thu, 20 Jan 2022 07:08:23 +0100 Subject: [PATCH] build-typescript draft changes --- build/package/scripts/build-typescript.sh | 69 ++++++++++++++++++++--- 1 file changed, 61 insertions(+), 8 deletions(-) diff --git a/build/package/scripts/build-typescript.sh b/build/package/scripts/build-typescript.sh index 29fb3fd7..f3529922 100755 --- a/build/package/scripts/build-typescript.sh +++ b/build/package/scripts/build-typescript.sh @@ -22,6 +22,7 @@ copyLintReport() { BUILD_DIR="dist" OUTPUT_DIR="docker" WORKING_DIR="." +PIPELINE_CACHE_DIR="" ARTIFACT_PREFIX="" DEBUG="${DEBUG:-false}" MAX_LINT_WARNINGS="0" @@ -34,6 +35,9 @@ while [[ "$#" -gt 0 ]]; do --working-dir) WORKING_DIR="$2"; shift;; --working-dir=*) WORKING_DIR="${1#*=}";; + --pipeline-cache-dir) PIPELINE_CACHE_DIR="$2"; shift;; + --pipeline-cache-dir=*) PIPELINE_CACHE_DIR="${1#*=}";; + --output-dir) OUTPUT_DIR="$2"; shift;; --output-dir=*) OUTPUT_DIR="${1#*=}";; @@ -60,9 +64,23 @@ if [ "${DEBUG}" == "true" ]; then fi ROOT_DIR=$(pwd) -if [ "${WORKING_DIR}" != "." ]; then - cd "${WORKING_DIR}" - ARTIFACT_PREFIX="${WORKING_DIR/\//-}-" +# NOTE: git is currently not available in build script +git_ref=$(cat .ods/git-ref) +case $git_ref in + master|develop) + echo "INFO: not using cache in master or develop branch" + PIPELINE_CACHE_DIR="" + ;; + *);; +esac + + +if [ -d "$PIPELINE_CACHE_DIR" ]; then + # NOTE: rsync is currently not available in build script + echo "Updating cache dir with sources ..." + # rsync -auvhp --itemize-changes --delete --exclude=node_modules "${WORKING_DIR}" "$PIPELINE_CACHE_DIR" + # rsync -auvhp --progress --delete --exclude=node_modules "${WORKING_DIR}" "$PIPELINE_CACHE_DIR" + rsync -auhp --info=progress2 --delete --exclude=node_modules "${WORKING_DIR}" "$PIPELINE_CACHE_DIR" # the info progress2 does not work with verbose, needs rather new rsync version. fi echo "Configuring npm to use Nexus ..." @@ -78,14 +96,37 @@ if [ -n "${NEXUS_HOST}" ] && [ -n "${NEXUS_USERNAME}" ] && [ -n "${NEXUS_PASSWOR npm config set strict-ssl=false fi; +build_dir="${WORKING_DIR}" +output_dir_abs="${ROOT_DIR}/${WORKING_DIR}/${OUTPUT_DIR}" +if [ -d "$PIPELINE_CACHE_DIR" ]; then + build_dir="$PIPELINE_CACHE_DIR/$WORKING_DIR" +fi + +if [ "${WORKING_DIR}" != "." ]; then + ARTIFACT_PREFIX="${WORKING_DIR/\//-}-" +fi +if [ "${build_dir}" != "." ]; then + cd "${build_dir}" +fi + echo "Installing dependencies ..." -npm ci +start_time=$SECONDS +if [ -d "$PIPELINE_CACHE_DIR" ]; then + npm i +else + npm ci +fi +elapsed=$(( SECONDS - start_time )) +echo "Installing dependencies took $elapsed seconds" echo "Linting ..." +start_time=$SECONDS set +e npx eslint src --ext "${LINT_FILE_EXT}" --format compact --max-warnings "${MAX_LINT_WARNINGS}" > eslint-report.txt exitcode=$? set -e +elapsed=$(( SECONDS - start_time )) +echo "linting took $elapsed seconds" if [ $exitcode == 0 ]; then echo "OK" > eslint-report.txt @@ -96,16 +137,25 @@ else fi echo "Building ..." +start_time=$SECONDS npm run build -mkdir -p "${OUTPUT_DIR}" -cp -r "${BUILD_DIR}" "${OUTPUT_DIR}/dist" +elapsed=$(( SECONDS - start_time )) +echo "build took $elapsed seconds" +mkdir -p "${output_dir_abs}" +cp -rv "${BUILD_DIR}" "${output_dir_abs}/dist" if [ "${COPY_NODE_MODULES}" = true ]; then - echo "Copying node_modules to ${OUTPUT_DIR}/dist/node_modules ..." - cp -r node_modules "${OUTPUT_DIR}/dist/node_modules" + echo "Copying node_modules to ${output_dir_abs}/dist/node_modules ..." + start_time=$SECONDS + cp -r node_modules "${output_dir_abs}/dist/node_modules" + elapsed=$(( SECONDS - start_time )) + echo "copying node_modules took $elapsed seconds" fi echo "Testing ..." +# Implement skipping tests for TypeScript #238 +# TODO: is this still needed? +# https://github.com/opendevstack/ods-pipeline/issues/238 if [ -f "${ROOT_DIR}/.ods/artifacts/xunit-reports/${ARTIFACT_PREFIX}report.xml" ]; then echo "Test artifacts already present, skipping tests ..." # Copy artifacts to working directory so that the SonarQube scanner can pick them up later. @@ -131,4 +181,7 @@ else cp build/coverage/lcov.info "${ROOT_DIR}/.ods/artifacts/code-coverage/${ARTIFACT_PREFIX}lcov.info" fi +# Provide disk usage so that one can use this to estimate needs + + supply-sonar-project-properties-default