From 7458a9129a063be4b89c7755f7f65f7cc62e8db0 Mon Sep 17 00:00:00 2001 From: Neta Nir Date: Thu, 3 Dec 2020 02:08:54 -0800 Subject: [PATCH] chore: remove packaging prerequisites requirements from build (#11691) Split the prerequisites check for `pack` and `build`. Executing `build` does not execute pack, which means it does not require the tools for packaging (`mvn`, `python`, `.Net`, `java`) to be installed locally. This PR splits `check-prerequisites` into two separate scripts, `check-build-prerequisites` and `check-pack-prerequisites`. For build check: * `node` * `yarn` * `docker` (arguable, but fine) For pack check: * all build prerequisites * `mvn` * `java` * `.Net` * `python` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- build.sh | 2 +- pack.sh | 4 + scripts/check-build-prerequisites.sh | 91 +++++++++++++++++++ ...uisites.sh => check-pack-prerequisites.sh} | 67 ++------------ 4 files changed, 102 insertions(+), 62 deletions(-) create mode 100644 scripts/check-build-prerequisites.sh rename scripts/{check-prerequisites.sh => check-pack-prerequisites.sh} (61%) diff --git a/build.sh b/build.sh index 13d525731b16e..14d8c27935405 100755 --- a/build.sh +++ b/build.sh @@ -56,7 +56,7 @@ fail() { # Verify all required tools are present before starting the build if [ "$check_prereqs" == "true" ]; then - /bin/bash ./scripts/check-prerequisites.sh + /bin/bash ./scripts/check-build-prerequisites.sh fi # Prepare for build with references diff --git a/pack.sh b/pack.sh index de48b7dea0c2f..727c6faaf63cd 100755 --- a/pack.sh +++ b/pack.sh @@ -19,6 +19,10 @@ distdir="$PWD/dist" rm -fr ${distdir} mkdir -p ${distdir} +if ${CHECK_PREREQS:-true}; then + /bin/bash ./scripts/check-pack-prerequisites.sh +fi + # Split out jsii and non-jsii packages. Jsii packages will be built all at once. # Non-jsii packages will be run individually. echo "Collecting package list..." >&2 diff --git a/scripts/check-build-prerequisites.sh b/scripts/check-build-prerequisites.sh new file mode 100644 index 0000000000000..c703d9f3e94e7 --- /dev/null +++ b/scripts/check-build-prerequisites.sh @@ -0,0 +1,91 @@ +#!/bin/bash +set -euo pipefail + +scriptdir=$(cd $(dirname $0) && pwd) + +# Testing with this to simulate different installed apps: +# docker run -it -v ~/Source/aws-cdk:/var/cdk ubuntu bash + +# Note: Don't use \d in regex, it doesn't work on Macs without GNU tools installed +# Use [0-9] instead + +die() { echo "$*" 1>&2 ; exit 1; } +wrong_version() { echo "Found $app version $app_v. Install $app >= $app_min" 1>&2; exit 1; } + +check_which() { + local app=$1 + local min=$2 + + echo -e "Checking if $app is installed... \c" + + w=$(which ${app}) || w="" + + if [ -z "$w" ] || [ "$w" == "$app not found" ] + then + die "Missing dependency: $app. Install $app >= $min" + else + echo "Ok" + fi +} + +app="" +app_min="" +app_v="" + +# [Node.js >= 10.13.0] +# ⚠️ versions `13.0.0` to `13.6.0` are not supported due to compatibility issues with our dependencies. +app="node" +app_min="v10.13.0" +check_which $app $app_min +app_v=$(node --version) + +# Check for version 10.*.* - 29.*.* +echo -e "Checking node version... \c" +if [ $(echo $app_v | grep -c -E "v[12][0-9]\.[0-9]+\.[0-9]+") -eq 1 ] +then + # Check for version 13.0 to 13.6 + if [ $(echo $app_v | grep -c -E "v13\.[0-6]\.[0-9]+") -eq 1 ] + then + die "node versions 13.0.0 to 13.6.0 are not supported due to compatibility issues with our dependencies." + else + # Check for version < 10.13 + if [ $(echo $app_v | grep -c -E "v10\.([0-9]|1[0-2])\.[0-9]+") -eq 1 ] + then + wrong_version + else + echo "Ok" + fi + fi +else + echo "Not 12" + wrong_version +fi + +# [Yarn >= 1.19.1, < 1.30] +app="yarn" +app_min="1.19.1" +check_which $app $app_min +app_v=$(${app} --version) +echo -e "Checking yarn version... \c" +if [ $(echo $app_v | grep -c -E "1\.(19|2[0-9])\.[0-9]+") -eq 1 ] +then + echo "Ok" +else + wrong_version +fi + +# [Docker >= 19.03] +app="docker" +app_min="19.03.0" +check_which $app $app_min + +# Make sure docker is running +echo -e "Checking if docker is running... \c" +docker_running=$(docker ps) +if [ $? -eq 0 ] +then + echo "Ok" +else + die "Docker is not running" +fi + diff --git a/scripts/check-prerequisites.sh b/scripts/check-pack-prerequisites.sh similarity index 61% rename from scripts/check-prerequisites.sh rename to scripts/check-pack-prerequisites.sh index 9a4232d9e3e2d..8dca0902114e5 100755 --- a/scripts/check-prerequisites.sh +++ b/scripts/check-pack-prerequisites.sh @@ -1,16 +1,15 @@ #!/bin/bash set -euo pipefail +scriptdir=$(cd $(dirname $0) && pwd) +source ${scriptdir}/check-build-prerequisites.sh + # Testing with this to simulate different installed apps: # docker run -it -v ~/Source/aws-cdk:/var/cdk ubuntu bash # Note: Don't use \d in regex, it doesn't work on Macs without GNU tools installed # Use [0-9] instead -app="" -app_min="" -app_v="" - die() { echo "$*" 1>&2 ; exit 1; } wrong_version() { echo "Found $app version $app_v. Install $app >= $app_min" 1>&2; exit 1; } @@ -30,47 +29,9 @@ check_which() { fi } -# [Node.js >= 10.13.0] -# ⚠️ versions `13.0.0` to `13.6.0` are not supported due to compatibility issues with our dependencies. -app="node" -app_min="v10.13.0" -check_which $app $app_min -app_v=$(node --version) - -# Check for version 10.*.* - 29.*.* -echo -e "Checking node version... \c" -if [ $(echo $app_v | grep -c -E "v[12][0-9]\.[0-9]+\.[0-9]+") -eq 1 ] -then - # Check for version 13.0 to 13.6 - if [ $(echo $app_v | grep -c -E "v13\.[0-6]\.[0-9]+") -eq 1 ] - then - die "node versions 13.0.0 to 13.6.0 are not supported due to compatibility issues with our dependencies." - else - # Check for version < 10.13 - if [ $(echo $app_v | grep -c -E "v10\.([0-9]|1[0-2])\.[0-9]+") -eq 1 ] - then - wrong_version - else - echo "Ok" - fi - fi -else - echo "Not 12" - wrong_version -fi - -# [Yarn >= 1.19.1, < 1.30] -app="yarn" -app_min="1.19.1" -check_which $app $app_min -app_v=$(${app} --version) -echo -e "Checking yarn version... \c" -if [ $(echo $app_v | grep -c -E "1\.(19|2[0-9])\.[0-9]+") -eq 1 ] -then - echo "Ok" -else - wrong_version -fi +app="" +app_min="" +app_v="" # [Java OpenJDK 8, 11, 14] @@ -143,19 +104,3 @@ then else wrong_version fi - -# [Docker >= 19.03] -app="docker" -app_min="19.03.0" -check_which $app $app_min - -# Make sure docker is running -echo -e "Checking if docker is running... \c" -docker_running=$(docker ps) -if [ $? -eq 0 ] -then - echo "Ok" -else - die "Docker is not running" -fi -