| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | #!/usr/bin/env bash
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:32:44 +02:00
										 |  |  | # WARNING: NGBUILDS_IO_KEY should NOT be printed. | 
					
						
							|  |  |  | set +x -eu -o pipefail | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | INPUT_DIR=dist/ | 
					
						
							|  |  |  | OUTPUT_FILE=/tmp/snapshot.tar.gz | 
					
						
							| 
									
										
										
										
											2017-04-01 02:24:25 +03:00
										 |  |  | AIO_BUILDS_DOMAIN=ngbuilds.io | 
					
						
							|  |  |  | UPLOAD_URL=https://$AIO_BUILDS_DOMAIN/create-build/$TRAVIS_PULL_REQUEST/$TRAVIS_PULL_REQUEST_SHA | 
					
						
							|  |  |  | DEPLOYED_URL=https://pr$TRAVIS_PULL_REQUEST-$TRAVIS_PULL_REQUEST_SHA.$AIO_BUILDS_DOMAIN | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | cd "`dirname $0`/.." | 
					
						
							| 
									
										
										
										
											2017-03-03 01:58:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-01 02:24:25 +03:00
										 |  |  | # Build the app | 
					
						
							|  |  |  | yarn build | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | tar --create --gzip --directory "$INPUT_DIR" --file "$OUTPUT_FILE" . | 
					
						
							| 
									
										
										
										
											2017-03-03 01:58:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-01 02:24:25 +03:00
										 |  |  | # Deploy to staging | 
					
						
							| 
									
										
										
										
											2017-03-03 01:58:31 +02:00
										 |  |  | 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: //' | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 00:38:21 +03:00
										 |  |  | # Exit with an error if the request failed. | 
					
						
							|  |  |  | # (Ignore 409 failures, which mean trying to re-deploy for the same PR/SHA.) | 
					
						
							|  |  |  | if [ $httpCode -lt 200 ] || ([ $httpCode -ge 400 ] && [ $httpCode -ne 409 ]); then | 
					
						
							| 
									
										
										
										
											2017-03-03 01:58:31 +02:00
										 |  |  |   exit 1 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-01 02:24:25 +03:00
										 |  |  | # Run PWA-score tests | 
					
						
							|  |  |  | yarn test-pwa-score -- "$DEPLOYED_URL" "$MIN_PWA_SCORE_PREVIEW" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | cd - |