perform OSSCheck in Dangerfile

This commit is contained in:
JP Simard
2016-12-24 15:11:16 -08:00
parent 6a417360e4
commit d4b4b007b9
2 changed files with 51 additions and 3 deletions
+1
View File
@@ -48,6 +48,7 @@ SwiftLint.pkg
SwiftLintFramework.framework.zip
benchmark_*
portable_swiftlint.zip
osscheck/
# SPM
.build
+50 -3
View File
@@ -1,5 +1,5 @@
# Warn when there is a big PR
warn("Big PR") if git.lines_of_code > 500
warn('Big PR') if git.lines_of_code > 500
# Sometimes its a README fix, or something like that - which isn't relevant for
# including in a CHANGELOG for example
@@ -7,7 +7,7 @@ has_app_changes = !git.modified_files.grep(/Source/).empty?
has_test_changes = !git.modified_files.grep(/Tests/).empty?
# Add a CHANGELOG entry for app changes
if !git.modified_files.include?("CHANGELOG.md") && has_app_changes
if !git.modified_files.include?('CHANGELOG.md') && has_app_changes
fail("Please include a CHANGELOG entry to credit yourself! \nYou can find it at [CHANGELOG.md](https://github.com/realm/SwiftLint/blob/master/CHANGELOG.md).")
markdown <<-MARKDOWN
Here's an example of your CHANGELOG entry:
@@ -22,5 +22,52 @@ end
# Non-trivial amounts of app changes without tests
if git.lines_of_code > 50 && has_app_changes && !has_test_changes
warn "This PR may need tests."
warn 'This PR may need tests.'
end
# Run OSSCheck if there were app changes
if has_app_changes
@repos = ['realm/realm-cocoa', 'jpsim/SourceKitten']
def generate_reports(clone, branch)
Dir.chdir('osscheck') do
@repos.each do |repo|
`git clone "https://github.com/#{repo}" --depth 1` if clone
repo_name = repo.partition('/').last
Dir.chdir(repo_name) do
File.open("../#{branch}_reports/#{repo_name}.txt", 'w') do |file|
file.puts `../../.build/debug/swiftlint`
end
end
end
end
end
# Prep
['osscheck/branch_reports', 'osscheck/master_reports'].each do |dir|
FileUtils.mkdir_p(dir)
end
# Build branch
`swift build`
# Generate branch reports
generate_reports(true, 'branch')
# Build master
`git checkout master`
`git pull`
`git submodule update --init --recursive`
`swift build`
# Generate master reports
generate_reports(false, 'master')
@repos.each do |repo|
repo_name = repo.partition('/').last
branch = File.read("osscheck/branch_reports/#{repo_name}.txt").split(/\n+/).reject { |c| c.empty? }
master = File.read("osscheck/master_reports/#{repo_name}.txt").split(/\n+/).reject { |c| c.empty? }
(master - branch).each do |fixed|
message "This PR fixed a violation in #{repo_name}: #{fixed}"
end
(branch - master).each do |violation|
warn "This PR introduced a violation in #{repo_name}: #{violation}"
end
end
FileUtils.rm_rf('osscheck')
end