Skip to content

Instantly share code, notes, and snippets.

@henrjk
Last active January 20, 2022 08:25
Show Gist options
  • Save henrjk/4265bc1b4f6fe3f7cd9027b0bcc284f9 to your computer and use it in GitHub Desktop.
Save henrjk/4265bc1b4f6fe3f7cd9027b0bcc284f9 to your computer and use it in GitHub Desktop.
Test ods-pipeline typescript task locally
#!/usr/bin/env bash
set -e
usage_and_exit() {
cat << USAGE >&2
Usage: run-build-task.sh <ods.yaml> task
USAGE
exit 1
}
error_exit() {
echo "$@"
exit 1
}
if [ "$#" -ne 2 ]; then
usage_and_exit
fi
ods_yaml=$1
task=$2
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOT_DIR="$( cd "$SCRIPT_DIR/../.." && pwd )"
ODS_PIPELINE_DIR="$( cd "$ROOT_DIR/../ods/ods-pipeline" && pwd )"
BUILT_SCRIPT="$ODS_PIPELINE_DIR/build/package/scripts/build-typescript.sh"
which yq > /dev/null || error_exit "yq required: brew install yq # see https://github.com/mikefarah/yq"
[ -f "$BUILT_SCRIPT" ] || error_exit "built script expected at $BUILT_SCRIPT"
echo "Using built script at $BUILT_SCRIPT"
working_dir=$(yq e ".pipeline.tasks.[] | select(.name == \"$task\").params.[] | select(.name == \"working-dir\").value" "$ods_yaml")
output_dir=$(yq e ".pipeline.tasks.[] | select(.name == \"$task\").params.[] | select(.name == \"output-dir\").value" "$ods_yaml")
max_lint_warnings=$(yq e ".pipeline.tasks.[] | select(.name == \"$task\").params.[] | select(.name == \"max-lint-warnings\").value" "$ods_yaml")
if [ -z "$max_lint_warnings" ]; then
max_lint_warnings=0
fi
copy_node_modules=$(yq e ".pipeline.tasks.[] | select(.name == \"$task\").params.[] | select(.name == \"copy-node-modules\").value" "$ods_yaml")
if [ -z "$copy_node_modules" ]; then
copy_node_modules=false
fi
working_dir_commit_sha=$(git rev-parse "HEAD:$working_dir")
# echo $working_dir
# echo $output_dir
set -x
set +e
start_time=$SECONDS
pipeline_cache_dir="$HOME/.pipeline-cache-dir"
# rm -rf "$pipeline_cache_dir"
mkdir -p "$pipeline_cache_dir"
rm -rf ".ods/artifacts"
time $BUILT_SCRIPT "--debug=true" "--working-dir=$working_dir" "--working-dir-commit-sha=$working_dir_commit_sha" "--output-dir=$output_dir" "--max-lint-warnings=$max_lint_warnings" "--copy-node-modules=$copy_node_modules" \
"--pipeline-cache-dir=$pipeline_cache_dir"
elapsed=$(( SECONDS - start_time ))
echo "command took $elapsed seconds"
@henrjk
Copy link
Author

henrjk commented Jan 19, 2022

This script is meant to be a template and adjusted to your local testing needs.

The script requires yq (see error message in script).
Also it expects ods-pipeline directory in a certain relative location to this script. Again just adjust this script.

My main usage is that in one of my projects

<foo-repox> ->  ../foo-tools/scripts/run-build-task.sh ods.yaml build-fe

where build-fe would be a typescript task in the ods.yaml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment