@@ -14,7 +14,12 @@ export LC_ALL=C
1414
1515# -- Functions --
1616
17- die () {
17+ debug () {
18+ test " $DEBUG " || return
19+ echo " [DEBUG] $@ "
20+ }
21+
22+ die () {
1823 echo " $* " >&2
1924 exit 1
2025}
@@ -111,6 +116,7 @@ Options include:
111116"
112117
113118# -- Extract project details --
119+ debug " Extracting project details"
114120
115121echoArg=' ${project.version}:${license.licenseName}:${project.parent.groupId}:${project.parent.artifactId}:${project.parent.version}'
116122projectDetails=$( mvn -N -Dexec.executable=echo -Dexec.args=" $echoArg " exec:exec -q)
@@ -124,10 +130,12 @@ licenseName=${projectDetails%%:*}
124130parentGAV=${projectDetails#*: }
125131
126132# -- Sanity checks --
133+ debug " Performing sanity checks"
127134
128135# Check that we have push rights to the repository.
129136if [ ! " $SKIP_PUSH " ]
130137then
138+ debug " Checking repository push rights"
131139 push=$( git remote -v | grep origin | grep ' (push)' )
132140 test " $push " || die ' No push URL found for remote origin.
133141Please use "git remote -v" to double check your remote settings.'
@@ -136,6 +144,7 @@ Please use "git remote set-url origin ..." to change it.'
136144fi
137145
138146# Discern the version to release.
147+ debug " Gleaning release version"
139148pomVersion=${currentVersion% -SNAPSHOT}
140149test " $VERSION " -o ! -t 0 || {
141150 printf ' Version? [%s]: ' " $pomVersion "
@@ -161,6 +170,7 @@ test -f "$VALID_SEMVER_BUMP" ||
161170 die " Missing helper script at '$VALID_SEMVER_BUMP '
162171Do you have a full clone of https://github.com/scijava/scijava-scripts?"
163172test " $SKIP_VERSION_CHECK " || {
173+ debug " Checking conformance to SemVer"
164174 sh -$- " $VALID_SEMVER_BUMP " " $pomVersion " " $VERSION " ||
165175 die " If you are sure, try again with --skip-version-check flag."
166176}
@@ -171,6 +181,7 @@ test -f "$MAVEN_HELPER" ||
171181 die " Missing helper script at '$MAVEN_HELPER '
172182Do you have a full clone of https://github.com/scijava/scijava-scripts?"
173183test " $SKIP_VERSION_CHECK " -o " $parentGAV " ! = " ${parentGAV# $} " || {
184+ debug " Checking pom-scijava parent version"
174185 latestParentVersion=$( sh -$- " $MAVEN_HELPER " latest-version " $parentGAV " )
175186 currentParentVersion=${parentGAV##*: }
176187 test " $currentParentVersion " = " $latestParentVersion " ||
@@ -180,18 +191,21 @@ Or if you know better, try again with --skip-version-check flag."
180191}
181192
182193# Check that the working copy is clean.
194+ debug " Checking if working copy is clean"
183195no_changes_pending || die ' There are uncommitted changes!'
184196test -z " $( git ls-files -o --exclude-standard) " ||
185197 die ' There are untracked files! Please stash them before releasing.'
186198
187199# Discern default branch.
200+ debug " Discerning default branch"
188201currentBranch=$( git rev-parse --abbrev-ref --symbolic-full-name HEAD)
189202upstreamBranch=$( git rev-parse --abbrev-ref --symbolic-full-name @{u})
190203remote=${upstreamBranch%/* }
191204defaultBranch=$( git remote show " $remote " | grep " HEAD branch" | sed ' s/.*: //' )
192205
193206# Check that we are on the main branch.
194207test " $SKIP_BRANCH_CHECK " || {
208+ debug " Checking current branch"
195209 test " $currentBranch " = " $defaultBranch " || die " Non-default branch: $currentBranch .
196210If you are certain you want to release from this branch,
197211try again with --skip-branch-check flag."
@@ -201,6 +215,7 @@ try again with --skip-branch-check flag."
201215REMOTE=" ${REMOTE:- $remote } "
202216
203217# Check that the main branch isn't behind the upstream branch.
218+ debug " Ensuring local branch is up-to-date"
204219HEAD=" $( git rev-parse HEAD) " &&
205220git fetch " $REMOTE " " $defaultBranch " &&
206221FETCH_HEAD=" $( git rev-parse FETCH_HEAD) " &&
@@ -209,6 +224,7 @@ test "$FETCH_HEAD" = "$(git merge-base $FETCH_HEAD $HEAD)" ||
209224 die " '$defaultBranch ' is not up-to-date"
210225
211226# Check for release-only files committed to the main branch.
227+ debug " Checking for spurious release-only files"
212228for release_file in release.properties pom.xml.releaseBackup
213229do
214230 if [ -e " $release_file " ]
224240done
225241
226242# Ensure that schema location URL uses HTTPS, not HTTP.
243+ debug " Checking that schema location URL uses HTTPS"
227244if grep -q http://maven.apache.org/xsd/maven-4.0.0.xsd pom.xml > /dev/null 2> /dev/null
228245then
229246 echo " ====================================================================="
237254fi
238255
239256# Check project xmlns, xmlns:xsi, and xsi:schemaLocation attributes.
257+ debug " Checking correctness of POM project XML attributes"
240258grep -qF ' xmlns="http://maven.apache.org/POM/4.0.0"' pom.xml > /dev/null 2> /dev/null &&
241259 grep -qF ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' pom.xml > /dev/null 2> /dev/null &&
242260 grep -qF ' xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 ' pom.xml > /dev/null 2> /dev/null ||
@@ -267,6 +285,7 @@ particular schema should always use the string identifier:' \
267285}
268286
269287# Change forum references from forum.image.net to forum.image.sc.
288+ debug " Checking correctness of forum URL references"
270289if grep -q ' https*://forum.imagej.net' pom.xml > /dev/null 2> /dev/null
271290then
272291 echo " ================================================================"
280299fi
281300
282301# Ensure that references to forum.image.sc use /tag/, not /tags/.
302+ debug " Checking correctness of forum tag references"
283303if grep -q forum.image.sc/tags/ pom.xml > /dev/null 2> /dev/null
284304then
285305 echo " =================================================================="
294314
295315# Ensure license headers are up-to-date.
296316test " $SKIP_LICENSE_UPDATE " -o -z " $licenseName " -o " $licenseName " = " N/A" || {
317+ debug " Ensuring that license headers are up-to-date"
297318 mvn license:update-project-license license:update-file-header &&
298319 git add LICENSE.txt || die ' Failed to update copyright blurbs.
299320You can skip the license update using the --skip-license-update flag.'
@@ -308,6 +329,7 @@ Alternately, try again with the --skip-license-update flag.'
308329}
309330
310331# Prepare new release without pushing (requires the release plugin >= 2.1).
332+ debug " Preparing new release"
311333$DRY_RUN mvn $BATCH_MODE release:prepare -DpushChanges=false -Dresume=false $TAG \
312334 $PROFILE $DEV_VERSION -DreleaseVersion=" $VERSION " \
313335 " -Darguments=-Dgpg.skip=true ${EXTRA_ARGS# } " ||
@@ -317,6 +339,7 @@ Use "mvn javadoc:javadoc | grep error" to check for javadoc syntax errors.'
317339# Squash the maven-release-plugin's two commits into one.
318340if test -z " $DRY_RUN "
319341then
342+ debug " Squashing release commits"
320343 test " [maven-release-plugin] prepare for next development iteration" = \
321344 " $( git show -s --format=%s HEAD) " ||
322345 die " maven-release-plugin's commits are unexpectedly missing!"
328351fi &&
329352
330353# Extract the name of the new tag.
354+ debug " Extracting new tag name"
331355if test -z " $DRY_RUN "
332356then
333357 tag=$( sed -n ' s/^scm.tag=//p' < release.properties)
336360fi &&
337361
338362# Rewrite the tag to include release.properties.
363+ debug " Rewriting tag to include release.properties"
339364test -n " $tag " &&
340365# HACK: SciJava projects use SSH ([email protected] :...) for developerConnection.341366# The release:perform command wants to use the developerConnection URL when
@@ -355,9 +380,13 @@ $DRY_RUN git checkout @{-1} &&
355380# Push the current branch and the tag.
356381if test -z " $SKIP_PUSH "
357382then
383+ debug " Pushing changes"
358384 $DRY_RUN git push " $REMOTE " HEAD $tag
359385fi
360386
361387# Remove files generated by the release process. They can end up
362388# committed to the mainline branch and hosing up later releases.
389+ debug " Cleaning up"
363390$DRY_RUN rm -f release.properties pom.xml.releaseBackup
391+
392+ debug " Release complete!"
0 commit comments