Skip to content

Commit

Permalink
chore: add prerequisite check before build (aws#8929)
Browse files Browse the repository at this point in the history
This PR is difficult to test, since it's checking for globally installed dependencies like Java, Dotnet, etc. I'm concerned mostly about the effects on our build process, since there may be regex patterns for valid installed versions that I missed.

Hopefully it will have a positive influence on adoption for new contributors by telling them exactly what they are missing before getting deep into a build and seeing confusing error messages.

Closes Issue aws#8847.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
ericzbeard authored and Curtis Eppel committed Aug 11, 2020
1 parent 2d6f5fa commit a9ae6da
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 7 deletions.
14 changes: 7 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ you need to have the following SDKs and tools locally:
- [Node.js >= 10.13.0](https://nodejs.org/download/release/latest-v10.x/)
- We recommend using a version in [Active LTS](https://nodejs.org/en/about/releases/)
- ⚠️ versions `13.0.0` to `13.6.0` are not supported due to compatibility issues with our dependencies.
- [Yarn >= 1.19.1](https://yarnpkg.com/lang/en/docs/install)
- [Java OpenJDK 8](https://docs.aws.amazon.com/corretto/latest/corretto-8-ug/downloads-list.html)
- [Apache Maven](http://maven.apache.org/install.html)
- [.NET Core SDK 3.1](https://www.microsoft.com/net/download)
- [Python 3.6.5](https://www.python.org/downloads/release/python-365/)
- [Ruby 2.5.1](https://www.ruby-lang.org/en/news/2018/03/28/ruby-2-5-1-released/)
- [Yarn >= 1.19.1, < 1.3](https://yarnpkg.com/lang/en/docs/install)
- [Java >= OpenJDK 8, 11, 14](https://docs.aws.amazon.com/corretto/latest/corretto-8-ug/downloads-list.html)
- [Apache Maven >= 3.6.0, < 4.0](http://maven.apache.org/install.html)
- [.NET Core SDK 3.1.x](https://www.microsoft.com/net/download)
- [Python >= 3.6.5, < 4.0](https://www.python.org/downloads/release/python-365/)
- [Ruby >= 2.5.1, < 3.0](https://www.ruby-lang.org/en/news/2018/03/28/ruby-2-5-1-released/)
- [Docker 19.03](https://docs.docker.com/get-docker/)

The basic commands to get the repository cloned and built locally follow:

```console
$ git clone https://github.com/aws/aws-cdk.git
$ cd aws-cdk
$ yarn install
$ yarn build
```

Expand Down
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ fail() {
exit 1
}

# Check for secrets that should not be committed
/bin/bash ./git-secrets-scan.sh

# Verify dependencies before starting the build
/bin/bash ./scripts/check-prerequisites.sh

# Prepare for build with references
/bin/bash scripts/generate-aggregate-tsconfig.sh > tsconfig.json

Expand Down
174 changes: 174 additions & 0 deletions scripts/check-prerequisites.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#!/bin/bash
set -euo pipefail

# 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; }

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
}

# [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

# [Java OpenJDK 8, 11, 14]

# Follow "More Info" on a new Mac when trying javac, install latest Oracle:
# javac 14.0.1

# apt install default-jdk on Ubuntu
# javac 11.0.7

# Install Coretto 8 from Amazon web site
# javac --version fails
# javac -version
# javac 1.8.0_252
# Old javac versions output version to stderr... why

app="javac"
app_min="1.8.0"
check_which $app $app_min
app_v=$(${app} -version 2>&1)
echo -e "Checking javac version... \c"
# 1.8
if [ $(echo $app_v | grep -c -E "1\.8\.[0-9].*") -eq 1 ]
then
echo "Ok"
else
# 11 or 14
if [ $(echo $app_v | grep -c -E "1[14]\.[0-9]\.[0-9].*") -eq 1 ]
then
echo "Ok"
else
wrong_version
fi
fi

# [Apache Maven >= 3.6.0, < 4.0]
app="mvn"
app_min="3.6.0"
check_which $app $app_min
app_v=$(${app} --version)
echo -e "Checking mvn version... \c"
if [ $(echo $app_v | grep -c -E "3\.[6789]\.[0-9].*") -eq 1 ]
then
echo "Ok"
else
wrong_version
fi

# [.NET Core SDK 3.1.*]
app="dotnet"
app_min="3.1.0"
check_which $app $app_min
app_v=$(${app} --version)
echo -e "Checking $app version... \c"
if [ $(echo $app_v | grep -c -E "3\.1\.[0-9].*") -eq 1 ]
then
echo "Ok"
else
wrong_version
fi

# [Python >= 3.6.5, < 4.0]
app="python3"
app_min="3.6.5"
check_which $app $app_min
app_v=$(${app} --version)
echo -e "Checking $app version... \c"
if [ $(echo $app_v | grep -c -E "3\.[6789]\.[0-9].*") -eq 1 ]
then
echo "Ok"
else
wrong_version
fi

# [Ruby >= 2.5.1, < 3.0]
app="ruby"
app_min="2.5.1"
check_which $app $app_min
app_v=$(${app} --version)
echo -e "Checking $app version... \c"
if [ $(echo $app_v | grep -c -E "2\.[56789]\.[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

0 comments on commit a9ae6da

Please sign in to comment.