[ci] Add apex projects for regression testing
Refs #2693 Dangerfile is copied from pmd/7.0.x and adjusted slightly: autogen is used now for both branches again.
This commit is contained in:
parent
59b36b6185
commit
fbcfebd1a9
@ -1,10 +1,19 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="All Java Rules"
|
||||
<ruleset name="All Regression Rules"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||
<description>Every java rule in PMD which is used for the regression tests with pmdtester</description>
|
||||
<description>Every apex and java rule in PMD which is used for the regression tests with pmdtester</description>
|
||||
|
||||
<rule ref="category/apex/bestpractices.xml" />
|
||||
<rule ref="category/apex/codestyle.xml" />
|
||||
<rule ref="category/apex/design.xml" />
|
||||
<rule ref="category/apex/documentation.xml" />
|
||||
<rule ref="category/apex/errorprone.xml" />
|
||||
<rule ref="category/apex/multithreading.xml" />
|
||||
<rule ref="category/apex/performance.xml" />
|
||||
<rule ref="category/apex/security.xml" />
|
||||
|
||||
<rule ref="category/java/bestpractices.xml" />
|
||||
<rule ref="category/java/codestyle.xml" />
|
@ -145,4 +145,26 @@ EOF
|
||||
<tag>jdk-11+28</tag>
|
||||
<src-subpath>src/java.base</src-subpath>
|
||||
</project>
|
||||
|
||||
<project>
|
||||
<name>Schedul-o-matic-9000</name>
|
||||
<type>git</type>
|
||||
<connection>https://github.com/SalesforceLabs/Schedul-o-matic-9000</connection>
|
||||
<tag>6b1229ba43b38931fbbab5924bc9b9611d19a786</tag>
|
||||
</project>
|
||||
|
||||
<project>
|
||||
<name>fflib-apex-common</name>
|
||||
<type>git</type>
|
||||
<connection>https://github.com/apex-enterprise-patterns/fflib-apex-common</connection>
|
||||
<tag>991bcbc20b017935405499c115309cadd1f8af9b</tag>
|
||||
</project>
|
||||
|
||||
<project>
|
||||
<name>apex-link</name>
|
||||
<type>git</type>
|
||||
<connection>https://github.com/nawforce/apex-link</connection>
|
||||
<tag>v2.3.0</tag>
|
||||
<src-subpath>samples</src-subpath>
|
||||
</project>
|
||||
</projectlist>
|
||||
|
@ -48,7 +48,7 @@ function regression_tester_uploadBaseline() {
|
||||
--mode single \
|
||||
--local-git-repo ./pmd \
|
||||
--patch-branch "${baseline_branch}" \
|
||||
--patch-config ./pmd/.ci/files/all-java.xml \
|
||||
--patch-config ./pmd/.ci/files/all-regression-rules.xml \
|
||||
--list-of-project ./pmd/.ci/files/project-list.xml --html-flag \
|
||||
--error-recovery
|
||||
pushd target/reports || { echo "Directory 'target/reports' doesn't exist"; exit 1; }
|
||||
|
108
Dangerfile
108
Dangerfile
@ -1,26 +1,68 @@
|
||||
require 'pmdtester'
|
||||
require 'time'
|
||||
require 'logger'
|
||||
require 'fileutils'
|
||||
|
||||
@logger = Logger.new(STDOUT)
|
||||
|
||||
def get_args(base_branch, autogen = TRUE, patch_config = './pmd/.ci/files/all-regression-rules.xml')
|
||||
['--local-git-repo', './pmd',
|
||||
'--list-of-project', './pmd/.ci/files/project-list.xml',
|
||||
'--base-branch', base_branch,
|
||||
'--patch-branch', 'HEAD',
|
||||
'--patch-config', patch_config,
|
||||
'--mode', 'online',
|
||||
autogen ? '--auto-gen-config' : '--filter-with-patch-config',
|
||||
'--keep-reports',
|
||||
'--error-recovery',
|
||||
'--baseline-download-url', 'https://pmd-code.org/pmd-regression-tester/',
|
||||
# '--debug',
|
||||
]
|
||||
end
|
||||
|
||||
def run_pmdtester
|
||||
Dir.chdir('..') do
|
||||
branch_name = "#{ENV['PMD_CI_BRANCH']}"
|
||||
argv = ['--local-git-repo', './pmd',
|
||||
'--list-of-project', './pmd/.ci/files/project-list.xml',
|
||||
'--base-branch', branch_name,
|
||||
'--patch-branch', 'HEAD',
|
||||
'--patch-config', './pmd/.ci/files/all-java.xml',
|
||||
'--mode', 'online',
|
||||
'--auto-gen-config',
|
||||
'--error-recovery',
|
||||
'--baseline-download-url', 'https://pmd-code.org/pmd-regression-tester/',
|
||||
#'--debug',
|
||||
]
|
||||
begin
|
||||
@summary = PmdTester::Runner.new(argv).run
|
||||
upload_report
|
||||
@base_branch = ENV['PMD_CI_BRANCH']
|
||||
@logger.info "\n\n--------------------------------------"
|
||||
@logger.info "Run against PR base #{@base_branch}"
|
||||
@summary = PmdTester::Runner.new(get_args(@base_branch)).run
|
||||
|
||||
unless Dir.exist?('target/reports/diff')
|
||||
message("No regression tested rules have been changed.", sticky: true)
|
||||
return
|
||||
end
|
||||
|
||||
# move the generated report out of the way
|
||||
FileUtils.mv 'target/reports/diff', 'target/diff1'
|
||||
message1 = create_message
|
||||
|
||||
# run against master branch (if the PR is not already against master)
|
||||
unless ENV['PMD_CI_BRANCH'] == 'master'
|
||||
@base_branch = 'master'
|
||||
@logger.info "\n\n--------------------------------------"
|
||||
@logger.info "Run against #{@base_branch}"
|
||||
@summary = PmdTester::Runner.new(get_args(@base_branch)).run
|
||||
|
||||
# move the generated report out of the way
|
||||
FileUtils.mv 'target/reports/diff', 'target/diff2'
|
||||
message2 = create_message
|
||||
end
|
||||
|
||||
report_url = upload_report
|
||||
|
||||
if report_url
|
||||
message1 += "[Full report](#{report_url}/diff1/index.html)"
|
||||
# set value of sticky to true and the message is kept after new commits are submitted to the PR
|
||||
message(message1, sticky: true)
|
||||
|
||||
if message2
|
||||
message2 += "[Full report](#{report_url}/diff2/index.html)"
|
||||
# set value of sticky to true and the message is kept after new commits are submitted to the PR
|
||||
message(message2, sticky: true)
|
||||
end
|
||||
end
|
||||
|
||||
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}"
|
||||
@ -28,34 +70,34 @@ def run_pmdtester
|
||||
end
|
||||
end
|
||||
|
||||
def upload_report
|
||||
Dir.chdir('target/reports') do
|
||||
tar_filename = "pr-#{ENV['PMD_CI_PULL_REQUEST_NUMBER']}-diff-report-#{Time.now.strftime("%Y-%m-%dT%H-%M-%SZ")}.tar.gz"
|
||||
unless Dir.exist?('diff/')
|
||||
message("No java rules are changed!", sticky: true)
|
||||
return
|
||||
end
|
||||
def create_message
|
||||
"Compared to #{@base_branch}:\n"\
|
||||
"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"
|
||||
end
|
||||
|
||||
`tar czf #{tar_filename} diff/`
|
||||
def upload_report
|
||||
Dir.chdir('target') do
|
||||
tar_filename = "pr-#{ENV['PMD_CI_PULL_REQUEST_NUMBER']}-diff-report-#{Time.now.strftime("%Y-%m-%dT%H-%M-%SZ")}.tar.gz"
|
||||
|
||||
`tar czf #{tar_filename} diff1/ diff2/`
|
||||
tar_size = (10 * File.size(tar_filename) / 1024 / 1024)/10.0
|
||||
@logger.info "Uploading file #{tar_filename} (#{tar_size}mb) now..."
|
||||
report_url = `curl -u #{ENV['PMD_CI_CHUNK_TOKEN']} -T #{tar_filename} https://chunk.io`
|
||||
if $?.success?
|
||||
report_url.chomp!
|
||||
@logger.info "Successfully uploaded #{tar_filename} to #{report_url}"
|
||||
|
||||
# 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" \
|
||||
"[Full report](#{report_url.chomp}/diff/index.html)", sticky: true)
|
||||
report_url
|
||||
else
|
||||
@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.")
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user