diff --git a/.travis.yml b/.travis.yml index 2bdc89ab..3cd379e9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: objective-c osx_image: xcode8 +rvm: 2.0.0 env: - DESTINATION='platform=iOS Simulator,name=iPad Air' @@ -19,8 +20,13 @@ env: - DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' +install: + - brew update && brew upgrade swiftlint + - bundle install + script: - set -o pipefail && xcodebuild -scheme DeviceKit -destination "$DESTINATION" test | xcpretty + - bundle exec danger deploy: provider: script diff --git a/Dangerfile b/Dangerfile new file mode 100755 index 00000000..c385537b --- /dev/null +++ b/Dangerfile @@ -0,0 +1,52 @@ +# Source: https://gist.github.com/candostdagdeviren/e49271e6a4b80f93f3193af89d10f4b1 + +# PR is a work in progress and shouldn't be merged yet +warn "PR is classed as Work in Progress" if github.pr_title.include? "[WIP]" + +# Warn when there is a big PR +warn "Big PR, consider splitting into smaller" if git.lines_of_code > 500 + +# Ensure a clean commits history +if git.commits.any? { |c| c.message =~ /^Merge branch '#{github.branch_for_base}'/ } + fail "Please rebase to get rid of the merge commits in this PR" +end + +# Mainly to encourage writing up some reasoning about the PR, rather than +# just leaving a title +if github.pr_body.length < 5 + fail "Please provide a summary in the Pull Request description" +end + +# If these are all empty something has gone wrong, better to raise it in a comment +if git.modified_files.empty? && git.added_files.empty? && git.deleted_files.empty? + fail "This PR has no changes at all, this is likely an issue during development." +end + +has_app_changes = !git.modified_files.grep(/ProjectName/).empty? +has_test_changes = !git.modified_files.grep(/ProjectNameTests/).empty? + +# If changes are more than 10 lines of code, tests need to be updated too +if has_app_changes && !has_test_changes && git.lines_of_code > 10 + fail("Tests were not updated", sticky: false) +end + +# Info.plist file shouldn't change often. Leave warning if it changes. +is_plist_change = git.modified_files.sort == ["ProjectName/Info.plist"].sort + +if !is_plist_change + warn "Plist changed, don't forget to localize your plist values" +end + +podfile_updated = !git.modified_files.grep(/Podfile/).empty? + +# Leave warning, if Podfile changes +if podfile_updated + warn "The `Podfile` was updated" +end + +# This is swiftlint plugin. More info: https://github.com/ashfurrow/danger-swiftlint +# +# This lints all Swift files and leave comments in PR if +# there is any issue with linting +swiftlint.lint_files +swiftlint.lint_files inline_mode: true diff --git a/DeviceKit.xcodeproj/project.pbxproj b/DeviceKit.xcodeproj/project.pbxproj index a683c637..b2c5e375 100644 --- a/DeviceKit.xcodeproj/project.pbxproj +++ b/DeviceKit.xcodeproj/project.pbxproj @@ -24,6 +24,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 6DAAE66C1EDDC53800074892 /* Dangerfile */ = {isa = PBXFileReference; lastKnownFileType = text; path = Dangerfile; sourceTree = ""; }; + 6DAAE66D1EDDF06700074892 /* Gemfile */ = {isa = PBXFileReference; lastKnownFileType = text; path = Gemfile; sourceTree = ""; }; 951E3A0D1C61549400261610 /* Device.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Device.swift; path = Source/Device.swift; sourceTree = ""; }; 951E3A0E1C61549400261610 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Source/Info.plist; sourceTree = ""; }; 954977FA1E748DC600D6FAEB /* push.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; name = push.sh; path = Scripts/push.sh; sourceTree = ""; }; @@ -97,6 +99,8 @@ 957D18261C28C1F30067D203 /* DeviceKit.podspec */, 957D18271C28C1FC0067D203 /* .travis.yml */, 95C7E84D1C6130DB00B0189E /* .swiftlint.yml */, + 6DAAE66C1EDDC53800074892 /* Dangerfile */, + 6DAAE66D1EDDF06700074892 /* Gemfile */, 95C7E83F1C61239D00B0189E /* .gitignore */, 95CBDB701BFD2B5F0065FC66 /* Products */, ); diff --git a/Gemfile b/Gemfile new file mode 100755 index 00000000..4db57759 --- /dev/null +++ b/Gemfile @@ -0,0 +1,6 @@ +source 'https://rubygems.org' + +gem 'xcpretty' +gem 'cocoapods' +gem 'danger' +gem 'danger-swiftlint'