105 lines
3.6 KiB
PHP
105 lines
3.6 KiB
PHP
#
|
|
# The functions here require the following scripts:
|
|
# inc/logger.inc
|
|
# inc/install-openjdk.inc
|
|
#
|
|
# The functions here require the following environment variables:
|
|
# PMD_SF_USER
|
|
# PMD_CI_BRANCH
|
|
#
|
|
# DANGER_GITHUB_API_TOKEN
|
|
# PMD_CI_CHUNK_TOKEN
|
|
|
|
function regression_tester_setup_ci() {
|
|
log_info "Install openjdk8 for pmd-regression-tests"
|
|
install_openjdk 8
|
|
|
|
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
|
|
|
|
if hash "bundler" 2>/dev/null; then
|
|
log_debug "Bundler is already installed"
|
|
else
|
|
log_info "Installing bundler..."
|
|
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
|
|
}
|
|
|
|
#
|
|
# Generate a new baseline and upload it to pmd-code.org
|
|
#
|
|
function regression_tester_uploadBaseline() {
|
|
log_debug "$FUNCNAME branch=${PMD_CI_BRANCH}"
|
|
local pmdcodeUrl="https://pmd-code.org/pmd-regression-tester/"
|
|
|
|
log_info "Generating and uploading baseline for pmdtester..."
|
|
pushd ..
|
|
bundle config --local gemfile pmd/Gemfile
|
|
bundle config set --local path pmd/vendor/bundle
|
|
bundle exec pmdtester \
|
|
--mode single \
|
|
--local-git-repo ./pmd \
|
|
--patch-branch ${PMD_CI_BRANCH:-$PMD_CI_TAG} \
|
|
--patch-config ./pmd/.ci/files/all-java.xml \
|
|
--list-of-project ./pmd/.ci/files/project-list.xml --html-flag \
|
|
--error-recovery
|
|
cd target/reports
|
|
BRANCH_FILENAME="${PMD_CI_BRANCH:-$PMD_CI_TAG}"
|
|
BRANCH_FILENAME="${BRANCH_FILENAME/\//_}"
|
|
zip -q -r ${BRANCH_FILENAME}-baseline.zip ${BRANCH_FILENAME}/
|
|
# ssh-key for pmd-code.org is setup already by pmd_ci_setup_ssh
|
|
scp ${BRANCH_FILENAME}-baseline.zip pmd@pmd-code.org:/httpdocs/pmd-regression-tester/
|
|
log_success "Successfully uploaded ${BRANCH_FILENAME}-baseline.zip to ${pmdcodeUrl}"
|
|
popd
|
|
}
|
|
|
|
#
|
|
# Execute danger, which executes pmd-regression-tester (via Dangerfile).
|
|
#
|
|
# Note: this function always succeeds, even if the danger fails.
|
|
# In that case, just a error logging is provided.
|
|
#
|
|
function regression_tester_executeDanger() {
|
|
log_debug "$FUNCNAME"
|
|
|
|
local errexitstate="$(shopt -po errexit)"
|
|
set +e # disable errexit
|
|
(
|
|
# This handler is called if any command fails
|
|
function danger_failed() {
|
|
log_error "Error while executing danger/pmd-regression-tester"
|
|
}
|
|
|
|
# exit subshell after trap
|
|
set -e
|
|
trap danger_failed ERR
|
|
|
|
# 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}
|
|
log_debug "Created local branch ${PMD_CI_BRANCH}"
|
|
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
|
|
|
|
log_info "Running danger on branch ${PMD_CI_BRANCH}"
|
|
bundle exec danger --verbose
|
|
log_success "Executing danger successfully"
|
|
)
|
|
# restore errexit state
|
|
eval "$errexitstate"
|
|
}
|