2015-11-09 18:25:00 -05:00
|
|
|
#!/bin/bash
|
|
|
|
set -e -x
|
|
|
|
|
|
|
|
|
2017-02-01 14:51:12 -05:00
|
|
|
# Find the most recent tag that is reachable from the current commit.
|
|
|
|
# This is shallow clone of the repo, so we might need to fetch more commits to
|
|
|
|
# find the tag.
|
|
|
|
function getLatestTag {
|
|
|
|
local depth=`git log --oneline | wc -l`
|
|
|
|
local latestTag=`git describe --tags --abbrev=0 || echo NOT_FOUND`
|
|
|
|
|
|
|
|
while [ "$latestTag" == "NOT_FOUND" ]; do
|
|
|
|
# Avoid infinite loop.
|
|
|
|
if [ "$depth" -gt "1000" ]; then
|
|
|
|
echo "Error: Unable to find the latest tag." 1>&2
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Increase the clone depth and look for a tag.
|
|
|
|
depth=$((depth + 50))
|
|
|
|
echo "Looking for latest tag at depth $depth..."
|
|
|
|
git fetch --depth=$depth
|
|
|
|
latestTag=`git describe --tags --abbrev=0 || echo NOT_FOUND`
|
|
|
|
done
|
|
|
|
|
|
|
|
echo $latestTag;
|
|
|
|
}
|
|
|
|
|
2015-11-09 18:25:00 -05:00
|
|
|
function publishRepo {
|
2016-05-09 20:26:51 -04:00
|
|
|
COMPONENT=$1
|
2015-11-09 18:25:00 -05:00
|
|
|
ARTIFACTS_DIR=$2
|
|
|
|
|
2016-05-09 20:26:51 -04:00
|
|
|
BUILD_REPO="${COMPONENT}-builds"
|
|
|
|
REPO_DIR="tmp/${BUILD_REPO}"
|
2015-11-09 18:25:00 -05:00
|
|
|
|
2016-12-15 14:19:21 -05:00
|
|
|
if [ -n "$CREATE_REPOS" ]; then
|
|
|
|
curl -u "$ORG:$TOKEN" https://api.github.com/user/repos \
|
|
|
|
-d '{"name":"'$BUILD_REPO'", "auto_init": true}'
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Pushing build artifacts to ${ORG}/${BUILD_REPO}"
|
2015-11-09 18:25:00 -05:00
|
|
|
|
|
|
|
# create local repo folder and clone build repo into it
|
|
|
|
rm -rf $REPO_DIR
|
|
|
|
mkdir -p $REPO_DIR
|
|
|
|
(
|
|
|
|
cd $REPO_DIR && \
|
|
|
|
git init && \
|
|
|
|
git remote add origin $REPO_URL && \
|
2016-12-20 17:52:50 -05:00
|
|
|
# use the remote branch if it exists
|
|
|
|
if git ls-remote --exit-code origin ${BRANCH}; then
|
|
|
|
git fetch origin ${BRANCH} --depth=1 && \
|
|
|
|
git checkout origin/${BRANCH}
|
|
|
|
fi
|
|
|
|
git checkout -b "${BRANCH}"
|
2015-11-09 18:25:00 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
# copy over build artifacts into the repo directory
|
|
|
|
rm -rf $REPO_DIR/*
|
|
|
|
cp -R $ARTIFACTS_DIR/* $REPO_DIR/
|
2016-05-25 18:37:40 -04:00
|
|
|
|
2016-12-20 17:52:50 -05:00
|
|
|
# Replace $$ANGULAR_VERSION$$ with the build version.
|
|
|
|
BUILD_VER="${LATEST_TAG}+${SHORT_SHA}"
|
2016-05-12 16:58:42 -04:00
|
|
|
if [[ ${TRAVIS} ]]; then
|
|
|
|
find $REPO_DIR/ -type f -name package.json -print0 | xargs -0 sed -i "s/\\\$\\\$ANGULAR_VERSION\\\$\\\$/${BUILD_VER}/g"
|
2016-08-31 21:58:59 -04:00
|
|
|
|
|
|
|
# Find umd.js and umd.min.js
|
|
|
|
UMD_FILES=$(find $REPO_DIR/ -type f -name "*.umd*.js" -print)
|
|
|
|
for UMD_FILE in ${UMD_FILES}; do
|
|
|
|
sed -i "s/\\\$\\\$ANGULAR_VERSION\\\$\\\$/${BUILD_VER}/g" ${UMD_FILE}
|
|
|
|
done
|
2016-12-15 14:19:21 -05:00
|
|
|
|
|
|
|
(
|
|
|
|
cd $REPO_DIR && \
|
|
|
|
git config credential.helper "store --file=.git/credentials" && \
|
|
|
|
echo "https://${GITHUB_TOKEN_ANGULAR}:@github.com" > .git/credentials
|
|
|
|
)
|
2016-05-12 16:58:42 -04:00
|
|
|
fi
|
2015-11-09 18:25:00 -05:00
|
|
|
echo `date` > $REPO_DIR/BUILD_INFO
|
|
|
|
echo $SHA >> $REPO_DIR/BUILD_INFO
|
|
|
|
|
|
|
|
(
|
|
|
|
cd $REPO_DIR && \
|
2015-11-16 21:14:14 -05:00
|
|
|
git config user.name "${COMMITTER_USER_NAME}" && \
|
|
|
|
git config user.email "${COMMITTER_USER_EMAIL}" && \
|
2015-11-17 17:56:51 -05:00
|
|
|
git add --all && \
|
|
|
|
git commit -m "${COMMIT_MSG}" && \
|
2016-05-09 20:26:51 -04:00
|
|
|
git tag "${BUILD_VER}" && \
|
2016-12-20 17:52:50 -05:00
|
|
|
git push origin "${BRANCH}" --tags --force
|
2015-11-09 18:25:00 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-05-09 20:26:51 -04:00
|
|
|
# Publish all individual packages from packages-dist.
|
2016-12-15 14:19:21 -05:00
|
|
|
function publishPackages {
|
2017-01-19 17:25:44 -05:00
|
|
|
GIT_SCHEME=$1
|
|
|
|
PKGS_DIST=$2
|
|
|
|
BRANCH=$3
|
|
|
|
|
2017-01-12 20:35:02 -05:00
|
|
|
for dir in $PKGS_DIST/*/ dist/tools/@angular/tsc-wrapped
|
2016-05-09 20:26:51 -04:00
|
|
|
do
|
|
|
|
COMPONENT="$(basename ${dir})"
|
2016-03-04 22:16:12 -05:00
|
|
|
|
2016-05-09 20:26:51 -04:00
|
|
|
# Replace _ with - in component name.
|
|
|
|
COMPONENT="${COMPONENT//_/-}"
|
|
|
|
JS_BUILD_ARTIFACTS_DIR="${dir}"
|
2016-03-04 22:16:12 -05:00
|
|
|
|
2017-01-19 17:25:44 -05:00
|
|
|
if [[ "$GIT_SCHEME" == "ssh" ]]; then
|
2016-12-15 14:19:21 -05:00
|
|
|
REPO_URL="git@github.com:${ORG}/${COMPONENT}-builds.git"
|
2017-01-19 17:25:44 -05:00
|
|
|
elif [[ "$GIT_SCHEME" == "http" ]]; then
|
2016-12-15 14:19:21 -05:00
|
|
|
REPO_URL="https://github.com/${ORG}/${COMPONENT}-builds.git"
|
|
|
|
else
|
2017-01-19 17:25:44 -05:00
|
|
|
die "Don't have a way to publish to scheme $GIT_SCHEME"
|
2016-12-15 14:19:21 -05:00
|
|
|
fi
|
2016-05-09 20:26:51 -04:00
|
|
|
SHA=`git rev-parse HEAD`
|
|
|
|
SHORT_SHA=`git rev-parse --short HEAD`
|
|
|
|
COMMIT_MSG=`git log --oneline | head -n1`
|
|
|
|
COMMITTER_USER_NAME=`git --no-pager show -s --format='%cN' HEAD`
|
|
|
|
COMMITTER_USER_EMAIL=`git --no-pager show -s --format='%cE' HEAD`
|
2017-02-01 14:51:12 -05:00
|
|
|
LATEST_TAG=`getLatestTag`
|
2016-03-04 22:16:12 -05:00
|
|
|
|
2016-05-09 20:26:51 -04:00
|
|
|
publishRepo "${COMPONENT}" "${JS_BUILD_ARTIFACTS_DIR}"
|
|
|
|
done
|
2015-11-18 01:56:41 -05:00
|
|
|
|
2015-11-09 18:25:00 -05:00
|
|
|
echo "Finished publishing build artifacts"
|
2016-12-15 14:19:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
# See DEVELOPER.md for help
|
2017-01-19 17:25:44 -05:00
|
|
|
CUR_BRANCH=${TRAVIS_BRANCH:-$(git symbolic-ref --short HEAD)}
|
2016-12-15 14:19:21 -05:00
|
|
|
if [ $# -gt 0 ]; then
|
|
|
|
ORG=$1
|
2017-01-19 17:25:44 -05:00
|
|
|
publishPackages "ssh" dist/packages-dist $CUR_BRANCH
|
|
|
|
if [[ -e dist/packages-dist-es2015 ]]; then
|
|
|
|
publishPackages "ssh" dist/packages-dist-es2015 ${CUR_BRANCH}-es2015
|
|
|
|
fi
|
|
|
|
|
2016-12-15 14:19:21 -05:00
|
|
|
elif [[ \
|
|
|
|
"$TRAVIS_REPO_SLUG" == "angular/angular" && \
|
|
|
|
"$TRAVIS_PULL_REQUEST" == "false" && \
|
|
|
|
"$CI_MODE" == "e2e" ]]; then
|
|
|
|
ORG="angular"
|
2017-01-19 17:25:44 -05:00
|
|
|
publishPackages "http" dist/packages-dist $CUR_BRANCH
|
|
|
|
if [[ -e dist/packages-dist-es2015 ]]; then
|
|
|
|
publishPackages "http" dist/packages-dist-es2015 ${CUR_BRANCH}-es2015
|
|
|
|
fi
|
|
|
|
|
2016-03-04 22:16:12 -05:00
|
|
|
else
|
2017-01-19 17:25:44 -05:00
|
|
|
echo "Not building the upstream/${CUR_BRANCH} branch, build artifacts won't be published."
|
2015-11-09 18:25:00 -05:00
|
|
|
fi
|