2020-11-10 22:26:26 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
# Exit this script immediately if a command/function exits with a non-zero status.
|
2020-11-10 22:26:26 +01:00
|
|
|
set -e
|
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
SCRIPT_INCLUDES="log.bash utils.bash setup-secrets.bash openjdk.bash maven.bash github-releases-api.bash
|
|
|
|
sourceforge-api.bash pmd-doc.inc pmd-code-api.inc regression-tester.inc"
|
|
|
|
# shellcheck source=inc/fetch_ci_scripts.bash
|
|
|
|
source "$(dirname "$0")/inc/fetch_ci_scripts.bash" && fetch_ci_scripts
|
|
|
|
|
|
|
|
function build() {
|
|
|
|
pmd_ci_log_group_start "Prepare Java 7+11, Bundler"
|
|
|
|
pmd_ci_openjdk_install_adoptopenjdk 11
|
|
|
|
pmd_ci_openjdk_setdefault 11
|
|
|
|
PMD_MAVEN_EXTRA_OPTS=""
|
|
|
|
if [ "$(pmd_ci_utils_get_os)" = "linux" ]; then
|
|
|
|
log_info "Install openjdk7 for integration tests"
|
|
|
|
pmd_ci_openjdk_install_zuluopenjdk 7
|
|
|
|
PMD_MAVEN_EXTRA_OPTS="-Djava7.home=${HOME}/oraclejdk7"
|
|
|
|
fi
|
2020-11-13 20:34:37 +01:00
|
|
|
pmd_ci_build_setup_bundler
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_group_end
|
|
|
|
|
|
|
|
echo
|
|
|
|
pmd_ci_maven_display_info_banner
|
|
|
|
pmd_ci_utils_determine_build_env pmd/pmd
|
|
|
|
echo
|
|
|
|
|
|
|
|
if pmd_ci_utils_is_fork_or_pull_request; then
|
|
|
|
pmd_ci_log_group_start "Build with mvnw"
|
|
|
|
./mvnw clean verify --show-version --errors --batch-mode --no-transfer-progress ${PMD_MAVEN_EXTRA_OPTS}
|
|
|
|
pmd_ci_log_group_end
|
|
|
|
|
|
|
|
# Danger is executed only on the linux runner
|
|
|
|
if [ "$(pmd_ci_utils_get_os)" = "linux" ]; then
|
|
|
|
pmd_ci_log_group_start "Executing danger"
|
|
|
|
regression_tester_setup_ci
|
|
|
|
regression_tester_executeDanger
|
|
|
|
pmd_ci_log_group_end
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$(pmd_ci_utils_get_os)" != "linux" ]; then
|
|
|
|
pmd_ci_log_group_start "Build with mvnw"
|
|
|
|
./mvnw clean verify --show-version --errors --batch-mode --no-transfer-progress ${PMD_MAVEN_EXTRA_OPTS}
|
|
|
|
pmd_ci_log_group_end
|
2020-11-13 20:34:37 +01:00
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_info "Stopping build here, because os is not linux"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# only builds on pmd/pmd continue here
|
|
|
|
pmd_ci_log_group_start "Setup environment"
|
|
|
|
pmd_ci_setup_secrets_private_env
|
|
|
|
pmd_ci_setup_secrets_gpg_key
|
|
|
|
pmd_ci_setup_secrets_ssh
|
|
|
|
pmd_ci_maven_setup_settings
|
|
|
|
pmd_ci_log_group_end
|
|
|
|
|
|
|
|
pmd_ci_log_group_start "Build and Deploy"
|
2020-11-13 20:34:37 +01:00
|
|
|
pmd_ci_build_run
|
|
|
|
pmd_ci_deploy_build_artifacts
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_group_end
|
2020-11-13 20:34:37 +01:00
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_group_start "Build and Upload documentation"
|
2020-11-13 20:34:37 +01:00
|
|
|
pmd_ci_build_and_upload_doc
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_group_end
|
2020-11-13 20:34:37 +01:00
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
if pmd_ci_maven_isReleaseBuild; then
|
|
|
|
pmd_ci_log_group_start "Publishing Release"
|
|
|
|
pmd_ci_gh_releases_publishRelease "$GH_RELEASE"
|
|
|
|
pmd_ci_sourceforge_selectDefault "${PMD_CI_MAVEN_PROJECT_VERSION}"
|
|
|
|
pmd_ci_log_group_end
|
2020-11-13 20:34:37 +01:00
|
|
|
fi
|
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_group_start "Creating new baseline for regression tester"
|
2020-11-13 20:34:37 +01:00
|
|
|
regression_tester_setup_ci
|
|
|
|
regression_tester_uploadBaseline
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_group_end
|
2020-11-13 20:34:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Installs bundler, which is needed for doc generation and regression tester
|
|
|
|
#
|
|
|
|
function pmd_ci_build_setup_bundler() {
|
|
|
|
log_info "Installing bundler..."
|
|
|
|
gem install bundler
|
|
|
|
}
|
2020-11-12 10:17:44 +01:00
|
|
|
|
2020-11-13 20:34:37 +01:00
|
|
|
#
|
|
|
|
# Performs the actual build.
|
|
|
|
# Deploys the artifacts to maven central.
|
|
|
|
# Also generates rule documentation.
|
|
|
|
#
|
|
|
|
function pmd_ci_build_run() {
|
2021-04-15 15:26:33 +02:00
|
|
|
local mvn_profiles="sign,generate-rule-docs"
|
2020-11-13 20:34:37 +01:00
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
if pmd_ci_maven_isReleaseBuild; then
|
|
|
|
pmd_ci_log_info "This is a release build"
|
2020-11-13 20:34:37 +01:00
|
|
|
mvn_profiles="${mvn_profiles},pmd-release"
|
|
|
|
else
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_info "This is a snapshot build"
|
2020-11-13 20:34:37 +01:00
|
|
|
fi
|
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
./mvnw clean deploy -P${mvn_profiles} --show-version --errors --batch-mode --no-transfer-progress ${PMD_MAVEN_EXTRA_OPTS}
|
2020-11-13 20:34:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Deploys the binary distribution
|
|
|
|
#
|
|
|
|
function pmd_ci_deploy_build_artifacts() {
|
2020-11-11 22:56:02 +01:00
|
|
|
# Deploy to sourceforge files
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_sourceforge_uploadFile "${PMD_CI_MAVEN_PROJECT_VERSION}" "pmd-dist/target/pmd-bin-${PMD_CI_MAVEN_PROJECT_VERSION}.zip"
|
|
|
|
pmd_ci_sourceforge_uploadFile "${PMD_CI_MAVEN_PROJECT_VERSION}" "pmd-dist/target/pmd-src-${PMD_CI_MAVEN_PROJECT_VERSION}.zip"
|
2020-11-10 22:26:26 +01:00
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
if pmd_ci_maven_isReleaseBuild; then
|
2020-11-13 20:34:37 +01:00
|
|
|
# create a draft github release
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_gh_releases_createDraftRelease "${PMD_CI_TAG}" "$(git rev-list -n 1 ${PMD_CI_TAG})"
|
2020-11-13 20:34:37 +01:00
|
|
|
GH_RELEASE="$RESULT"
|
2020-11-10 22:26:26 +01:00
|
|
|
|
2020-11-13 20:34:37 +01:00
|
|
|
# Deploy to github releases
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_gh_releases_uploadAsset "$GH_RELEASE" "pmd-dist/target/pmd-bin-${PMD_CI_MAVEN_PROJECT_VERSION}.zip"
|
|
|
|
pmd_ci_gh_releases_uploadAsset "$GH_RELEASE" "pmd-dist/target/pmd-src-${PMD_CI_MAVEN_PROJECT_VERSION}.zip"
|
2020-11-13 20:34:37 +01:00
|
|
|
fi
|
2020-11-11 22:56:02 +01:00
|
|
|
}
|
|
|
|
|
2020-11-13 20:34:37 +01:00
|
|
|
#
|
|
|
|
# Builds and uploads the documentation site
|
|
|
|
#
|
2020-11-12 10:17:44 +01:00
|
|
|
function pmd_ci_build_and_upload_doc() {
|
|
|
|
pmd_doc_generate_jekyll_site
|
|
|
|
pmd_doc_create_archive
|
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_sourceforge_uploadFile "${PMD_CI_MAVEN_PROJECT_VERSION}" "docs/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}.zip"
|
|
|
|
if pmd_ci_maven_isReleaseBuild; then
|
|
|
|
pmd_ci_gh_releases_uploadAsset "$GH_RELEASE" "docs/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}.zip"
|
2020-11-13 20:34:37 +01:00
|
|
|
fi
|
2020-11-12 10:17:44 +01:00
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
# Deploy doc to https://docs.pmd-code.org/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}/
|
|
|
|
pmd_code_uploadDocumentation "${PMD_CI_MAVEN_PROJECT_VERSION}" "docs/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}.zip"
|
|
|
|
# Deploy javadoc to https://docs.pmd-code.org/apidocs/*/${PMD_CI_MAVEN_PROJECT_VERSION}/
|
|
|
|
pmd_code_uploadJavadoc "${PMD_CI_MAVEN_PROJECT_VERSION}" "$(pwd)"
|
2020-11-12 10:17:44 +01:00
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
if [ pmd_ci_maven_isSnapshotBuild && "${PMD_CI_BRANCH}" = "master" ]; then
|
2020-11-13 20:34:37 +01:00
|
|
|
# only for snapshot builds from branch master
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_code_createSymlink "${PMD_CI_MAVEN_PROJECT_VERSION}" "snapshot"
|
2020-11-12 10:17:44 +01:00
|
|
|
|
2020-11-13 20:34:37 +01:00
|
|
|
# update github pages https://pmd.github.io/pmd/
|
|
|
|
pmd_doc_publish_to_github_pages
|
|
|
|
# rsync site to https://pmd.sourceforge.io/snapshot
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_sourceforge_rsyncSnapshotDocumentation "${PMD_CI_MAVEN_PROJECT_VERSION}" "snapshot"
|
2020-11-13 20:34:37 +01:00
|
|
|
fi
|
2020-11-12 10:17:44 +01:00
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
if pmd_ci_maven_isReleaseBuild; then
|
|
|
|
# documentation is already uploaded to https://docs.pmd-code.org/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}
|
2020-11-13 20:34:37 +01:00
|
|
|
# we only need to setup symlinks for the released version
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_code_createSymlink "${PMD_CI_MAVEN_PROJECT_VERSION}" "latest"
|
2020-11-13 20:34:37 +01:00
|
|
|
# remove old doc and point to the new version
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_code_removeDocumentation "${PMD_CI_MAVEN_PROJECT_VERSION}-SNAPSHOT"
|
|
|
|
pmd_code_createSymlink "${PMD_CI_MAVEN_PROJECT_VERSION}" "${PMD_CI_MAVEN_PROJECT_VERSION}-SNAPSHOT"
|
2020-11-13 20:34:37 +01:00
|
|
|
# remove old javadoc
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_code_removeJavadoc "${PMD_CI_MAVEN_PROJECT_VERSION}-SNAPSHOT"
|
2020-11-13 20:34:37 +01:00
|
|
|
|
|
|
|
# updating github release text
|
2020-12-12 11:29:36 +01:00
|
|
|
rm -f .bundle/config
|
|
|
|
bundle config set --local path vendor/bundle
|
|
|
|
bundle config set --local with release_notes_preprocessing
|
|
|
|
bundle install
|
2020-11-13 20:34:37 +01:00
|
|
|
# renders, and skips the first 6 lines - the Jekyll front-matter
|
|
|
|
local rendered_release_notes=$(bundle exec .ci/render_release_notes.rb docs/pages/release_notes.md | tail -n +6)
|
2021-04-15 15:26:33 +02:00
|
|
|
local release_name="PMD ${PMD_CI_MAVEN_PROJECT_VERSION} ($(date -u +%d-%B-%Y))"
|
|
|
|
pmd_ci_gh_releases_updateRelease "$GH_RELEASE" "$release_name" "$rendered_release_notes"
|
|
|
|
pmd_ci_sourceforge_uploadReleaseNotes "${PMD_CI_MAVEN_PROJECT_VERSION}" "${rendered_release_notes}"
|
2020-11-13 20:34:37 +01:00
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
# updates https://pmd.github.io/latest/ and https://pmd.github.io/pmd-${PMD_CI_MAVEN_PROJECT_VERSION}
|
2020-11-13 20:34:37 +01:00
|
|
|
publish_release_documentation_github
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_sourceforge_rsyncSnapshotDocumentation "${PMD_CI_MAVEN_PROJECT_VERSION}" "pmd-${PMD_CI_MAVEN_PROJECT_VERSION}"
|
2020-11-13 20:34:37 +01:00
|
|
|
fi
|
2020-11-11 22:56:02 +01:00
|
|
|
}
|
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
build
|
2020-11-11 22:56:02 +01:00
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
exit 0
|