-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
133 lines (115 loc) · 4.22 KB
/
build.gradle
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* This file was generated by the Gradle 'init' task.
*
* This is a general purpose Gradle build.
* Learn more about Gradle by exploring our samples at https://docs.gradle.org/7.5.1/samples
*/
apply plugin: 'groovy'
repositories {
mavenCentral()
mavenLocal()
maven { url 'https://repo.jenkins-ci.org/releases/' }
}
sourceSets {
main {
groovy {
srcDirs = ['src']
}
}
test {
groovy {
srcDirs = ['test']
}
}
}
dependencies {
implementation 'org.codehaus.groovy:groovy-all:2.4.21'
testImplementation 'com.lesfurets:jenkins-pipeline-unit:1.12'
testImplementation "junit:junit:4.12"
}
// Prettify the test result output.
tasks.withType(Test) {
String ANSI_BOLD_WHITE = "\u001B[0;1m"
String ANSI_RESET = "\u001B[0m"
String ANSI_BLACK = "\u001B[30m"
String ANSI_RED = "\u001B[31m"
String ANSI_GREEN = "\u001B[32m"
String ANSI_YELLOW = "\u001B[33m"
String ANSI_BLUE = "\u001B[34m"
String ANSI_PURPLE = "\u001B[35m"
String ANSI_CYAN = "\u001B[36m"
String ANSI_WHITE = "\u001B[37m"
String CHECK_MARK = "\u2713"
String NEUTRAL_FACE = "\u0CA0_\u0CA0"
String X_MARK = "\u274C"
// Used to collect data to create a markdown file with the test results after
// the suite has finished.
// The GitHub action uses this markdown file to create the job summary.
// https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/
String resultsFilePath = "build/test-results.md"
String resultsFileContent = ""
dependsOn cleanTest
testLogging {
outputs.upToDateWhen {false}
lifecycle.events = []
}
beforeSuite { suite ->
if(suite.parent != null && suite.className != null){
out.println(ANSI_BOLD_WHITE + suite.name + ANSI_RESET )
resultsFileContent += "#### " + suite.name + "\n"
}
}
afterTest { descriptor, result ->
def indicator = ANSI_WHITE
def mdIndicator
if (result.failedTestCount > 0) {
indicator = ANSI_RED + X_MARK
mdIndicator = ":x:"
} else if (result.skippedTestCount > 0) {
indicator = ANSI_YELLOW + NEUTRAL_FACE
mdIndicator = ":leftwards_arrow_with_hook:"
}
else {
indicator = ANSI_GREEN + CHECK_MARK
mdIndicator = ":white_check_mark:"
}
def message = ' ' + indicator + ANSI_RESET + " " + descriptor.name
def mdMessage = '- ' + mdIndicator + " " + descriptor.name
if (result.failedTestCount > 0) {
message += ' -> ' + result.exception
mdMessage += ' -> `' + result.exception + '`'
} else {
message += ' '
}
out.println(message)
resultsFileContent += mdMessage + "\n"
}
afterSuite { desc, result ->
if(desc.parent != null && desc.className != null){
out.println("")
}
if (!desc.parent) { // will match the outermost suite
def failStyle = ANSI_RED
def skipStyle = ANSI_YELLOW
def summaryStyle = ANSI_WHITE
switch(result.resultType){
case TestResult.ResultType.SUCCESS:
summaryStyle = ANSI_GREEN
break
case TestResult.ResultType.FAILURE:
summaryStyle = ANSI_RED
break
}
out.println( "--------------------------------------------------------------------------")
out.println( "Results: " + summaryStyle + "${result.resultType}" + ANSI_RESET
+ " (${result.testCount} tests, "
+ ANSI_GREEN + "${result.successfulTestCount} passed" + ANSI_RESET
+ ", " + failStyle + "${result.failedTestCount} failed" + ANSI_RESET
+ ", " + skipStyle + "${result.skippedTestCount} skipped" + ANSI_RESET
+ ")")
out.println( "--------------------------------------------------------------------------")
// Write the results file for GitHub action job summary.
new File(projectDir, resultsFilePath).text = resultsFileContent
}
}
}