2018-08-02 22:35:09 +08:00
|
|
|
require 'pmdtester'
|
2018-07-23 23:06:46 +08:00
|
|
|
require 'time'
|
|
|
|
require 'logger'
|
|
|
|
|
|
|
|
@logger = Logger.new(STDOUT)
|
|
|
|
|
|
|
|
def run_pmdtester
|
|
|
|
Dir.chdir('..') do
|
2020-11-24 16:15:06 +01:00
|
|
|
branch_name = "#{ENV['PMD_CI_BRANCH']}"
|
2020-10-10 17:25:03 +02:00
|
|
|
argv = ['--local-git-repo', './pmd',
|
2020-11-12 13:11:56 +01:00
|
|
|
'--list-of-project', './pmd/.ci/files/project-list.xml',
|
2020-11-24 16:15:06 +01:00
|
|
|
'--base-branch', branch_name,
|
2020-10-09 11:03:25 +02:00
|
|
|
'--patch-branch', 'HEAD',
|
2020-11-12 13:11:56 +01:00
|
|
|
'--patch-config', './pmd/.ci/files/all-java.xml',
|
2020-10-09 11:03:25 +02:00
|
|
|
'--mode', 'online',
|
|
|
|
'--auto-gen-config',
|
2020-11-25 11:26:16 +01:00
|
|
|
'--error-recovery',
|
|
|
|
'--baseline-download-url', 'https://pmd-code.org/pmd-regression-tester/',
|
2021-01-08 16:09:22 +01:00
|
|
|
'--debug',
|
2020-10-09 11:03:25 +02:00
|
|
|
]
|
2018-09-10 21:16:42 +08:00
|
|
|
begin
|
2020-11-25 11:26:16 +01:00
|
|
|
@summary = PmdTester::Runner.new(argv).run
|
2018-09-10 21:16:42 +08:00
|
|
|
upload_report
|
|
|
|
rescue StandardError => e
|
|
|
|
warn("Running pmdtester failed, this message is mainly used to remind the maintainers of PMD.")
|
|
|
|
@logger.error "Running pmdtester failed: #{e.inspect}"
|
|
|
|
end
|
2018-07-23 23:06:46 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def upload_report
|
|
|
|
Dir.chdir('target/reports') do
|
2020-11-12 13:11:56 +01:00
|
|
|
tar_filename = "pr-#{ENV['PMD_CI_PULL_REQUEST_NUMBER']}-diff-report-#{Time.now.strftime("%Y-%m-%dT%H-%M-%SZ")}.tar"
|
2018-07-23 23:06:46 +08:00
|
|
|
unless Dir.exist?('diff/')
|
|
|
|
message("No java rules are changed!", sticky: true)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
`tar -cf #{tar_filename} diff/`
|
2020-11-12 13:11:56 +01:00
|
|
|
report_url = `curl -u #{ENV['PMD_CI_CHUNK_TOKEN']} -T #{tar_filename} https://chunk.io`
|
2019-01-20 20:17:23 +01:00
|
|
|
if $?.success?
|
2021-01-08 15:59:33 +01:00
|
|
|
@logger.info "Successfully uploaded #{tar_filename} to #{report_url}"
|
2018-07-23 23:06:46 +08:00
|
|
|
|
2020-11-25 11:26:16 +01:00
|
|
|
# set value of sticky to true and the message is kept after new commits are submitted to the PR
|
|
|
|
message("This changeset " \
|
|
|
|
"changes #{@summary[:violations][:changed]} violations,\n" \
|
|
|
|
"introduces #{@summary[:violations][:new]} new violations, " \
|
|
|
|
"#{@summary[:errors][:new]} new errors and " \
|
|
|
|
"#{@summary[:configerrors][:new]} new configuration errors,\n" \
|
|
|
|
"removes #{@summary[:violations][:removed]} violations, "\
|
|
|
|
"#{@summary[:errors][:removed]} errors and " \
|
|
|
|
"#{@summary[:configerrors][:removed]} configuration errors.\n" \
|
2019-01-20 20:17:23 +01:00
|
|
|
"[Full report](#{report_url.chomp}/diff/index.html)", sticky: true)
|
|
|
|
else
|
2018-07-23 23:06:46 +08:00
|
|
|
@logger.error "Error while uploading #{tar_filename} to chunk.io: #{report_url}"
|
|
|
|
warn("Uploading the diff report failed, this message is mainly used to remind the maintainers of PMD.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Perform regression testing
|
2020-11-12 13:11:56 +01:00
|
|
|
run_pmdtester
|
2018-07-23 23:06:46 +08:00
|
|
|
|
|
|
|
# vim: syntax=ruby
|