Skip to content

Commit

Permalink
[#55] Update release.bash for new workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Jul 27, 2020
1 parent 0c7c182 commit 618c1ac
Showing 1 changed file with 94 additions and 21 deletions.
115 changes: 94 additions & 21 deletions release.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,108 @@ fi

RELEASE_VERSION="$(date -u +%Y.%m.%d_%H.%M.%S)"
DEVELOPMENT_VERSION="$(date -u +%Y.%m.%d_%H.%M)-NEXT-SNAPSHOT"
RELEASE_NOTES_FILE="RELEASE-NOTES-NEXT.md"
RELEASE_NOTES_HISTORY_FILE="RELEASE-NOTES.md"
RELEASE_NOTES_TEMP_HISTORY_FILE="RELEASE-NOTES.md.tmp"

# Displays the specified error message and exits with status code=1.
error() {
local BRIGHT_RED='\033[0;91m'
local NC='\033[0m' # No Color
echo -e "${BRIGHT_RED}Error: ${1:-Something went wrong}${NC}"
exit 1
}

echo "Releasing v${RELEASE_VERSION}"

echo "Checking for uncommitted changes..."
if ! mvn scm:check-local-modification; then
error "There are uncommitted changes. Please revert or commit them before releasing."
fi
echo "OK. The workspace is clean."

echo "Checking Release Notes for this release (RELEASE-NOTES-NEXT.md)..."
read -r -d '' RELEASE_NOTES_TEMPLATE << EOD
## Summary
This is a bugfix release...
## Changes in this Release
- First Change
- Second Change
EOD

# Read actual release notes (convert CRLF to LF in case file is checked out on Windows)
ACTUAL_RELEASE_NOTES=$(tr -d '\r' < "${RELEASE_NOTES_FILE}")

# Verify that `RELEASE-NOTES-NEXT.md` has release notes describing this release.
if [ -z "${ACTUAL_RELEASE_NOTES}" ] ; then
error "The Release Notes are empty. Please update ${RELEASE_NOTES_FILE}."
fi

#echo -n "${ACTUAL_RELEASE_NOTES}" | md5sum
#echo -n "${RELEASE_NOTES_TEMPLATE}" | md5sum

# Verify that `RELEASE-NOTES-NEXT.md` has actual release notes and not just the template.
if [ "${ACTUAL_RELEASE_NOTES}" == "${RELEASE_NOTES_TEMPLATE}" ]; then
error "The Release Notes are just the template. Please update ${RELEASE_NOTES_FILE}."
fi
echo "OK. Release Notes exist."

echo "Prepending ${RELEASE_NOTES_FILE} to ${RELEASE_NOTES_HISTORY_FILE}.."
# Copy the contents of `RELEASE-NOTES-NEXT.md` to the top of `RELEASE-NOTES.md`, with the tag name as a level-1 header.
echo "# ami v${RELEASE_VERSION}" > "${RELEASE_NOTES_TEMP_HISTORY_FILE}"
echo "${ACTUAL_RELEASE_NOTES}" >> "${RELEASE_NOTES_TEMP_HISTORY_FILE}"
echo "" >> "${RELEASE_NOTES_TEMP_HISTORY_FILE}"
echo "" >> "${RELEASE_NOTES_TEMP_HISTORY_FILE}"
cat "${RELEASE_NOTES_HISTORY_FILE}" >> "${RELEASE_NOTES_TEMP_HISTORY_FILE}"
mv "${RELEASE_NOTES_TEMP_HISTORY_FILE}" "${RELEASE_NOTES_HISTORY_FILE}"
echo "Updated ${RELEASE_NOTES_HISTORY_FILE} OK."

echo "Updating release version in pom.xml..."
# This `sed` syntax works on both GNU and BSD/macOS, due to a *non-empty* option-argument:
# Create a backup file *temporarily* and remove it on success.
sed -i.bak "s/<version>[0-9][0-9][0-9][0-9]\.[0-9][0-9]\.[0-9][0-9]_[0-9][0-9].*</<version>${RELEASE_VERSION}</g" pom.xml && rm pom.xml.bak

# The maven scm:checkin goal commits ALL modified files, not just pom.xml...
# see https://stackoverflow.com/questions/48947392/commit-multiple-files-with-maven-scm-plugin
# see https://maven.apache.org/scm/maven-scm-plugin/checkin-mojo.html
# WAS: if mvn scm:checkin -Dmessage="Bump ami version to ${RELEASE_VERSION}" -Dincludes=pom.xml -DpushChanges=false
if git commit -m "Release ami version ${RELEASE_VERSION}" --verbose pom.xml
echo "Committing pom.xml and RELEASE-NOTES.md..."
if ! git commit -m "Release ami version ${RELEASE_VERSION}" --verbose pom.xml RELEASE-NOTES.md
then
error "Unable to commit pom.xml and RELEASE-NOTES.md"
fi
echo "OK."

#git tag -m "Release ami version ${VERSION}"
# Use scm:check-local-modification to ensure all changes are committed before we tag the commit.
# see https://maven.apache.org/scm/maven-scm-plugin/tag-mojo.html
# and https://maven.apache.org/scm/maven-scm-plugin/check-local-modification-mojo.html
if mvn scm:check-local-modification scm:tag -Dmessage="Release ami version ${RELEASE_VERSION}" -DpushChanges=false
then
# mvn deploy to upload our distribution artifacts to GitHub Packages
# see https://docs.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-apache-maven-for-use-with-github-packages
#mvn -Darguments=-DskipTests -DskipTests -Dmaven.test.skip=true clean package deploy

echo "Updating to v${DEVELOPMENT_VERSION} for next development cycle..."
sed -i.bak "s/<version>${RELEASE_VERSION}</<version>${DEVELOPMENT_VERSION}</g" pom.xml && rm pom.xml.bak
# mvn scm:checkin -Dmessage="Updating ami version to ${DEVELOPMENT_VERSION} for next development cycle" -Dincludes=pom.xml -DpushChanges=true
git commit -m "Setting ami version to ${DEVELOPMENT_VERSION} for next development cycle" --verbose pom.xml
git push --tags --progress --porcelain origin master
fi
echo "Tagging last commit..."
if ! git tag -m "Release ami version ${RELEASE_VERSION}"
then
error "Unable to tag the last commit"
fi
echo "OK."

# If we wanted to run `mvn deploy` to publish to GitHub Packages, this is where we would do it.
# see https://docs.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-apache-maven-for-use-with-github-packages
#mvn -Darguments=-DskipTests -DskipTests -Dmaven.test.skip=true clean package deploy

echo "Preparing for next development cycle..."

echo "Resetting ${RELEASE_NOTES_FILE} to template..."
echo "${RELEASE_NOTES_TEMPLATE}" > "${RELEASE_NOTES_FILE}"

echo "Updating version in pom.xml to v${DEVELOPMENT_VERSION}..."
sed -i.bak "s/<version>${RELEASE_VERSION}</<version>${DEVELOPMENT_VERSION}</g" pom.xml && rm pom.xml.bak

echo "Committing pom.xml and ${RELEASE_NOTES_FILE}..."
if ! git commit -m "Setting ami version to ${DEVELOPMENT_VERSION} for next development cycle" --verbose pom.xml "${RELEASE_NOTES_FILE}"
then
error "Unable to commit pom.xml and ${RELEASE_NOTES_FILE}"
fi
echo "Committed SNAPSHOT version and reset Release Notes OK."

echo "Pushing changes..."
if ! git push --tags --progress --porcelain origin master
then
error "Unable push changes to master branch in origin repository"
fi
echo "Pushed changes OK."

echo "Done."

0 comments on commit 618c1ac

Please sign in to comment.