|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -ex |
| 3 | + |
| 4 | +VERSION_FILE_PATH=$1 |
| 5 | +if [ ! readlink -e "$VERSION_FILE_PATH" ]; then |
| 6 | + echo "No VERSION file found! Cannot make release!" |
| 7 | + exit 1 |
| 8 | +else |
| 9 | + echo "VERSION file found..." |
| 10 | +fi |
| 11 | +VERSION=$(cat $VERSION_FILE_PATH) |
| 12 | + |
| 13 | +# Make sure the version variable is populated |
| 14 | +if [ -z "${VERSION}" ]; then |
| 15 | + echo "VERSION file is empty!" |
| 16 | + exit 1 |
| 17 | +else |
| 18 | + echo "VERSION file contains: ${VERSION}" |
| 19 | +fi |
| 20 | + |
| 21 | +# Make sure the version follows the correct format: major.minor.patch |
| 22 | +LENGTH_CHECK="${VERSION//[^.]}" |
| 23 | +if [ ${#LENGTH_CHECK} != 2 ]; then |
| 24 | + echo "VERSION file contains invalid version (not in format major.minor.patch)" |
| 25 | + exit 1 |
| 26 | +fi |
| 27 | +# Use RegX to ensure it only contains numbers and periods |
| 28 | +REGX_CHECK='^([0-9]+\.){0,2}(\*|[0-9]+)$' |
| 29 | +if [[ $VERSION =~ $REGX_CHECK ]]; then |
| 30 | + echo "VERSION file contains valid version" |
| 31 | +else |
| 32 | + echo "VERSION file contains invalid version (RegX validator failed)" |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | + |
| 36 | +PUBLISHED_TAG_VERSION=`npm show aws-iot-device-sdk-v2 version` |
| 37 | +if [ "$PUBLISHED_TAG_VERSION" == "$VERSION" ]; then |
| 38 | + echo "$VERSION found in npm. Testing release..." |
| 39 | + |
| 40 | + # install the Typescript and the SDK |
| 41 | + npm install -g typescript |
| 42 | + npm install |
| 43 | + |
| 44 | + # Move to the sample folder and get the endpoint |
| 45 | + cd samples/node/pub_sub |
| 46 | + ENDPOINT=$(aws secretsmanager get-secret-value --secret-id "ci/endpoint" --region us-east-1 --query "SecretString" | cut -f2 -d":" | sed -e 's/[\\\"\}]//g') |
| 47 | + |
| 48 | + # Run the sample! |
| 49 | + npm install |
| 50 | + node dist/index.js --endpoint $ENDPOINT --ca_file /tmp/AmazonRootCA1.pem --cert /tmp/certificate.pem --key /tmp/privatekey.pem |
| 51 | + |
| 52 | + exit 0 |
| 53 | + |
| 54 | +else |
| 55 | + echo "$VERSION was not found in npm. Release failed!" |
| 56 | +fi |
| 57 | + |
| 58 | +exit 1 |
0 commit comments