2017-03-05 09:49:10 +00:00
#!/usr/bin/env bash
2017-03-05 19:43:25 +00:00
set -x -u -e -o pipefail
2017-03-05 09:49:10 +00:00
# Setup environment
readonly thisDir = $( cd $( dirname $0 ) ; pwd )
2015-11-09 23:25:00 +00:00
2017-02-01 19:51:12 +00: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 23:25:00 +00:00
function publishRepo {
2016-05-10 00:26:51 +00:00
COMPONENT = $1
2015-11-09 23:25:00 +00:00
ARTIFACTS_DIR = $2
2016-05-10 00:26:51 +00:00
BUILD_REPO = " ${ COMPONENT } -builds "
2022-05-12 20:09:42 +00:00
REPO_DIR = " $( pwd ) /tmp/ ${ BUILD_REPO } "
REPO_URL = " https://github.com/angular/ ${ BUILD_REPO } .git "
2015-11-09 23:25:00 +00:00
2017-03-07 02:03:38 +00:00
if [ -n " ${ CREATE_REPOS :- } " ] ; then
2016-12-15 19:19:21 +00: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 23:25:00 +00:00
# create local repo folder and clone build repo into it
rm -rf $REPO_DIR
2022-05-12 20:09:42 +00:00
mkdir -p ${ REPO_DIR }
echo " Starting cloning process of ${ REPO_URL } into ${ REPO_DIR } .. "
2022-05-20 18:21:03 +00:00
2022-05-12 22:30:23 +00:00
(
if [ [ $( git ls-remote --heads ${ REPO_URL } ${ BRANCH } ) ] ] ; then
echo " Branch ${ BRANCH } already exists. Cloning that branch. "
git clone ${ REPO_URL } ${ REPO_DIR } --depth 1 --branch ${ BRANCH }
2022-05-12 20:09:42 +00:00
2022-05-12 22:30:23 +00:00
cd ${ REPO_DIR }
echo " Cloned repository and switched into the repository directory ( ${ REPO_DIR } ). "
else
2022-05-20 18:21:03 +00:00
echo " Branch ${ BRANCH } does not exist on ${ BUILD_REPO } yet. "
2022-05-12 22:30:23 +00:00
echo " Cloning default branch and creating branch ' ${ BRANCH } ' on top of it. "
2022-05-12 20:09:42 +00:00
2022-05-12 22:30:23 +00:00
git clone ${ REPO_URL } ${ REPO_DIR } --depth 1
cd ${ REPO_DIR }
2022-05-12 20:09:42 +00:00
2022-05-12 22:30:23 +00:00
echo "Cloned repository and switched into directory. Creating new branch now.."
2022-05-12 20:09:42 +00:00
2022-05-12 22:30:23 +00:00
git checkout -b ${ BRANCH }
fi
)
# Unshallow the repo manually so that it doesn't trigger a push failure.
# This is generally unsafe, however we immediately remove all of the files from within
# the repo on the next line, so we should be able to safely treat the entire repo
# contents as an atomic piece to be pushed.
rm $REPO_DIR /.git/shallow
2015-11-09 23:25:00 +00:00
# copy over build artifacts into the repo directory
rm -rf $REPO_DIR /*
cp -R $ARTIFACTS_DIR /* $REPO_DIR /
2016-05-25 22:37:40 +00:00
2018-04-23 18:46:02 +00:00
if [ [ ${ CI } ] ] ; then
2016-12-15 19:19:21 +00:00
(
2018-04-27 23:21:38 +00:00
# The file ~/.git_credentials is created in /.circleci/config.yml
2016-12-15 19:19:21 +00:00
cd $REPO_DIR && \
2018-04-23 18:46:02 +00:00
git config credential.helper " store --file= $HOME /.git_credentials "
2016-12-15 19:19:21 +00:00
)
2016-05-12 20:58:42 +00:00
fi
2015-11-09 23:25:00 +00:00
echo ` date` > $REPO_DIR /BUILD_INFO
echo $SHA >> $REPO_DIR /BUILD_INFO
2019-07-19 19:10:10 +00:00
echo 'This file is used by the npm/yarn_install rule to detect APF. See https://github.com/bazelbuild/rules_nodejs/issues/927' > $REPO_DIR /ANGULAR_PACKAGE
2015-11-09 23:25:00 +00:00
(
cd $REPO_DIR && \
2015-11-17 02:14:14 +00:00
git config user.name " ${ COMMITTER_USER_NAME } " && \
git config user.email " ${ COMMITTER_USER_EMAIL } " && \
2015-11-17 22:56:51 +00:00
git add --all && \
2017-08-24 19:49:58 +00:00
git commit -m " ${ COMMIT_MSG } " --quiet && \
2022-06-14 20:34:53 +00:00
git tag " ${ BUILD_VER } " --force && \
2016-12-20 22:52:50 +00:00
git push origin " ${ BRANCH } " --tags --force
2015-11-09 23:25:00 +00:00
)
}
2016-05-10 00:26:51 +00:00
# Publish all individual packages from packages-dist.
2016-12-15 19:19:21 +00:00
function publishPackages {
2017-01-19 22:25:44 +00:00
GIT_SCHEME = $1
PKGS_DIST = $2
BRANCH = $3
2018-09-28 13:11:07 +00:00
BUILD_VER = $4
2017-01-19 22:25:44 +00:00
2017-08-24 19:49:58 +00:00
for dir in $PKGS_DIST /*/
2016-05-10 00:26:51 +00:00
do
2021-03-31 17:47:19 +00:00
if [ [ ! -f " $dir /package.json " ] ] ; then
# Only publish directories that contain a `package.json` file.
echo " Skipping $dir , it does not contain a package to be published. "
continue
fi
2016-05-10 00:26:51 +00:00
COMPONENT = " $( basename ${ dir } ) "
2016-03-05 03:16:12 +00:00
2016-05-10 00:26:51 +00:00
# Replace _ with - in component name.
COMPONENT = " ${ COMPONENT //_/- } "
JS_BUILD_ARTIFACTS_DIR = " ${ dir } "
2016-03-05 03:16:12 +00:00
2017-01-19 22:25:44 +00:00
if [ [ " $GIT_SCHEME " = = "ssh" ] ] ; then
2016-12-15 19:19:21 +00:00
REPO_URL = " git@github.com: ${ ORG } / ${ COMPONENT } -builds.git "
2017-01-19 22:25:44 +00:00
elif [ [ " $GIT_SCHEME " = = "http" ] ] ; then
2016-12-15 19:19:21 +00:00
REPO_URL = " https://github.com/ ${ ORG } / ${ COMPONENT } -builds.git "
else
2017-01-19 22:25:44 +00:00
die " Don't have a way to publish to scheme $GIT_SCHEME "
2016-12-15 19:19:21 +00:00
fi
2016-03-05 03:16:12 +00:00
2016-05-10 00:26:51 +00:00
publishRepo " ${ COMPONENT } " " ${ JS_BUILD_ARTIFACTS_DIR } "
done
2015-11-18 06:56:41 +00:00
2015-11-09 23:25:00 +00:00
echo "Finished publishing build artifacts"
2016-12-15 19:19:21 +00:00
}
2018-06-05 18:38:46 +00:00
function publishAllBuilds( ) {
GIT_SCHEME = " $1 "
2018-09-28 13:11:07 +00: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`
2022-05-12 22:30:23 +00:00
PACKAGES_DIST = " $( pwd ) /dist/packages-dist "
2018-09-28 13:11:07 +00:00
local shortSha = ` git rev-parse --short HEAD`
local latestTag = ` getLatestTag`
2022-05-12 22:30:23 +00:00
publishPackages $GIT_SCHEME $PACKAGES_DIST $CUR_BRANCH " ${ latestTag } + ${ shortSha } "
2018-06-05 18:38:46 +00:00
}
2017-03-23 05:50:12 +00:00
# See docs/DEVELOPER.md for help
2023-09-28 19:17:41 +00:00
CUR_BRANCH = $( git symbolic-ref --short HEAD)
2016-12-15 19:19:21 +00:00
if [ $# -gt 0 ] ; then
ORG = $1
2018-06-05 18:38:46 +00:00
publishAllBuilds "ssh"
2018-04-27 23:21:38 +00:00
else
2016-12-15 19:19:21 +00:00
ORG = "angular"
2018-06-05 18:38:46 +00:00
publishAllBuilds "http"
2015-11-09 23:25:00 +00:00
fi