From 226f78bf8aaca83204b748881b404ff6fd430de5 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sun, 10 Nov 2019 18:35:10 +0100 Subject: [PATCH] [ci] Refactor upload of documentation to sourceforge --- .travis/build-deploy.sh | 1 - .travis/build-doc.sh | 54 +++++--------------------------------- .travis/build-publish.sh | 2 ++ .travis/sourceforge-api.sh | 33 +++++++++++++++++++++++ 4 files changed, 41 insertions(+), 49 deletions(-) diff --git a/.travis/build-deploy.sh b/.travis/build-deploy.sh index 7b1eb0a546..19b022dd0e 100755 --- a/.travis/build-deploy.sh +++ b/.travis/build-deploy.sh @@ -51,7 +51,6 @@ elif travis_isPush; then # Deploy to sourceforge files sourceforge_uploadFile "${VERSION}" "pmd-dist/target/pmd-bin-${VERSION}.zip" sourceforge_uploadFile "${VERSION}" "pmd-dist/target/pmd-src-${VERSION}.zip" - sourceforge_selectDefault "${VERSION}" regression-tester_uploadBaseline diff --git a/.travis/build-doc.sh b/.travis/build-doc.sh index d748e5aded..01771f41a3 100755 --- a/.travis/build-doc.sh +++ b/.travis/build-doc.sh @@ -98,58 +98,16 @@ if [[ "${VERSION}" != *-SNAPSHOT && "${TRAVIS_TAG}" != "" ]]; then git push origin master ) - - ( - # disable fast fail, exit immediately, in this subshell - set +e - - echo -e "\n\n" - log_info "Uploading the new release to pmd.sourceforge.net which serves as an archive..." - - .travis/travis_wait "rsync -ah --stats docs/pmd-doc-${VERSION}/ ${PMD_SF_USER}@web.sourceforge.net:/home/project-web/pmd/htdocs/pmd-${VERSION}/" - - if [ $? -ne 0 ]; then - log_error "Uploading documentation to pmd.sourceforge.net failed..." - log_error "Please upload manually (PMD Version: ${VERSION})" - else - log_success "The documentation is now available under http://pmd.sourceforge.net/pmd-${VERSION}/" - fi - true - ) + sourceforge_rsyncSnapshotDocumentation "${VERSION}" "pmd-${VERSION}" fi # Deploy to sourceforge files -( - # disable fast fail, exit immediately, in this subshell - set +e - - if [[ "${TRAVIS_TAG}" != "" || "${VERSION}" == *-SNAPSHOT ]]; then - echo -e "\n\n" - log_info "Uploading pmd doc distribution to sourceforge..." - .travis/travis_wait "rsync -avh docs/pmd-doc-${VERSION}.zip ${PMD_SF_USER}@web.sourceforge.net:/home/frs/project/pmd/pmd/${VERSION}/" - if [ $? -ne 0 ]; then - log_error "Couldn't upload docs/pmd-doc-${VERSION}.zip!" - log_error "Please upload manually: https://sourceforge.net/projects/pmd/files/pmd/" - else - log_success "Successfully uploaded pmd-doc-${VERSION}.zip to sourceforge" - fi - fi - - # rsync site to pmd.sourceforge.net/snapshot - if [[ "${VERSION}" == *-SNAPSHOT && "${TRAVIS_BRANCH}" == "master" ]]; then - echo -e "\n\n" - log_info "Uploading snapshot site to pmd.sourceforge.net/snapshot..." - .travis/travis_wait "rsync -ah --stats --delete docs/pmd-doc-${VERSION}/ ${PMD_SF_USER}@web.sourceforge.net:/home/project-web/pmd/htdocs/snapshot/" - if [ $? -ne 0 ]; then - log_error "Couldn't upload the snapshot documentation. It won't be current on http://pmd.sourceforge.net/snapshot/" - else - log_success "Successfully uploaded snapshot documentation: http://pmd.sourceforge.net/snapshot/" - fi - fi - - true -) +sourceforge_uploadFile "${VERSION}" "docs/pmd-doc-${VERSION}.zip" +# rsync site to https://pmd.sourceforge.io/snapshot +if [[ "${VERSION}" == *-SNAPSHOT && "${TRAVIS_BRANCH}" == "master" ]]; then + sourceforge_rsyncSnapshotDocumentation "${VERSION}" "snapshot" +fi diff --git a/.travis/build-publish.sh b/.travis/build-publish.sh index 9ed8241faa..e93f47a270 100644 --- a/.travis/build-publish.sh +++ b/.travis/build-publish.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 "PMD Release ${VERSION}" @@ -24,3 +25,4 @@ gh_releases_getLatestDraftRelease GH_RELEASE="$RESULT" gh_release_publishRelease "$GH_RELEASE" +sourceforge_selectDefault "${VERSION}" diff --git a/.travis/sourceforge-api.sh b/.travis/sourceforge-api.sh index 8f5d4d24e2..41933c9a21 100644 --- a/.travis/sourceforge-api.sh +++ b/.travis/sourceforge-api.sh @@ -131,3 +131,36 @@ function sourceforge_selectDefault() { # restore errexit state eval "$errexitstate" } + +# +# Rsyncs the complete documentation to sourceforge. +# +# Note: This function always succeeds, even if the upload fails. +# In that case, just a error logging is provided. +# +function sourceforge_rsyncSnapshotDocumentation() { + local pmdVersion="$1" + local targetPath="$2" + + log_debug "$FUNCNAME pmdVersion=$pmdVersion targetPath=$targetPath" + local targetUrl="https://pmd.sourceforge.io/${targetPath}/" + + local errexitstate="$(shopt -po errexit)" + set +e # disable errexit + ( + # This handler is called if any command fails + function upload_failed() { + log_error "Couldn't upload the documentation. It won't be current on ${targetUrl}" + } + + # exit subshell after trap + set -e + trap upload_failed ERR + + log_info "Uploading documentation to ${targetUrl}..." + .travis/travis_wait "rsync -ah --stats --delete docs/pmd-doc-${VERSION}/ ${PMD_SF_USER}@web.sourceforge.net:/home/project-web/pmd/htdocs/snapshot/" + log_success "Successfully uploaded documentation: ${targetUrl}" + ) + # restore errexit state + eval "$errexitstate" +}