2021-04-15 15:26:33 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
MODULE="pmd-doc"
|
|
|
|
SCRIPT_INCLUDES="log.bash openjdk.bash"
|
|
|
|
# shellcheck source=inc/fetch_ci_scripts.bash
|
|
|
|
source "$(dirname "$0")/inc/fetch_ci_scripts.bash" && fetch_ci_scripts
|
|
|
|
|
2020-11-12 11:54:51 +01:00
|
|
|
#
|
|
|
|
# The functions here require the following environment variables:
|
|
|
|
# PMD_SF_USER
|
|
|
|
# PMD_CI_BRANCH
|
2020-11-13 14:27:26 +01:00
|
|
|
#
|
|
|
|
# DANGER_GITHUB_API_TOKEN
|
|
|
|
# PMD_CI_CHUNK_TOKEN
|
2020-11-12 11:54:51 +01:00
|
|
|
|
2020-11-12 13:11:56 +01:00
|
|
|
function regression_tester_setup_ci() {
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_info "Install openjdk8 for pmd-regression-tests"
|
|
|
|
pmd_ci_openjdk_install_adoptopenjdk 8
|
2020-11-12 13:11:56 +01:00
|
|
|
|
2020-11-13 14:27:26 +01:00
|
|
|
gpg --batch --yes --decrypt --passphrase="GnxdjywUEPveyCD1RLiTd7t8CImnefYr" \
|
|
|
|
--output .ci/files/public-env .ci/files/public-env.gpg
|
|
|
|
source .ci/files/public-env >/dev/null 2>&1
|
|
|
|
rm .ci/files/public-env
|
|
|
|
|
2020-11-12 13:11:56 +01:00
|
|
|
if hash "bundler" 2>/dev/null; then
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_debug "Bundler is already installed"
|
2020-11-12 13:11:56 +01:00
|
|
|
else
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_info "Installing bundler..."
|
2020-11-12 13:11:56 +01:00
|
|
|
gem install bundler
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm -f .bundle/config
|
|
|
|
bundle config set --local path vendor/bundle
|
|
|
|
bundle config set --local with release_notes_preprocessing
|
|
|
|
bundle install
|
|
|
|
}
|
|
|
|
|
2020-11-12 11:54:51 +01:00
|
|
|
#
|
2021-01-08 15:38:47 +01:00
|
|
|
# Generate a new baseline and upload it to pmd-code.org
|
2020-11-12 11:54:51 +01:00
|
|
|
#
|
|
|
|
function regression_tester_uploadBaseline() {
|
2020-11-24 16:15:06 +01:00
|
|
|
local pmdcodeUrl="https://pmd-code.org/pmd-regression-tester/"
|
2021-01-08 15:50:42 +01:00
|
|
|
local baseline_branch="${PMD_CI_BRANCH:-$PMD_CI_TAG}"
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_debug "$FUNCNAME branch=${baseline_branch}"
|
2020-11-12 11:54:51 +01:00
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_info "Generating and uploading baseline for pmdtester (${baseline_branch})..."
|
2021-01-08 15:38:47 +01:00
|
|
|
pushd ..
|
2021-01-08 15:50:42 +01:00
|
|
|
rm -f .bundle/config
|
|
|
|
bundle config set --local gemfile pmd/Gemfile
|
2021-01-08 15:38:47 +01:00
|
|
|
bundle exec pmdtester \
|
|
|
|
--mode single \
|
|
|
|
--local-git-repo ./pmd \
|
2021-01-08 15:50:42 +01:00
|
|
|
--patch-branch ${baseline_branch} \
|
2021-01-08 15:38:47 +01:00
|
|
|
--patch-config ./pmd/.ci/files/all-java.xml \
|
|
|
|
--list-of-project ./pmd/.ci/files/project-list.xml --html-flag \
|
2021-01-16 10:11:22 +01:00
|
|
|
--error-recovery
|
2021-01-08 15:50:42 +01:00
|
|
|
pushd target/reports
|
|
|
|
BRANCH_FILENAME="${baseline_branch/\//_}"
|
2021-01-08 15:38:47 +01:00
|
|
|
zip -q -r ${BRANCH_FILENAME}-baseline.zip ${BRANCH_FILENAME}/
|
2021-04-15 15:26:33 +02:00
|
|
|
# ssh-key for pmd-code.org is setup already by pmd_ci_setup_secrets_ssh
|
2021-01-08 15:38:47 +01:00
|
|
|
scp ${BRANCH_FILENAME}-baseline.zip pmd@pmd-code.org:/httpdocs/pmd-regression-tester/
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_success "Successfully uploaded ${BRANCH_FILENAME}-baseline.zip to ${pmdcodeUrl}"
|
2021-01-08 15:38:47 +01:00
|
|
|
popd
|
2021-01-08 15:50:42 +01:00
|
|
|
popd
|
2020-11-12 11:54:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Execute danger, which executes pmd-regression-tester (via Dangerfile).
|
|
|
|
#
|
|
|
|
function regression_tester_executeDanger() {
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_debug "$FUNCNAME"
|
2020-11-12 11:54:51 +01:00
|
|
|
|
2021-01-08 15:59:33 +01:00
|
|
|
# Create a corresponding remote branch locally
|
|
|
|
if ! git show-ref --verify --quiet refs/heads/${PMD_CI_BRANCH}; then
|
|
|
|
git fetch --no-tags --depth=1 origin +refs/heads/${PMD_CI_BRANCH}:refs/remotes/origin/${PMD_CI_BRANCH}
|
|
|
|
git branch ${PMD_CI_BRANCH} origin/${PMD_CI_BRANCH}
|
2021-04-15 16:44:17 +02:00
|
|
|
pmd_ci_log_debug "Created local branch ${PMD_CI_BRANCH}"
|
2021-01-08 15:59:33 +01:00
|
|
|
fi
|
|
|
|
# Fetch more commits of the PR for danger and regression tester
|
|
|
|
git fetch --no-tags --depth=50 origin +$(git rev-parse HEAD^2):
|
|
|
|
# Fetch more commits from master branch for regression tester
|
|
|
|
if [[ "${PMD_CI_BRANCH}" != "master" ]]; then
|
|
|
|
git fetch --no-tags --depth=50 origin +master:
|
|
|
|
git branch master origin/master
|
|
|
|
fi
|
2020-11-12 11:54:51 +01:00
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_info "Running danger on branch ${PMD_CI_BRANCH}"
|
2021-01-08 15:59:33 +01:00
|
|
|
bundle exec danger --verbose
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_success "Executed danger successfully"
|
2020-11-12 11:54:51 +01:00
|
|
|
}
|