@@ -29,19 +29,23 @@ publishPackage() {
29
29
packageName=${1}
30
30
packageRepo=${2}
31
31
32
- buildDir=" dist/releases/${packageName} "
32
+ buildDir=" $( pwd ) / dist/releases/${packageName} "
33
33
buildVersion=$( node -pe " require('./package.json').version" )
34
+ branchName=${TRAVIS_BRANCH:- ' master' }
34
35
35
36
commitSha=$( git rev-parse --short HEAD)
36
37
commitAuthorName=$( git --no-pager show -s --format=' %an' HEAD)
37
38
commitAuthorEmail=$( git --no-pager show -s --format=' %ae' HEAD)
38
39
commitMessage=$( git log --oneline -n 1)
39
- commitTag=" ${buildVersion} -${commitSha} "
40
+
41
+ buildVersionName=" ${buildVersion} -${commitSha} "
42
+ buildTagName=" ${branchName} -${commitSha} "
43
+ buildCommitMessage=" ${branchName} - ${commitMessage} "
40
44
41
45
repoUrl=" https://github.com/angular/${packageRepo} .git"
42
46
repoDir=" tmp/${packageRepo} "
43
47
44
- echo " Starting publish process of ${packageName} for ${commitTag } .."
48
+ echo " Starting publish process of ${packageName} for ${buildVersionName} into ${branchName } .."
45
49
46
50
if [[ ! ${COMMAND_ARGS} == * --no-build* ]]; then
47
51
# Create a release of the current repository.
@@ -59,26 +63,35 @@ publishPackage() {
59
63
60
64
echo " Successfully cloned ${repoUrl} into ${repoDir} ."
61
65
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
-
68
66
# Create the build commit and push the changes to the repository.
69
67
cd ${repoDir}
70
68
71
69
echo " Switched into the repository directory (${repoDir} )."
72
70
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
74
87
echo " Skipping publish because tag is already published"
75
88
exit 0
76
89
fi
77
90
78
91
# Replace the version in every file recursively with a more specific version that also includes
79
92
# the SHA of the current build job. Normally this "sed" call would just replace the version
80
93
# 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 ' *\/.*' )
82
95
83
96
echo " Updated the build version in every file to include the SHA of the latest commit."
84
97
@@ -92,11 +105,11 @@ publishPackage() {
92
105
echo " Git configuration has been updated to match the last commit author. Publishing now.."
93
106
94
107
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
98
111
99
- echo " Published package artifacts for ${packageName} #${commitSha} . "
112
+ echo " Published package artifacts for ${packageName} #${buildVersionName} into ${branchName} "
100
113
}
101
114
102
115
for (( i = 0 ; i < ${# PACKAGES[@]} ; i++ )) ; do
0 commit comments