diff --git a/aio/aio-builds-setup/docs/NOTES.md b/aio/aio-builds-setup/docs/NOTES.md index a5debd8c25..59c8d68de8 100644 --- a/aio/aio-builds-setup/docs/NOTES.md +++ b/aio/aio-builds-setup/docs/NOTES.md @@ -28,3 +28,5 @@ - Do we care to keep logs (e.g. cron, nginx, aio-upload-server, aio-clean-up, pm2) outside of the container? - Instead of creating new comments for each commit, update the original comment? - Do we want to drop HTTP support (and/or redirect to HTTPS)? +- When re-running a Travis job build that has previous succeeded for AIO, it will not be able to + deploy and fail. diff --git a/aio/scripts/deploy-preview.sh b/aio/scripts/deploy-preview.sh index dd49776973..9d8f383793 100755 --- a/aio/scripts/deploy-preview.sh +++ b/aio/scripts/deploy-preview.sh @@ -6,10 +6,26 @@ set -eux -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" . -curl -iLX POST --header "Authorization: Token $NGBUILDS_IO_KEY" --data-binary "@$OUTPUT_FILE" \ - "$AIO_BUILDS_HOST/create-build/$TRAVIS_PULL_REQUEST/$TRAVIS_COMMIT" + +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 -