2017-03-05 04:49:10 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2017-03-05 14:43:25 -05:00
|
|
|
set -x -u -e -o pipefail
|
2017-03-05 04:49:10 -05:00
|
|
|
|
|
|
|
# Setup environment
|
|
|
|
readonly thisDir=$(cd $(dirname $0); pwd)
|
2015-11-09 18:25:00 -05:00
|
|
|
|
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))
|
|
|
|
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
|
|
|
|
2017-03-06 21:03:38 -05:00
|
|
|
if [ -n "${CREATE_REPOS:-}" ]; then
|
2016-12-15 14:19:21 -05:00
|
|
|
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
|
|
|
|
2018-04-23 14:46:02 -04:00
|
|
|
if [[ ${CI} ]]; then
|
2016-12-15 14:19:21 -05:00
|
|
|
(
|
2018-04-27 19:21:38 -04:00
|
|
|
# The file ~/.git_credentials is created in /.circleci/config.yml
|
2016-12-15 14:19:21 -05:00
|
|
|
cd $REPO_DIR && \
|
2018-04-23 14:46:02 -04:00
|
|
|
git config credential.helper "store --file=$HOME/.git_credentials"
|
2016-12-15 14:19:21 -05:00
|
|
|
)
|
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 && \
|
2017-08-24 15:49:58 -04:00
|
|
|
git commit -m "${COMMIT_MSG}" --quiet && \
|
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
|
2018-09-28 09:11:07 -04:00
|
|
|
BUILD_VER=$4
|
2017-01-19 17:25:44 -05:00
|
|
|
|
2017-08-24 15:49:58 -04:00
|
|
|
for dir in $PKGS_DIST/*/
|
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-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
|
|
|
}
|
|
|
|
|
2018-06-05 14:38:46 -04:00
|
|
|
function publishAllBuilds() {
|
|
|
|
GIT_SCHEME="$1"
|
|
|
|
|
2018-09-28 09:11:07 -04:00
|
|
|
SHA=`git rev-parse HEAD`
|
|
|
|
COMMIT_MSG=`git log --oneline -1`
|
|
|
|
COMMITTER_USER_NAME=`git --no-pager show -s --format='%cN' HEAD`
|
|
|
|
COMMITTER_USER_EMAIL=`git --no-pager show -s --format='%cE' HEAD`
|
|
|
|
|
|
|
|
local shortSha=`git rev-parse --short HEAD`
|
|
|
|
local latestTag=`getLatestTag`
|
|
|
|
|
|
|
|
publishPackages $GIT_SCHEME dist/packages-dist $CUR_BRANCH "${latestTag}+${shortSha}"
|
|
|
|
publishPackages $GIT_SCHEME dist/packages-dist-ivy-jit "${CUR_BRANCH}-ivy-jit" "${latestTag}-ivy-jit+${shortSha}"
|
|
|
|
publishPackages $GIT_SCHEME dist/packages-dist-ivy-local "${CUR_BRANCH}-ivy-aot" "${latestTag}-ivy-aot+${shortSha}"
|
2018-06-05 14:38:46 -04:00
|
|
|
}
|
|
|
|
|
2017-03-23 01:50:12 -04:00
|
|
|
# See docs/DEVELOPER.md for help
|
2018-04-23 14:46:02 -04:00
|
|
|
CUR_BRANCH=${CIRCLE_BRANCH:-$(git symbolic-ref --short HEAD)}
|
2016-12-15 14:19:21 -05:00
|
|
|
if [ $# -gt 0 ]; then
|
|
|
|
ORG=$1
|
2018-06-05 14:38:46 -04:00
|
|
|
publishAllBuilds "ssh"
|
2018-04-27 19:21:38 -04:00
|
|
|
else
|
2016-12-15 14:19:21 -05:00
|
|
|
ORG="angular"
|
2018-06-05 14:38:46 -04:00
|
|
|
publishAllBuilds "http"
|
2015-11-09 18:25:00 -05:00
|
|
|
fi
|