angular/aio/scripts/deploy-preview.sh
Georgios Kalpakas fd34a58e13 fix(aio): ensure NGBUILDS_IO_KEY is not printed
Gaining access to another PR's JWT, would allow faking that PR's author wrt to
GitHub team membership verification for as long as the JWT is valid (currently
90 mins).
2017-03-07 18:24:45 -08:00

33 lines
809 B
Bash
Executable File

#!/usr/bin/env bash
# WARNING: NGBUILDS_IO_KEY should NOT be printed.
set +x -eu -o pipefail
INPUT_DIR=dist/
OUTPUT_FILE=/tmp/snapshot.tar.gz
AIO_BUILDS_HOST=https://ngbuilds.io
UPLOAD_URL=$AIO_BUILDS_HOST/create-build/$TRAVIS_PULL_REQUEST/$TRAVIS_PULL_REQUEST_SHA
cd "`dirname $0`/.."
yarn run build -- --prod
tar --create --gzip --directory "$INPUT_DIR" --file "$OUTPUT_FILE" .
exec 3>&1
httpCode=$(
curl --include --location --request POST --silent --write-out "\nHTTP_CODE: %{http_code}\n" \
--header "Authorization: Token $NGBUILDS_IO_KEY" --data-binary "@$OUTPUT_FILE" "$UPLOAD_URL" \
| sed 's/\r\n/\n/' \
| tee /dev/fd/3 \
| tail -1 \
| sed 's/HTTP_CODE: //'
)
# Exit with an error if the request failed
if [ $httpCode -lt 200 ] || [ $httpCode -ge 400 ]; then
exit 1
fi
cd -