build: use CI-provider independent variable names (#26377)

PR Close #26377
This commit is contained in:
George Kalpakas
2018-10-17 19:19:15 +03:00
committed by Alex Rickabaugh
parent b647608c96
commit 3b24e0edb6
10 changed files with 121 additions and 96 deletions

View File

@ -2,13 +2,12 @@
set -eu -o pipefail
source "`dirname $0`/../../scripts/ci/env.sh" print
readonly INPUT_DIR=dist/
readonly OUTPUT_FILE=$PROJECT_ROOT/$1
readonly PR_NUMBER=$2
readonly PR_LAST_SHA=$3
readonly deployedUrl=https://pr${PR_NUMBER}-${PR_LAST_SHA:0:7}.ngbuilds.io/
readonly relativeOutputPath=$1
readonly prNumber=$2
readonly prLastSha=$3
readonly inputDir=dist/
readonly outputFile=$PROJECT_ROOT/$relativeOutputPath
readonly deployedUrl=https://pr${prNumber}-${prLastSha:0:7}.ngbuilds.io/
(
cd $PROJECT_ROOT/aio
@ -20,6 +19,6 @@ readonly deployedUrl=https://pr${PR_NUMBER}-${PR_LAST_SHA:0:7}.ngbuilds.io/
# deployedUrl must end with /
yarn set-opensearch-url $deployedUrl
mkdir -p "`dirname $OUTPUT_FILE`"
tar --create --gzip --directory "$INPUT_DIR" --file "$OUTPUT_FILE" .
mkdir -p "`dirname $outputFile`"
tar --create --gzip --directory "$inputDir" --file "$outputFile" .
)

View File

@ -1,35 +1,35 @@
#!/usr/bin/env bash
# WARNING: FIREBASE_TOKEN should NOT be printed.
# WARNING: CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN should NOT be printed.
set +x -eu -o pipefail
# Only deploy if this not a PR. PRs are deployed early in `build.sh`.
if [[ $TRAVIS_PULL_REQUEST != "false" ]]; then
if [[ $CI_PULL_REQUEST != "false" ]]; then
echo "Skipping deploy because this is a PR build."
exit 0
fi
# Do not deploy if the current commit is not the latest on its branch.
readonly LATEST_COMMIT=$(git ls-remote origin $TRAVIS_BRANCH | cut -c1-40)
if [[ $TRAVIS_COMMIT != $LATEST_COMMIT ]]; then
echo "Skipping deploy because $TRAVIS_COMMIT is not the latest commit ($LATEST_COMMIT)."
readonly LATEST_COMMIT=$(git ls-remote origin $CI_BRANCH | cut -c1-40)
if [[ $CI_COMMIT != $LATEST_COMMIT ]]; then
echo "Skipping deploy because $CI_COMMIT is not the latest commit ($LATEST_COMMIT)."
exit 0
fi
# The deployment mode is computed based on the branch we are building
if [[ $TRAVIS_BRANCH == master ]]; then
if [[ $CI_BRANCH == master ]]; then
readonly deployEnv=next
elif [[ $TRAVIS_BRANCH == $STABLE_BRANCH ]]; then
elif [[ $CI_BRANCH == $STABLE_BRANCH ]]; then
readonly deployEnv=stable
else
# Extract the major versions from the branches, e.g. the 4 from 4.3.x
readonly majorVersion=${TRAVIS_BRANCH%%.*}
readonly majorVersion=${CI_BRANCH%%.*}
readonly majorVersionStable=${STABLE_BRANCH%%.*}
# Do not deploy if the major version is not less than the stable branch major version
if [[ !( "$majorVersion" < "$majorVersionStable" ) ]]; then
echo "Skipping deploy of branch \"${TRAVIS_BRANCH}\" to firebase."
echo "We only deploy archive branches with the major version less than the stable branch: \"${STABLE_BRANCH}\""
echo "Skipping deploy of branch \"$CI_BRANCH\" to firebase."
echo "We only deploy archive branches with the major version less than the stable branch: \"$STABLE_BRANCH\""
exit 0
fi
@ -46,9 +46,9 @@ else
)
# Do not deploy as it is not the latest branch for the given major version
if [[ $TRAVIS_BRANCH != $mostRecentMinorVersion ]]; then
echo "Skipping deploy of branch \"${TRAVIS_BRANCH}\" to firebase."
echo "There is a more recent branch with the same major version: \"${mostRecentMinorVersion}\""
if [[ $CI_BRANCH != $mostRecentMinorVersion ]]; then
echo "Skipping deploy of branch \"$CI_BRANCH\" to firebase."
echo "There is a more recent branch with the same major version: \"$mostRecentMinorVersion\""
exit 0
fi
@ -59,21 +59,21 @@ case $deployEnv in
next)
readonly projectId=aio-staging
readonly deployedUrl=https://next.angular.io/
readonly firebaseToken=$FIREBASE_TOKEN
readonly firebaseToken=$CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN
;;
stable)
readonly projectId=angular-io
readonly deployedUrl=https://angular.io/
readonly firebaseToken=$FIREBASE_TOKEN
readonly firebaseToken=$CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN
;;
archive)
readonly projectId=v${majorVersion}-angular-io
readonly deployedUrl=https://v${majorVersion}.angular.io/
readonly firebaseToken=$FIREBASE_TOKEN
readonly firebaseToken=$CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN
;;
esac
echo "Git branch : $TRAVIS_BRANCH"
echo "Git branch : $CI_BRANCH"
echo "Build/deploy mode : $deployEnv"
echo "Firebase project : $projectId"
echo "Deployment URL : $deployedUrl"
@ -101,8 +101,8 @@ fi
# Deploy to Firebase
firebase use "$projectId" --token "$firebaseToken"
firebase deploy --message "Commit: $TRAVIS_COMMIT" --non-interactive --token "$firebaseToken"
firebase deploy --message "Commit: $CI_COMMIT" --non-interactive --token "$firebaseToken"
# Run PWA-score tests
yarn test-pwa-score "$deployedUrl" "$AIO_MIN_PWA_SCORE"
yarn test-pwa-score "$deployedUrl" "$CI_AIO_MIN_PWA_SCORE"
)

View File

@ -17,7 +17,7 @@ function check {
(
echo ===== master - skip deploy - pull request
actual=$(
export TRAVIS_PULL_REQUEST=true
export CI_PULL_REQUEST=true
`dirname $0`/deploy-to-firebase.sh --dry-run
)
expected="Skipping deploy because this is a PR build."
@ -27,10 +27,10 @@ function check {
(
echo ===== master - deploy success
actual=$(
export TRAVIS_PULL_REQUEST=false
export TRAVIS_BRANCH=master
export TRAVIS_COMMIT=$(git ls-remote origin master | cut -c-40)
export FIREBASE_TOKEN=XXXXX
export CI_PULL_REQUEST=false
export CI_BRANCH=master
export CI_COMMIT=$(git ls-remote origin master | cut -c-40)
export CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN=XXXXX
`dirname $0`/deploy-to-firebase.sh --dry-run
)
expected="Git branch : master
@ -43,9 +43,9 @@ Deployment URL : https://next.angular.io/"
(
echo ===== master - skip deploy - commit not HEAD
actual=$(
export TRAVIS_PULL_REQUEST=false
export TRAVIS_BRANCH=master
export TRAVIS_COMMIT=DUMMY_TEST_COMMIT
export CI_PULL_REQUEST=false
export CI_BRANCH=master
export CI_COMMIT=DUMMY_TEST_COMMIT
`dirname $0`/deploy-to-firebase.sh --dry-run
)
expected="Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ($(git ls-remote origin master | cut -c1-40))."
@ -55,11 +55,11 @@ Deployment URL : https://next.angular.io/"
(
echo ===== stable - deploy success
actual=$(
export TRAVIS_PULL_REQUEST=false
export TRAVIS_BRANCH=4.3.x
export CI_PULL_REQUEST=false
export CI_BRANCH=4.3.x
export STABLE_BRANCH=4.3.x
export TRAVIS_COMMIT=$(git ls-remote origin 4.3.x | cut -c-40)
export FIREBASE_TOKEN=XXXXX
export CI_COMMIT=$(git ls-remote origin 4.3.x | cut -c-40)
export CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN=XXXXX
`dirname $0`/deploy-to-firebase.sh --dry-run
)
expected="Git branch : 4.3.x
@ -72,10 +72,10 @@ Deployment URL : https://angular.io/"
(
echo ===== stable - skip deploy - commit not HEAD
actual=$(
export TRAVIS_PULL_REQUEST=false
export TRAVIS_BRANCH=4.3.x
export CI_PULL_REQUEST=false
export CI_BRANCH=4.3.x
export STABLE_BRANCH=4.3.x
export TRAVIS_COMMIT=DUMMY_TEST_COMMIT
export CI_COMMIT=DUMMY_TEST_COMMIT
`dirname $0`/deploy-to-firebase.sh --dry-run
)
expected="Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ($(git ls-remote origin 4.3.x | cut -c1-40))."
@ -85,11 +85,11 @@ Deployment URL : https://angular.io/"
(
echo ===== archive - deploy success
actual=$(
export TRAVIS_PULL_REQUEST=false
export TRAVIS_BRANCH=2.4.x
export CI_PULL_REQUEST=false
export CI_BRANCH=2.4.x
export STABLE_BRANCH=4.3.x
export TRAVIS_COMMIT=$(git ls-remote origin 2.4.x | cut -c-40)
export FIREBASE_TOKEN=XXXXX
export CI_COMMIT=$(git ls-remote origin 2.4.x | cut -c-40)
export CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN=XXXXX
`dirname $0`/deploy-to-firebase.sh --dry-run
)
expected="Git branch : 2.4.x
@ -102,11 +102,11 @@ Deployment URL : https://v2.angular.io/"
(
echo ===== archive - skip deploy - commit not HEAD
actual=$(
export TRAVIS_PULL_REQUEST=false
export TRAVIS_BRANCH=2.4.x
export CI_PULL_REQUEST=false
export CI_BRANCH=2.4.x
export STABLE_BRANCH=4.3.x
export TRAVIS_COMMIT=DUMMY_TEST_COMMIT
export FIREBASE_TOKEN=XXXXX
export CI_COMMIT=DUMMY_TEST_COMMIT
export CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN=XXXXX
`dirname $0`/deploy-to-firebase.sh --dry-run
)
expected="Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ($(git ls-remote origin 2.4.x | cut -c1-40))."
@ -116,11 +116,11 @@ Deployment URL : https://v2.angular.io/"
(
echo ===== archive - skip deploy - major version too high, lower minor
actual=$(
export TRAVIS_PULL_REQUEST=false
export TRAVIS_BRANCH=2.1.x
export CI_PULL_REQUEST=false
export CI_BRANCH=2.1.x
export STABLE_BRANCH=2.2.x
export TRAVIS_COMMIT=$(git ls-remote origin 2.1.x | cut -c-40)
export FIREBASE_TOKEN=XXXXX
export CI_COMMIT=$(git ls-remote origin 2.1.x | cut -c-40)
export CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN=XXXXX
`dirname $0`/deploy-to-firebase.sh --dry-run
)
expected="Skipping deploy of branch \"2.1.x\" to firebase.
@ -131,11 +131,11 @@ We only deploy archive branches with the major version less than the stable bran
(
echo ===== archive - skip deploy - major version too high, higher minor
actual=$(
export TRAVIS_PULL_REQUEST=false
export TRAVIS_BRANCH=2.4.x
export CI_PULL_REQUEST=false
export CI_BRANCH=2.4.x
export STABLE_BRANCH=2.2.x
export TRAVIS_COMMIT=$(git ls-remote origin 2.4.x | cut -c-40)
export FIREBASE_TOKEN=XXXXX
export CI_COMMIT=$(git ls-remote origin 2.4.x | cut -c-40)
export CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN=XXXXX
`dirname $0`/deploy-to-firebase.sh --dry-run
)
expected="Skipping deploy of branch \"2.4.x\" to firebase.
@ -146,11 +146,11 @@ We only deploy archive branches with the major version less than the stable bran
(
echo ===== archive - skip deploy - minor version too low
actual=$(
export TRAVIS_PULL_REQUEST=false
export TRAVIS_BRANCH=2.1.x
export CI_PULL_REQUEST=false
export CI_BRANCH=2.1.x
export STABLE_BRANCH=4.3.x
export TRAVIS_COMMIT=$(git ls-remote origin 2.1.x | cut -c-40)
export FIREBASE_TOKEN=XXXXX
export CI_COMMIT=$(git ls-remote origin 2.1.x | cut -c-40)
export CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN=XXXXX
`dirname $0`/deploy-to-firebase.sh --dry-run
)
expected="Skipping deploy of branch \"2.1.x\" to firebase.