Skip to content

Commit

Permalink
build-typescript draft changes
Browse files Browse the repository at this point in the history
  • Loading branch information
henrjk committed Jan 20, 2022
1 parent b496f4f commit 4dc6da4
Showing 1 changed file with 61 additions and 8 deletions.
69 changes: 61 additions & 8 deletions build/package/scripts/build-typescript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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#*=}";;

Expand All @@ -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 ..."
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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

0 comments on commit 4dc6da4

Please sign in to comment.