forked from netguru/ar-localizer-view-android
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dangerfile
105 lines (86 loc) · 4.07 KB
/
Dangerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# This is an example Dangerfile containing many useful examples of what can be done with Danger
# Make sure you read every comment (#) to enjoy proper Danger setup
# Every part of this setup is optional, so pick, remove, adjust and add as you need
# You can remove the comments afterwards
# To setup Danger with repo on Github.com you need to add DANGER_GITHUB_API_TOKEN for a user to your CI secret and expose it for PRs
# To setup Danger on enterprise Github, you need to also add these environment variables:
# DANGER_GITHUB_HOST=git.corp.goodcorp.com - host that the Github is running on
# DANGER_GITHUB_API_BASE_URL=https://git.corp.goodcorp.com/api/v3 - host at which the Github API is reachable on
# To setup Danger for Slack, you need to add SLACK_API_TOKEN to your CI secrets - a token for a bot user on Slack
# Check env variable:
def envBlank?(env)
return env.nil? || env.empty?
end
def pluginEnabled?(env)
env.to_s.downcase == "true"
end
# Danger actions:
# Android Lint running and reporting:
unless envBlank?(ENV["LINT_GRADLE_TASK"]) || envBlank?(ENV["LINT_REPORT_PATH"])
# Unfortunately android_lint plugin forces lint task running, so you have to specify lint task name
# Remember to remove lint task from Bitrise
android_lint.gradle_task = ENV["LINT_GRADLE_TASK"]
android_lint.filtering = true
# Specify your exact report location
android_lint.report_file = ENV["LINT_REPORT_PATH"]
android_lint.lint(inline_mode: true)
end
if pluginEnabled?(ENV["DETEKT_ENABLED"])
# Detekt reporting:
kotlin_detekt.filtering = true
# Skip default gradle task instead you should always use `detektAll` task which
# supports multimodule setup and will run checks across whole codebase
kotlin_detekt.skip_gradle_task = true
# Specify your exact report location - for multi-module projects you should look at buildscript/detekt.gradle in NAT
# A task called detektGenerateMergedReport in there will generate a single-file report for you
kotlin_detekt.report_file = 'build/reports/detekt/detekt.xml'
kotlin_detekt.detekt(inline_mode: true)
end
# JUnit test reporting:
if pluginEnabled?(ENV["JUNIT_ENABLED"])
# JUnit just parses already existing reports
junit_tests_dir = "**/test-results/**/*.xml"
Dir[junit_tests_dir].each do |file_name|
junit.parse file_name
junit.report
end
end
# Jacoco reporting:
unless envBlank?(ENV["JACOCO_REPORT_PATH"])
# Uncomment to enforce minimum coverage of your choice, causing build fail when this is not met:
#jacoco.minimum_project_coverage_percentage = 50
#jacoco.minimum_class_coverage_percentage = 75
# Specify your exact report location
jacoco.report(ENV["JACOCO_REPORT_PATH"])
end
# Jira link commenting (based on PR title or commits messages):
unless envBlank?(ENV["JIRA_IDENTIFIERS"]) || envBlank?(ENV["JIRA_SUBDOMAIN"])
jira.check(
key: ENV["JIRA_IDENTIFIERS"].split(","), #first part of your typical task identifier, like MOB-250
url: "https://#{ENV["JIRA_SUBDOMAIN"]}.atlassian.net/browse", # put your jira subdomain in place of "netguru" or leave as is
search_title: true,
search_commits: false,
fail_on_warning: false,
report_missing: true,
skippable: true # you can skip this check by putting [no-jira] in PR's title
)
end
#Apk Analyzer
unless envBlank?(ENV["APK_PATH"])
apkanalyzer.apk_file = ENV["APK_PATH"]
apkanalyzer.file_size
apkanalyzer.method_references
end
# Notifying selected slack channel about finished build:
# get status_report text for Slack
# @return [[String]]
def slack_report
errors_count = status_report[:errors].count
warnings_count = status_report[:warnings].count
"There were #{errors_count} errors and #{warnings_count} warnings."
end
emoji = [":rocket:", ":parrot:", ":fire:", ":hammer:"].sample
unless envBlank?(ENV["SLACK_NOTIFICATION_CHANNEL"])
# Update channel to the one you want to notify
slack.notify(channel: "##{ENV["SLACK_NOTIFICATION_CHANNEL"]}", text: "Hello, a build just finished! #{emoji}\n#{slack_report}\nFind it here: #{github.pr_json['html_url']}")
end