build: use subshells when changing directories

This prevents being left in the wrong directory in case of error.
This commit is contained in:
Georgios Kalpakas 2017-05-12 22:07:51 +03:00 committed by Igor Minar
parent 21d213dfc7
commit 06264645fd
7 changed files with 114 additions and 109 deletions

View File

@ -5,7 +5,8 @@ set -eux -o pipefail
source "`dirname $0`/_env.sh" source "`dirname $0`/_env.sh"
# Test `scripts-js/` # Test `scripts-js/`
cd "$SCRIPTS_JS_DIR" (
yarn install cd "$SCRIPTS_JS_DIR"
yarn test yarn install
cd - yarn test
)

View File

@ -5,10 +5,11 @@ set -eux -o pipefail
source "`dirname $0`/_env.sh" source "`dirname $0`/_env.sh"
# Build `scripts-js/` # Build `scripts-js/`
cd "$SCRIPTS_JS_DIR" (
yarn install cd "$SCRIPTS_JS_DIR"
yarn build yarn install
cd - yarn build
)
# Preverify PR # Preverify PR
AIO_GITHUB_ORGANIZATION="angular" \ AIO_GITHUB_ORGANIZATION="angular" \

View File

@ -15,59 +15,59 @@ readonly PREVERIFY_SCRIPT=aio-builds-setup/scripts/travis-preverify-pr.sh
readonly skipBuild=$([[ "$1" == "--skip-build" ]] && echo "true" || echo ""); readonly skipBuild=$([[ "$1" == "--skip-build" ]] && echo "true" || echo "");
readonly relevantChangedFilesCount=$(git diff --name-only $TRAVIS_COMMIT_RANGE | grep -P "^(?:aio|packages)/(?!.*[._]spec\.[jt]s$)" | wc -l) readonly relevantChangedFilesCount=$(git diff --name-only $TRAVIS_COMMIT_RANGE | grep -P "^(?:aio|packages)/(?!.*[._]spec\.[jt]s$)" | wc -l)
cd "`dirname $0`/.." (
cd "`dirname $0`/.."
# Do not deploy unless this PR has touched relevant files: `aio/` or `packages/` (except for spec files) # Do not deploy unless this PR has touched relevant files: `aio/` or `packages/` (except for spec files)
if [[ $relevantChangedFilesCount -eq 0 ]]; then if [[ $relevantChangedFilesCount -eq 0 ]]; then
echo "Skipping deploy because this PR did not touch any relevant files." echo "Skipping deploy because this PR did not touch any relevant files."
exit 0
fi
# Do not deploy unless this PR meets certain preconditions.
readonly preverifyExitCode=$($PREVERIFY_SCRIPT > /dev/fd/3 && echo 0 || echo $?)
case $preverifyExitCode in
0)
# Preconditions met: Deploy
;;
1)
# An error occurred: Fail the script
exit 1
;;
2)
# Preconditions not met: Skip deploy
echo "Skipping deploy because this PR did not meet the preconditions."
exit 0 exit 0
;; fi
*)
# Unexpected exit code: Fail the script # Do not deploy unless this PR meets certain preconditions.
echo "Unexpected pre-verification exit code: $preverifyExitCode" readonly preverifyExitCode=$($PREVERIFY_SCRIPT > /dev/fd/3 && echo 0 || echo $?)
case $preverifyExitCode in
0)
# Preconditions met: Deploy
;;
1)
# An error occurred: Fail the script
exit 1
;;
2)
# Preconditions not met: Skip deploy
echo "Skipping deploy because this PR did not meet the preconditions."
exit 0
;;
*)
# Unexpected exit code: Fail the script
echo "Unexpected pre-verification exit code: $preverifyExitCode"
exit 1
;;
esac
# Build the app
if [ "$skipBuild" != "true" ]; then
yarn build
fi
tar --create --gzip --directory "$INPUT_DIR" --file "$OUTPUT_FILE" .
# Deploy to staging
readonly 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.
# (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
exit 1 exit 1
;; fi
esac
# Build the app # Run PWA-score tests
if [ "$skipBuild" != "true" ]; then yarn test-pwa-score -- "$DEPLOYED_URL" "$MIN_PWA_SCORE"
yarn build
fi
tar --create --gzip --directory "$INPUT_DIR" --file "$OUTPUT_FILE" .
# Deploy to staging
readonly 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.
# (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
exit 1
fi
# Run PWA-score tests
yarn test-pwa-score -- "$DEPLOYED_URL" "$MIN_PWA_SCORE"
cd -

View File

@ -7,18 +7,18 @@ set +x -eu -o pipefail
FIREBASE_PROJECT_ID=aio-staging FIREBASE_PROJECT_ID=aio-staging
DEPLOYED_URL=https://$FIREBASE_PROJECT_ID.firebaseapp.com DEPLOYED_URL=https://$FIREBASE_PROJECT_ID.firebaseapp.com
cd "`dirname $0`/.." (
cd "`dirname $0`/.."
# Build the app # Build the app
yarn build yarn build
# Deploy to staging # Deploy to staging
firebase use "$FIREBASE_PROJECT_ID" --token "$FIREBASE_TOKEN" firebase use "$FIREBASE_PROJECT_ID" --token "$FIREBASE_TOKEN"
firebase deploy --message "Commit: $TRAVIS_COMMIT" --non-interactive --token "$FIREBASE_TOKEN" firebase deploy --message "Commit: $TRAVIS_COMMIT" --non-interactive --token "$FIREBASE_TOKEN"
# Run PWA-score tests # Run PWA-score tests
# TODO(gkalpak): Figure out why this fails and re-enable. # TODO(gkalpak): Figure out why this fails and re-enable.
sleep 10 sleep 10
yarn test-pwa-score -- "$DEPLOYED_URL" "$MIN_PWA_SCORE" || true yarn test-pwa-score -- "$DEPLOYED_URL" "$MIN_PWA_SCORE" || true
)
cd -

View File

@ -362,38 +362,40 @@ if [[ ${BUILD_ALL} == true && ${TYPECHECK_ALL} == true ]]; then
travisFoldStart "copy e2e files" "no-xtrace" travisFoldStart "copy e2e files" "no-xtrace"
mkdir -p ./dist/all/ mkdir -p ./dist/all/
echo "====== Copying files needed for e2e tests =====" (
cp -r ./modules/playground ./dist/all/ echo "====== Copying files needed for e2e tests ====="
cp -r ./modules/playground/favicon.ico ./dist/ cp -r ./modules/playground ./dist/all/
#rsync -aP ./modules/playground/* ./dist/all/playground/ cp -r ./modules/playground/favicon.ico ./dist/
mkdir ./dist/all/playground/vendor #rsync -aP ./modules/playground/* ./dist/all/playground/
cd ./dist/all/playground/vendor mkdir ./dist/all/playground/vendor
ln -s ../../../../node_modules/core-js/client/core.js . cd ./dist/all/playground/vendor
ln -s ../../../../node_modules/zone.js/dist/zone.js . ln -s ../../../../node_modules/core-js/client/core.js .
ln -s ../../../../node_modules/zone.js/dist/long-stack-trace-zone.js . ln -s ../../../../node_modules/zone.js/dist/zone.js .
ln -s ../../../../node_modules/systemjs/dist/system.src.js . ln -s ../../../../node_modules/zone.js/dist/long-stack-trace-zone.js .
ln -s ../../../../node_modules/base64-js . ln -s ../../../../node_modules/systemjs/dist/system.src.js .
ln -s ../../../../node_modules/reflect-metadata/Reflect.js . ln -s ../../../../node_modules/base64-js .
ln -s ../../../../node_modules/rxjs . ln -s ../../../../node_modules/reflect-metadata/Reflect.js .
ln -s ../../../../node_modules/angular/angular.js . ln -s ../../../../node_modules/rxjs .
ln -s ../../../../node_modules/hammerjs/hammer.js . ln -s ../../../../node_modules/angular/angular.js .
cd - ln -s ../../../../node_modules/hammerjs/hammer.js .
)
echo "====== Copying files needed for benchmarks =====" (
cp -r ./modules/benchmarks ./dist/all/ echo "====== Copying files needed for benchmarks ====="
cp -r ./modules/benchmarks/favicon.ico ./dist/ cp -r ./modules/benchmarks ./dist/all/
mkdir ./dist/all/benchmarks/vendor cp -r ./modules/benchmarks/favicon.ico ./dist/
cd ./dist/all/benchmarks/vendor mkdir ./dist/all/benchmarks/vendor
ln -s ../../../../node_modules/core-js/client/core.js . cd ./dist/all/benchmarks/vendor
ln -s ../../../../node_modules/zone.js/dist/zone.js . ln -s ../../../../node_modules/core-js/client/core.js .
ln -s ../../../../node_modules/zone.js/dist/long-stack-trace-zone.js . ln -s ../../../../node_modules/zone.js/dist/zone.js .
ln -s ../../../../node_modules/systemjs/dist/system.src.js . ln -s ../../../../node_modules/zone.js/dist/long-stack-trace-zone.js .
ln -s ../../../../node_modules/reflect-metadata/Reflect.js . ln -s ../../../../node_modules/systemjs/dist/system.src.js .
ln -s ../../../../node_modules/rxjs . ln -s ../../../../node_modules/reflect-metadata/Reflect.js .
ln -s ../../../../node_modules/angular/angular.js . ln -s ../../../../node_modules/rxjs .
ln -s ../../../../bower_components/polymer . ln -s ../../../../node_modules/angular/angular.js .
ln -s ../../../../node_modules/incremental-dom/dist/incremental-dom-cjs.js ln -s ../../../../bower_components/polymer .
cd - ln -s ../../../../node_modules/incremental-dom/dist/incremental-dom-cjs.js
)
travisFoldEnd "copy e2e files" travisFoldEnd "copy e2e files"
TSCONFIG="packages/tsconfig.json" TSCONFIG="packages/tsconfig.json"

View File

@ -40,6 +40,7 @@ travisFoldEnd "tsc a bunch of useless stuff"
# Build angular.io # Build angular.io
if [[ ${CI_MODE:-} == "aio" ]]; then if [[ ${CI_MODE:-} == "aio" ]]; then
travisFoldStart "build.aio" travisFoldStart "build.aio"
(
cd "`dirname $0`/../../aio" cd "`dirname $0`/../../aio"
yarn build yarn build
@ -52,7 +53,6 @@ if [[ ${CI_MODE:-} == "aio" ]]; then
yarn deploy-preview -- --skip-build yarn deploy-preview -- --skip-build
travisFoldEnd "deploy.aio.pr-preview" travisFoldEnd "deploy.aio.pr-preview"
fi fi
)
cd -
travisFoldEnd "build.aio" travisFoldEnd "build.aio"
fi fi

View File

@ -30,11 +30,12 @@ function prepare {
if [ -d "$REPO_DIR" ]; then if [ -d "$REPO_DIR" ]; then
cd $REPO_DIR (
git fetch --update-shallow origin cd $REPO_DIR
git checkout master git fetch --update-shallow origin
git merge --ff-only origin/master git checkout master
cd - git merge --ff-only origin/master
)
else else
echo "-- Cloning code.angularjs.org into $REPO_DIR" echo "-- Cloning code.angularjs.org into $REPO_DIR"
git clone git@github.com:angular/code.angularjs.org.git $REPO_DIR --depth=1 git clone git@github.com:angular/code.angularjs.org.git $REPO_DIR --depth=1