Skip to content

Commit

Permalink
Merge pull request #4 from mayckonx/DangerExample
Browse files Browse the repository at this point in the history
Added danger to CI process
  • Loading branch information
mayckonx authored Mar 11, 2019
2 parents 16c7603 + 680a306 commit 9e40c96
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ xcode_project: MBSPasswordView.xcodeproj
before_install:
- rvm install 2.4.1
- gem install slather --no-ri --no-rdoc
- gem install danger --no-ri --no-rdoc
- gem install danger-swiftlint --no-ri --no-rdoc

script:
- xcodebuild test -project MBSPasswordView.xcodeproj -scheme MBSPasswordView -destination 'platform=iOS Simulator,name=iPhone X,OS=11.4'
Expand Down
46 changes: 34 additions & 12 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@

# Make it more obvious that a PR is a work in progress and shouldn't be merged yet
warn("PR is classed as Work in Progress", sticky: true) if github.pr_title.include? "[WIP]"
# 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", sticky: true) if git.lines_of_code > 500
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

## Let's check if there are any changes in the project folder
has_app_changes = !git.modified_files.grep(/ProjectName/).empty?
## Then, we should check if tests are updated
has_test_changes = !git.modified_files.grep(/ProjectNameTests/).empty?
## Finally, let's combine them and put extra condition
## for changed number of lines of code
if has_app_changes && !has_test_changes && git.lines_of_code > 20

# 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

# SwiftLint
swiftlint.config_file = '.swiftlint.yml'
swiftlint.lint_files inline_mode: true
# 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

# 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 inline_mode: true
2 changes: 1 addition & 1 deletion Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extension ViewController: MBSPasswordDelegate {
let alert = UIAlertController(title: "Success", message: "Password Validated!", preferredStyle: .alert)
self.present(alert, animated: true, completion: nil)
}
func passwordFromBiometrics(_ result: Result<[String]>) {
func passwordFromBiometrics(_ result: MBSPasswordResult<[String]>) {
switch result {
case .success(let password):
print("Authenticated by password and biometrics. Password:\(password)")
Expand Down
4 changes: 2 additions & 2 deletions MBSPasswordView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = ARMU3CM3A3;
DEVELOPMENT_TEAM = HBJY6RMJ3R;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -707,7 +707,7 @@
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = ARMU3CM3A3;
DEVELOPMENT_TEAM = HBJY6RMJ3R;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand Down

0 comments on commit 9e40c96

Please sign in to comment.