@@ -29,19 +29,23 @@ publishPackage() {
2929 packageName=${1}
3030 packageRepo=${2}
3131
32- buildDir=" dist/releases/${packageName} "
32+ buildDir=" $( pwd ) / dist/releases/${packageName} "
3333 buildVersion=$( node -pe " require('./package.json').version" )
34+ branchName=${TRAVIS_BRANCH:- ' master' }
3435
3536 commitSha=$( git rev-parse --short HEAD)
3637 commitAuthorName=$( git --no-pager show -s --format=' %an' HEAD)
3738 commitAuthorEmail=$( git --no-pager show -s --format=' %ae' HEAD)
3839 commitMessage=$( git log --oneline -n 1)
39- commitTag=" ${buildVersion} -${commitSha} "
40+
41+ buildVersionName=" ${buildVersion} -${commitSha} "
42+ buildTagName=" ${branchName} -${commitSha} "
43+ buildCommitMessage=" ${branchName} - ${commitMessage} "
4044
4145 repoUrl=" https://github.com/angular/${packageRepo} .git"
4246 repoDir=" tmp/${packageRepo} "
4347
44- echo " Starting publish process of ${packageName} for ${commitTag } .."
48+ echo " Starting publish process of ${packageName} for ${buildVersionName} into ${branchName } .."
4549
4650 if [[ ! ${COMMAND_ARGS} == * --no-build* ]]; then
4751 # Create a release of the current repository.
@@ -59,26 +63,35 @@ publishPackage() {
5963
6064 echo " Successfully cloned ${repoUrl} into ${repoDir} ."
6165
62- # Copy the build files to the repository
63- rm -rf ${repoDir} /*
64- cp -r ${buildDir} /* ${repoDir}
65-
66- echo " Removed everything from ${packageRepo} and added the new build output."
67-
6866 # Create the build commit and push the changes to the repository.
6967 cd ${repoDir}
7068
7169 echo " Switched into the repository directory (${repoDir} )."
7270
73- if [[ $( git ls-remote origin " refs/tags/${commitTag} " ) ]]; then
71+ if [[ $( git ls-remote --heads origin ${branchName} ) ]]; then
72+ git checkout ${branchName}
73+ echo " Switched to ${branchName} branch."
74+ else
75+ echo " Branch ${branchName} does not exist on ${packageRepo} yet. Creating ${branchName} .."
76+ git checkout -b ${branchName}
77+ echo " Branch created and checked out."
78+ fi
79+
80+ # Copy the build files to the repository
81+ rm -rf ./*
82+ cp -r ${buildDir} /* ./
83+
84+ echo " Removed everything from ${packageRepo} #${branchName} and added the new build output."
85+
86+ if [[ $( git ls-remote origin " refs/tags/${buildTagName} " ) ]]; then
7487 echo " Skipping publish because tag is already published"
7588 exit 0
7689 fi
7790
7891 # Replace the version in every file recursively with a more specific version that also includes
7992 # the SHA of the current build job. Normally this "sed" call would just replace the version
8093 # placeholder, but the version placeholders have been replaced by the release task already.
81- sed -i " s/${buildVersion} /${commitTag } /g" $( find . -type f -not -path ' *\/.*' )
94+ sed -i " s/${buildVersion} /${buildVersionName } /g" $( find . -type f -not -path ' *\/.*' )
8295
8396 echo " Updated the build version in every file to include the SHA of the latest commit."
8497
@@ -92,11 +105,11 @@ publishPackage() {
92105 echo " Git configuration has been updated to match the last commit author. Publishing now.."
93106
94107 git add -A
95- git commit --allow-empty -m " ${commitMessage } "
96- git tag " ${commitTag } "
97- git push origin master --tags
108+ git commit --allow-empty -m " ${buildCommitMessage } "
109+ git tag " ${buildTagName } "
110+ git push origin ${branchName} --tags
98111
99- echo " Published package artifacts for ${packageName} #${commitSha} . "
112+ echo " Published package artifacts for ${packageName} #${buildVersionName} into ${branchName} "
100113}
101114
102115for (( i = 0 ; i < ${# PACKAGES[@]} ; i++ )) ; do
0 commit comments