From 5828134799d30f8cf5993be0c815746953c82c2c Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Mon, 8 Nov 2010 16:56:04 -0800 Subject: [PATCH] Make doc symlink creation more robust :docs:uploadArchives symlink creation now checks to ensure that any existing wildcard (e.g., 2.0.x) or 'latest-ga' symlinks do not point to targets with greater lexical value than the version being published. If so, the symlink will not be overwritten. EXAMPLE Given an existing docs/ directory listing as follows: 1.0.3.RELEASE 1.0.x -> 1.0.3.RELEASE 2.0.0.BUILD-SNAPSHOT 2.0.0.RC1 2.0.x -> 2.0.0.RC1 latest-ga -> 1.0.3.RELEASE Upon publishing 1.0.4.RELEASE, the directory listing will update as follows (asterisk indicates added / changed entries): 1.0.3.RELEASE * 1.0.4.RELEASE * 1.0.x -> 1.0.4.RELEASE 2.0.0.BUILD-SNAPSHOT 2.0.0.RC1 2.0.x -> 2.0.0.RC1 * latest-ga -> 1.0.4.RELEASE This functionality worked as described prior to this change. However, it would break down in the following scenario. Imagine the existing directory listing had been as below, following the release of Spring Integration 2.0.0.RELEASE: 1.0.3.RELEASE 1.0.x -> 1.0.3.RELEASE 2.0.0.BUILD-SNAPSHOT 2.0.0.RC1 2.0.0.RELEASE 2.0.x -> 2.0.0.RELEASE latest-ga -> 2.0.0.RELEASE Note that latest-ga points to 2.0.0.RELEASE. Prior to the changes in this commit, if a new GA on the 1.0.x line were to be published the latest-ga symlink would have been incorrectly updated: 1.0.3.RELEASE * 1.0.4.RELEASE * 1.0.x -> 1.0.4.RELEASE 2.0.0.BUILD-SNAPSHOT 2.0.0.RC1 2.0.0.RELEASE 2.0.x -> 2.0.0.RELEASE ! latest-ga -> 1.0.4.RELEASE ! indicates the mistake. We want latest-ga to point to the latest GA release at all times. This now happens, such that the directory listing would be updated as follows: 1.0.3.RELEASE * 1.0.4.RELEASE * 1.0.x -> 1.0.4.RELEASE 2.0.0.BUILD-SNAPSHOT 2.0.0.RC1 2.0.0.RELEASE 2.0.x -> 2.0.0.RELEASE latest-ga -> 2.0.0.RELEASE Note that 'latest-ga' remains unchanged. This same logic applies when updating wildcard links. In the rare case that a 1.0.4.RELEASE were published *after* a 1.0.5.RELEASE, the wildcard symlink will not be updated. It will remain pointing to 1.0.5.RELEASE. --- docs/build.gradle | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/docs/build.gradle b/docs/build.gradle index 8d542f61ce..0c2b368f33 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -228,18 +228,47 @@ uploadArchives { classpath: configurations.scpAntTask.asPath) // copy the archive, unpack it, then delete it - def unpackCommand = "cd ${remoteDocsDir} && rm -rf ${version} && unzip -qKo ${archive.archiveName} && rm ${archive.archiveName}" - def wildcardSymlinkCommand = "cd ${remoteDocsDir} && rm -f ${version.wildcardValue} && ln -s ${version} ${version.wildcardValue}" - def latestGASymlinkCommand = "cd ${remoteDocsDir} && rm -f latest-ga && ln -s ${version} latest-ga" + def unpackCommand = """ + cd ${remoteDocsDir} && + rm -rf ${version} && + unzip -qKo ${archive.archiveName} && + rm ${archive.archiveName} + """ - println "Unpacking docs archive: (${unpackCommand})" + def wildcardSymlinkCommand = """ + cd ${remoteDocsDir} && + if [ -e ${version.wildcardValue} ]; then + currentWildcard=`readlink ${version.wildcardValue}` + else + currentWildcard=-1 + fi && + if [[ ${version} > \$currentWildcard ]]; then + rm -f ${version.wildcardValue} && + ln -s ${version} ${version.wildcardValue} + fi + """ + + def latestGASymlinkCommand = """ + cd ${remoteDocsDir} && + if [ -e latest-ga ]; then + latestGa=`readlink latest-ga` + else + latestGa=-1 + fi && + if [[ ${version} > \$latestGa ]]; then + rm -f latest-ga && + ln -s ${version} latest-ga + fi + """ + + println "Unpacking docs archive: ${unpackCommand}" sshexec(host: sshHost, username: sshUsername, keyfile: sshPrivateKey, command: unpackCommand) if (version.releaseType != 'SNAPSHOT') { - println "Creating wildcard symlink: (${wildcardSymlinkCommand})" + println "Creating wildcard symlink: ${wildcardSymlinkCommand}" sshexec(host: sshHost, username: sshUsername, keyfile: sshPrivateKey, command: wildcardSymlinkCommand) } if (version.releaseType == 'RELEASE') { - println "Creating latest-ga symlink: (${latestGASymlinkCommand})" + println "Creating latest-ga symlink: ${latestGASymlinkCommand}" sshexec(host: sshHost, username: sshUsername, keyfile: sshPrivateKey, command: latestGASymlinkCommand) } println "UPLOAD SUCCESSFUL - validate by visiting ${docUrl}"