Skip to content

Commit 4759012

Browse files
authored
Merge pull request #1 from artstorm/feature/unity-build-number
Feature/unity build number
2 parents 2f059eb + 075af20 commit 4759012

18 files changed

+646
-2
lines changed

.editorconfig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ root = true
44
charset = utf-8
55
end_of_line = lf
66
indent_style = space
7-
indent_size = 2
7+
indent_size = 4
88

99
[*.groovy]
1010
insert_final_newline = true
11-
trim_trailing_whitespace = true
11+
trim_trailing_whitespace = true
12+
13+
[*.yml]
14+
indent_size = 2

.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# Linux start script should use lf
5+
/gradlew text eol=lf
6+
7+
# These are Windows script files and should use crlf
8+
*.bat text eol=crlf
9+

.github/workflows/tests.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Tests
2+
on: pull_request
3+
4+
jobs:
5+
gradle:
6+
name: Gradle Test
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v3
11+
- uses: gradle/gradle-build-action@v2
12+
with:
13+
gradle-version: 7.5.1
14+
arguments: test
15+
16+
- name: Adding Test Results Summary
17+
run: |
18+
echo '### Test Results' >> $GITHUB_STEP_SUMMARY
19+
cat build/test-results.md >> $GITHUB_STEP_SUMMARY

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle
3+
4+
# Ignore Gradle build output directory
5+
build

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
# Jenkins Pipeline Shared Library
22

33
- [Shared Libraries in Jenkins Doc](https://www.jenkins.io/doc/book/pipeline/shared-libraries/)
4+
5+
6+
7+
## Functions
8+
### Unity
9+
#### Unity Build Number
10+
This function parses Unity's Project Settings and returns the build number that has been set
11+
for the Standalone build in Unity's `Project Settings > Player > Build`.
12+
13+
```groovy
14+
steps {
15+
echo "Unity build number: ${unityBuildNumber()}"
16+
}
17+
```

build.gradle

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* This file was generated by the Gradle 'init' task.
3+
*
4+
* This is a general purpose Gradle build.
5+
* Learn more about Gradle by exploring our samples at https://docs.gradle.org/7.5.1/samples
6+
*/
7+
apply plugin: 'groovy'
8+
9+
repositories {
10+
mavenCentral()
11+
mavenLocal()
12+
maven { url 'https://repo.jenkins-ci.org/releases/' }
13+
}
14+
15+
sourceSets {
16+
main {
17+
groovy {
18+
srcDirs = ['src']
19+
}
20+
}
21+
22+
test {
23+
groovy {
24+
srcDirs = ['test']
25+
}
26+
}
27+
}
28+
29+
dependencies {
30+
implementation 'org.codehaus.groovy:groovy-all:2.4.21'
31+
32+
testImplementation 'com.lesfurets:jenkins-pipeline-unit:1.12'
33+
testImplementation "junit:junit:4.12"
34+
}
35+
36+
// Prettify the test result output.
37+
tasks.withType(Test) {
38+
String ANSI_BOLD_WHITE = "\u001B[0;1m"
39+
String ANSI_RESET = "\u001B[0m"
40+
String ANSI_BLACK = "\u001B[30m"
41+
String ANSI_RED = "\u001B[31m"
42+
String ANSI_GREEN = "\u001B[32m"
43+
String ANSI_YELLOW = "\u001B[33m"
44+
String ANSI_BLUE = "\u001B[34m"
45+
String ANSI_PURPLE = "\u001B[35m"
46+
String ANSI_CYAN = "\u001B[36m"
47+
String ANSI_WHITE = "\u001B[37m"
48+
String CHECK_MARK = "\u2713"
49+
String NEUTRAL_FACE = "\u0CA0_\u0CA0"
50+
String X_MARK = "\u274C"
51+
52+
// Used to collect data to create a markdown file with the test results after
53+
// the suite has finished.
54+
// The GitHub action uses this markdown file to create the job summary.
55+
// https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/
56+
String resultsFilePath = "build/test-results.md"
57+
String resultsFileContent = ""
58+
59+
dependsOn cleanTest
60+
61+
testLogging {
62+
outputs.upToDateWhen {false}
63+
lifecycle.events = []
64+
}
65+
66+
beforeSuite { suite ->
67+
if(suite.parent != null && suite.className != null){
68+
out.println(ANSI_BOLD_WHITE + suite.name + ANSI_RESET )
69+
resultsFileContent += "#### " + suite.name + "\n"
70+
}
71+
}
72+
73+
afterTest { descriptor, result ->
74+
def indicator = ANSI_WHITE
75+
def mdIndicator
76+
77+
if (result.failedTestCount > 0) {
78+
indicator = ANSI_RED + X_MARK
79+
mdIndicator = ":x:"
80+
} else if (result.skippedTestCount > 0) {
81+
indicator = ANSI_YELLOW + NEUTRAL_FACE
82+
mdIndicator = ":leftwards_arrow_with_hook:"
83+
}
84+
else {
85+
indicator = ANSI_GREEN + CHECK_MARK
86+
mdIndicator = ":white_check_mark:"
87+
}
88+
89+
def message = ' ' + indicator + ANSI_RESET + " " + descriptor.name
90+
def mdMessage = '- ' + mdIndicator + " " + descriptor.name
91+
if (result.failedTestCount > 0) {
92+
message += ' -> ' + result.exception
93+
mdMessage += ' -> `' + result.exception + '`'
94+
} else {
95+
message += ' '
96+
}
97+
out.println(message)
98+
resultsFileContent += mdMessage + "\n"
99+
}
100+
101+
afterSuite { desc, result ->
102+
if(desc.parent != null && desc.className != null){
103+
out.println("")
104+
}
105+
106+
if (!desc.parent) { // will match the outermost suite
107+
def failStyle = ANSI_RED
108+
def skipStyle = ANSI_YELLOW
109+
def summaryStyle = ANSI_WHITE
110+
111+
switch(result.resultType){
112+
case TestResult.ResultType.SUCCESS:
113+
summaryStyle = ANSI_GREEN
114+
break
115+
case TestResult.ResultType.FAILURE:
116+
summaryStyle = ANSI_RED
117+
break
118+
}
119+
120+
out.println( "--------------------------------------------------------------------------")
121+
out.println( "Results: " + summaryStyle + "${result.resultType}" + ANSI_RESET
122+
+ " (${result.testCount} tests, "
123+
+ ANSI_GREEN + "${result.successfulTestCount} passed" + ANSI_RESET
124+
+ ", " + failStyle + "${result.failedTestCount} failed" + ANSI_RESET
125+
+ ", " + skipStyle + "${result.skippedTestCount} skipped" + ANSI_RESET
126+
+ ")")
127+
out.println( "--------------------------------------------------------------------------")
128+
129+
// Write the results file for GitHub action job summary.
130+
new File(projectDir, resultsFilePath).text = resultsFileContent
131+
}
132+
}
133+
}

gradle/wrapper/gradle-wrapper.jar

59.3 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)