diff --git a/.travis/build-deploy.sh b/.travis/build-deploy.sh index 1f72543946..e3e7eb1381 100755 --- a/.travis/build-deploy.sh +++ b/.travis/build-deploy.sh @@ -4,6 +4,7 @@ set -e source .travis/logger.sh source .travis/common-functions.sh source .travis/github-releases-api.sh +source .travis/sourceforge-api.sh function upload_baseline() { log_info "Generating and uploading baseline for pmdtester..." @@ -64,39 +65,27 @@ elif travis_isPush; then gh_releases_createDraftRelease "${TRAVIS_TAG}" "$(git show-ref --hash HEAD)" GH_RELEASE="$RESULT" + # Build and deploy to ossrh / maven-central ./mvnw deploy -Possrh,sign,pmd-release $MVN_BUILD_FLAGS echo -e "\n\n" - # Deploy to ossrh has already been done with the usual maven build - # Deploy to github releases gh_release_uploadAsset "$GH_RELEASE" "pmd-dist/target/pmd-bin-${VERSION}.zip" gh_release_uploadAsset "$GH_RELEASE" "pmd-dist/target/pmd-src-${VERSION}.zip" - # Deploy to sourceforge files - ( - # disable fast fail, exit immediately, in this subshell - set +e - - echo -e "\n\n" - log_info "Uploading pmd distribution to sourceforge..." - .travis/travis_wait "rsync -avh pmd-dist/target/pmd-*-${VERSION}.zip ${PMD_SF_USER}@web.sourceforge.net:/home/frs/project/pmd/pmd/${VERSION}/" - if [ $? -ne 0 ]; then - log_error "Error while uploading pmd-*-${VERSION}.zip to sourceforge!" - log_error "Please upload manually: https://sourceforge.net/projects/pmd/files/pmd/" - exit 1 - else - log_success "Successfully uploaded pmd-*-${VERSION}.zip to sourceforge" - fi - - true - ) - + sourceforge_uploadFile "${VERSION}" "pmd-dist/target/pmd-bin-${VERSION}.zip" + sourceforge_uploadFile "${VERSION}" "pmd-dist/target/pmd-src-${VERSION}.zip" + sourceforge_selectDefault "${VERSION}" elif [[ "${VERSION}" == *-SNAPSHOT ]]; then log_info "This is a snapshot build" ./mvnw deploy -Possrh,sign $MVN_BUILD_FLAGS + + # Deploy to sourceforge files + sourceforge_uploadFile "${VERSION}" "pmd-dist/target/pmd-bin-${VERSION}.zip" + sourceforge_uploadFile "${VERSION}" "pmd-dist/target/pmd-src-${VERSION}.zip" + else # other build. Can happen during release: the commit with a non snapshot version is built, but not from the tag. log_info "This is some other build, probably during release: commit with a non-snapshot version on branch master..." @@ -105,57 +94,6 @@ elif travis_isPush; then exit 0 fi - # Deploy to sourceforge files - ( - # disable fast fail, exit immediately, in this subshell - set +e - - echo -e "\n\n" - log_info "Uploading pmd distribution to sourceforge..." - .travis/travis_wait "rsync -avh pmd-dist/target/pmd-*-${VERSION}.zip ${PMD_SF_USER}@web.sourceforge.net:/home/frs/project/pmd/pmd/${VERSION}/" - if [ $? -ne 0 ]; then - log_error "Error while uploading pmd-*-${VERSION}.zip to sourceforge!" - log_error "Please upload manually: https://sourceforge.net/projects/pmd/files/pmd/" - exit 1 - else - log_success "Successfully uploaded pmd-*-${VERSION}.zip to sourceforge" - fi - - if [[ "${VERSION}" != *-SNAPSHOT && "${TRAVIS_TAG}" != "" ]]; then - # Since this is a release, making the binary the new default file... - log_info "Selecting pmd-bin-${VERSION} as default on sourceforge.net..." - curl -H "Accept: application/json" -X PUT -d "default=windows&default=mac&default=linux&default=bsd&default=solaris&default=others" \ - -d "api_key=${PMD_SF_APIKEY}" https://sourceforge.net/projects/pmd/files/pmd/${VERSION}/pmd-bin-${VERSION}.zip - if [ $? -ne 0 ]; then - log_error "Couldn't select latest binary as default on sourceforge.net" - else - log_info "pmd-bin-${VERSION} is now the default download option." - fi - fi - ) - ( # UPLOAD RELEASE NOTES TO SOURCEFORGE - - # This handler is called if any command fails - function release_notes_fail() { - log_error "Error while uploading release_notes.md as ReadMe.md to sourceforge!" - log_error "Please upload manually: https://sourceforge.net/projects/pmd/files/pmd/" - } - - # exit subshell after trap - set -e - trap release_notes_fail ERR - - RELEASE_NOTES_TMP=$(mktemp -t) - - bundle exec .travis/render_release_notes.rb docs/pages/release_notes.md | tail -n +6 > "$RELEASE_NOTES_TMP" - - rsync -avh "$RELEASE_NOTES_TMP" ${PMD_SF_USER}@web.sourceforge.net:/home/frs/project/pmd/pmd/${VERSION}/ReadMe.md - - log_success "Successfully uploaded release_notes.md as ReadMe.md to sourceforge" - - ) - - ( # disable fast fail, exit immediately, in this subshell set +e diff --git a/.travis/build-doc.sh b/.travis/build-doc.sh index 98b295b64f..d748e5aded 100755 --- a/.travis/build-doc.sh +++ b/.travis/build-doc.sh @@ -4,6 +4,7 @@ set -e source .travis/logger.sh source .travis/common-functions.sh source .travis/github-releases-api.sh +source .travis/sourceforge-api.sh VERSION=$(./mvnw -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.5.0:exec) log_info "Building PMD Documentation ${VERSION} on branch ${TRAVIS_BRANCH}" @@ -53,6 +54,7 @@ if [[ "${VERSION}" != *-SNAPSHOT && "${TRAVIS_TAG}" != "" ]]; then RENDERED_RELEASE_NOTES=$(bundle exec .travis/render_release_notes.rb docs/pages/release_notes.md | tail -n +6) RELEASE_NAME="PMD ${VERSION} ($(date -u +%d-%B-%Y))" gh_release_updateRelease "$GH_RELEASE" "$RELEASE_NAME" "$RENDERED_RELEASE_NOTES" + sourceforge_uploadReleaseNotes "${VERSION}" "${RENDERED_RELEASE_NOTES}" echo -e "\n\n" log_info "Adding the new doc to pmd.github.io..." diff --git a/.travis/github-releases-api.sh b/.travis/github-releases-api.sh index 0fc6cfda05..7fde8b837d 100644 --- a/.travis/github-releases-api.sh +++ b/.travis/github-releases-api.sh @@ -1,4 +1,10 @@ - +# +# The functions here require the following scripts: +# .travis/logger.sh +# +# The functions here require the following environment variables: +# GITHUB_OAUTH_TOKEN +# # # Creates a new release on github with the given tag and target_commit. diff --git a/.travis/sourceforge-api.sh b/.travis/sourceforge-api.sh new file mode 100644 index 0000000000..8f5d4d24e2 --- /dev/null +++ b/.travis/sourceforge-api.sh @@ -0,0 +1,133 @@ +# +# The functions here require the following scripts: +# .travis/logger.sh +# +# The functions here require the following environment variables: +# PMD_SF_USER +# PMD_SF_APIKEY +# + +# +# Uploads the release notes to sourceforge files as "ReadMe.md". +# +# Note: this function always succeeds, even if the upload fails. +# In that case, just a error logging is provided. +# +function sourceforge_uploadReleaseNotes() { + local pmdVersion="$1" + local releaseNotes="$2" + + log_debug "$FUNCNAME pmdVersion=$pmdVersion" + local targetUrl="https://sourceforge.net/projects/pmd/files/pmd/${pmdVersion}" + + local errexitstate="$(shopt -po errexit)" + set +e # disable errexit + ( + # This handler is called if any command fails + function release_notes_fail() { + log_error "Error while uploading release notes as ReadMe.md to sourceforge!" + log_error "Please upload manually: ${targetUrl}" + cleanup_temp_dir + } + + function cleanup_temp_dir() { + log_debug "Cleanup tempdir $releaseNotesTempDir" + rm "${releaseNotesTempDir}/${pmdVersion}/ReadMe.md" || true + rmdir "${releaseNotesTempDir}/${pmdVersion}" || true + rmdir "${releaseNotesTempDir}" || true + } + + # exit subshell after trap + set -e + trap release_notes_fail ERR + + local releaseNotesTempDir=$(mktemp -d) + log_debug "Tempdir: $releaseNotesTempDir" + mkdir -p "${releaseNotesTempDir}/${pmdVersion}" + echo "$releaseNotes" > "${releaseNotesTempDir}/${pmdVersion}/ReadMe.md" + + log_info "Uploading release notes to sourceforge for version $pmdVersion" + rsync -avz \ + "${releaseNotesTempDir}/" \ + "${PMD_SF_USER}@web.sourceforge.net:/home/frs/project/pmd/pmd/" + + log_success "Successfully uploaded release notes as ReadMe.md to sourceforge: ${targetUrl}" + + cleanup_temp_dir + ) + # restore errexit state + eval "$errexitstate" +} + +# +# Uploads the given file to sourceforge. +# +# Note: This function always succeeds, even if the upload fails. +# In that case, just a error logging is provided. +# +function sourceforge_uploadFile() { + local pmdVersion="$1" + local filename="$2" + + log_debug "$FUNCNAME pmdVersion=$pmdVersion filename=$filename" + local targetUrl="https://sourceforge.net/projects/pmd/files/pmd/${pmdVersion}" + + local errexitstate="$(shopt -po errexit)" + set +e # disable errexit + ( + # This handler is called if any command fails + function upload_failed() { + log_error "Error while uploading ${filename} to sourceforge!" + log_error "Please upload manually: ${targetUrl}" + } + + # exit subshell after trap + set -e + trap upload_failed ERR + + log_info "Uploading $filename to sourceforge..." + .travis/travis_wait "rsync -avh ${filename} ${PMD_SF_USER}@web.sourceforge.net:/home/frs/project/pmd/pmd/${pmdVersion}/" + log_success "Successfully uploaded ${filename} to sourceforge: ${targetUrl}" + ) + # restore errexit state + eval "$errexitstate" +} + +# +# Select the given version as the new default download. +# +# Note: This function always succeeds, even if the request fails. +# In that case, just a error logging is provided. +# +function sourceforge_selectDefault() { + local pmdVersion="$1" + + log_debug "$FUNCNAME pmdVersion=$pmdVersion" + local targetUrl="https://sourceforge.net/projects/pmd/files/pmd/${pmdVersion}" + + local errexitstate="$(shopt -po errexit)" + set +e # disable errexit + ( + # This handler is called if any command fails + function request_failed() { + log_error "Error while selecting ${pmdVersion} as new default download on sourceforge!" + log_error "Please do it manually: ${targetUrl}" + } + + # exit subshell after trap + set -e + trap request_failed ERR + + log_info "Selecting $pmdVersion as new default on sourceforge..." + local response + response=$(curl --fail -s -H "Accept: application/json" \ + -X PUT \ + -d "api_key=${PMD_SF_APIKEY}" \ + -d "default=windows&default=mac&default=linux&default=bsd&default=solaris&default=others" \ + "https://sourceforge.net/projects/pmd/files/pmd/${pmdVersion}/pmd-bin-${pmdVersion}.zip") + log_debug " -> response: $response" + log_success "Successfully selected $pmdVersion as new default on sourceforge: ${targetUrl}" + ) + # restore errexit state + eval "$errexitstate" +}