Skip to content

build: publish artifacts based on branch #9919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions scripts/deploy/publish-build-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,23 @@ publishPackage() {
packageName=${1}
packageRepo=${2}

buildDir="dist/releases/${packageName}"
buildDir="$(pwd)/dist/releases/${packageName}"
buildVersion=$(node -pe "require('./package.json').version")
branchName=${TRAVIS_BRANCH:-'master'}

commitSha=$(git rev-parse --short HEAD)
commitAuthorName=$(git --no-pager show -s --format='%an' HEAD)
commitAuthorEmail=$(git --no-pager show -s --format='%ae' HEAD)
commitMessage=$(git log --oneline -n 1)
commitTag="${buildVersion}-${commitSha}"

buildVersionName="${buildVersion}-${commitSha}"
buildTagName="${branchName}-${commitSha}"
buildCommitMessage="${branchName} - ${commitMessage}"

repoUrl="https://github.com/angular/${packageRepo}.git"
repoDir="tmp/${packageRepo}"

echo "Starting publish process of ${packageName} for ${commitTag}.."
echo "Starting publish process of ${packageName} for ${buildVersionName} into ${branchName}.."

if [[ ! ${COMMAND_ARGS} == *--no-build* ]]; then
# Create a release of the current repository.
Expand All @@ -59,26 +63,35 @@ publishPackage() {

echo "Successfully cloned ${repoUrl} into ${repoDir}."

# Copy the build files to the repository
rm -rf ${repoDir}/*
cp -r ${buildDir}/* ${repoDir}

echo "Removed everything from ${packageRepo} and added the new build output."

# Create the build commit and push the changes to the repository.
cd ${repoDir}

echo "Switched into the repository directory (${repoDir})."

if [[ $(git ls-remote origin "refs/tags/${commitTag}") ]]; then
if [[ $(git ls-remote --heads origin ${branchName}) ]]; then
git checkout ${branchName}
echo "Switched to ${branchName} branch."
else
echo "Branch ${branchName} does not exist on ${packageRepo} yet. Creating ${branchName}.."
git checkout -b ${branchName}
echo "Branch created and checked out."
fi

# Copy the build files to the repository
rm -rf ./*
cp -r ${buildDir}/* ./

echo "Removed everything from ${packageRepo}#${branchName} and added the new build output."

if [[ $(git ls-remote origin "refs/tags/${buildTagName}") ]]; then
echo "Skipping publish because tag is already published"
exit 0
fi

# Replace the version in every file recursively with a more specific version that also includes
# the SHA of the current build job. Normally this "sed" call would just replace the version
# placeholder, but the version placeholders have been replaced by the release task already.
sed -i "s/${buildVersion}/${commitTag}/g" $(find . -type f -not -path '*\/.*')
sed -i "s/${buildVersion}/${buildVersionName}/g" $(find . -type f -not -path '*\/.*')

echo "Updated the build version in every file to include the SHA of the latest commit."

Expand All @@ -92,11 +105,11 @@ publishPackage() {
echo "Git configuration has been updated to match the last commit author. Publishing now.."

git add -A
git commit --allow-empty -m "${commitMessage}"
git tag "${commitTag}"
git push origin master --tags
git commit --allow-empty -m "${buildCommitMessage}"
git tag "${buildTagName}"
git push origin ${branchName} --tags

echo "Published package artifacts for ${packageName}#${commitSha}."
echo "Published package artifacts for ${packageName}#${buildVersionName} into ${branchName}"
}

for ((i = 0; i < ${#PACKAGES[@]}; i++)); do
Expand Down