diff --git a/do-release.sh b/do-release.sh index 12bd13fb81..00efa30a5e 100755 --- a/do-release.sh +++ b/do-release.sh @@ -5,7 +5,7 @@ set -e export LANG=C.UTF-8 # verify the current directory -if [ ! -f pom.xml -o ! -d ../pmd.github.io ]; then +if [ ! -f pom.xml ] || [ ! -d ../pmd.github.io ]; then echo "You seem to be in the wrong working directory or you don't have pmd.github.io checked out..." echo echo "Expected:" @@ -26,20 +26,20 @@ echo "-------------------------------------------" CURRENT_VERSION=$(./mvnw org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.version -q -DforceStdout) RELEASE_VERSION=${CURRENT_VERSION%-SNAPSHOT} -MAJOR=$(echo $RELEASE_VERSION | cut -d . -f 1) -MINOR=$(echo $RELEASE_VERSION | cut -d . -f 2) -PATCH=$(echo $RELEASE_VERSION | cut -d . -f 3) +MAJOR=$(echo "$RELEASE_VERSION" | cut -d . -f 1) +MINOR=$(echo "$RELEASE_VERSION" | cut -d . -f 2) +PATCH=$(echo "$RELEASE_VERSION" | cut -d . -f 3) if [ "$PATCH" == "0" ]; then - NEXT_MINOR=$(expr ${MINOR} + 1) + NEXT_MINOR=$(("${MINOR}" + 1)) NEXT_PATCH="0" - LAST_MINOR=$(expr ${MINOR} - 1) + LAST_MINOR=$(("${MINOR}" - 1)) LAST_PATCH="0" else # this is a bugfixing release NEXT_MINOR="${MINOR}" - NEXT_PATCH=$(expr ${PATCH} + 1) + NEXT_PATCH=$(("${PATCH}" + 1)) LAST_MINOR="${MINOR}" - LAST_PATCH=$(expr ${PATCH} - 1) + LAST_PATCH=$(("${PATCH}" - 1)) fi LAST_VERSION="$MAJOR.$LAST_MINOR.$LAST_PATCH" DEVELOPMENT_VERSION="$MAJOR.$NEXT_MINOR.$NEXT_PATCH" @@ -65,7 +65,7 @@ echo echo "Is this correct?" echo echo "Press enter to continue... (or CTRL+C to cancel)" -read +read -r export LAST_VERSION export RELEASE_VERSION @@ -95,16 +95,16 @@ echo "* Update property \`pmd-designer.version\` in **pom.xml** to reference t echo " See for the available releases." echo echo "Press enter to continue..." -read +read -r # calculating stats for release notes STATS=$( echo "### Stats" -echo "* $(git log pmd_releases/${LAST_VERSION}..HEAD --oneline --no-merges |wc -l) commits" +echo "* $(git log pmd_releases/"${LAST_VERSION}"..HEAD --oneline --no-merges |wc -l) commits" echo "* $(curl -s https://api.github.com/repos/pmd/pmd/milestones|jq ".[] | select(.title == \"$RELEASE_VERSION\") | .closed_issues") closed tickets & PRs" -echo "* Days since last release: $(( ( $(date +%s) - $(git log --max-count=1 --format="%at" pmd_releases/${LAST_VERSION}) ) / 86400))" +echo "* Days since last release: $(( ( $(date +%s) - $(git log --max-count=1 --format="%at" pmd_releases/"${LAST_VERSION}") ) / 86400))" ) TEMP_RELEASE_NOTES=$(cat docs/pages/release_notes.md) @@ -118,17 +118,18 @@ echo echo "Please verify docs/pages/release_notes.md" echo echo "Press enter to continue..." -read +read -r # install bundles needed for rendering release notes bundle config set --local path vendor/bundle bundle config set --local with release_notes_preprocessing bundle install -export RELEASE_NOTES_POST="_posts/$(date -u +%Y-%m-%d)-PMD-${RELEASE_VERSION}.md" +RELEASE_NOTES_POST="_posts/$(date -u +%Y-%m-%d)-PMD-${RELEASE_VERSION}.md" +export RELEASE_NOTES_POST echo "Generating ../pmd.github.io/${RELEASE_NOTES_POST}..." NEW_RELEASE_NOTES=$(bundle exec docs/render_release_notes.rb docs/pages/release_notes.md | tail -n +6) -cat > ../pmd.github.io/${RELEASE_NOTES_POST} < "../pmd.github.io/${RELEASE_NOTES_POST}" </dev/null| egrep "^[AMDRC]" | wc -l) - if [ $changes -gt 0 ]; then + git add "${RELEASE_NOTES_POST}" + changes=$(git status --porcelain 2>/dev/null| grep -c -E "^[AMDRC]") + if [ "$changes" -gt 0 ]; then echo "Committing current changes (pmd.github.io)" git commit -a -m "Prepare pmd release ${RELEASE_VERSION}" && git push fi ) ./mvnw -B release:clean release:prepare \ - -Dtag=pmd_releases/${RELEASE_VERSION} \ - -DreleaseVersion=${RELEASE_VERSION} \ - -DdevelopmentVersion=${DEVELOPMENT_VERSION} \ + -Dtag="pmd_releases/${RELEASE_VERSION}" \ + -DreleaseVersion="${RELEASE_VERSION}" \ + -DdevelopmentVersion="${DEVELOPMENT_VERSION}" \ -Pgenerate-rule-docs @@ -166,7 +167,7 @@ echo "Tag has been pushed.... now check github actions: docs/pages/release_notes_old.md -echo "$NEW_RELEASE_NOTES" >> docs/pages/release_notes_old.md -echo >> docs/pages/release_notes_old.md -echo "$OLD_RELEASE_NOTES" >> docs/pages/release_notes_old.md +OLD_RELEASE_NOTES_HEADER=$(head -n 7 docs/pages/release_notes_old.md) +echo "${OLD_RELEASE_NOTES_HEADER} +${NEW_RELEASE_NOTES} +${OLD_RELEASE_NOTES}" > docs/pages/release_notes_old.md # reset release notes template cat > docs/pages/release_notes.md <