-
Notifications
You must be signed in to change notification settings - Fork 0
/
java.go
83 lines (73 loc) · 1.83 KB
/
java.go
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
package internal
import (
"github.com/CircleCI-Public/circleci-config/config"
"github.com/CircleCI-Public/circleci-config/labeling/labels"
)
// latest LTS version
const javaDockerImage = "cimg/openjdk:17.0"
func javaTestJob(ls labels.LabelSet) *Job {
var cachePath string
var testCommand string
var testResultsPath string
var testReportsPath string
if ls[labels.ToolGradle].Valid {
cachePath = "~/.gradle/caches"
testCommand = "./gradlew check"
testResultsPath = "build/test-results"
testReportsPath = "build/reports"
} else {
cachePath = "~/.m2/repository"
testCommand = "mvn verify"
testResultsPath = "target/surefire-reports"
}
cacheKeyCalcCommand := `find . -name 'pom.xml' -o -name 'gradlew*' -o -name '*.gradle*' | \
sort | xargs cat > /tmp/CIRCLECI_CACHE_KEY`
cacheKey := `cache-{{ checksum "/tmp/CIRCLECI_CACHE_KEY" }}`
steps := []config.Step{
checkoutStep(ls[labels.DepsJava]),
{
Type: config.Run,
Name: "Calculate cache key",
Command: cacheKeyCalcCommand,
},
{
Type: config.RestoreCache,
CacheKey: cacheKey,
},
{
Type: config.Run,
Command: testCommand,
},
{
Type: config.StoreTestResults,
Path: testResultsPath,
},
{
Type: config.SaveCache,
CacheKey: cacheKey,
Path: cachePath,
},
}
if testReportsPath != "" {
steps = append(steps, config.Step{
Type: config.StoreArtifacts,
Name: "Store test reports as artifacts",
Path: testReportsPath,
})
}
return &Job{
Job: config.Job{
Name: "test-java",
DockerImages: []string{javaDockerImage},
WorkingDirectory: workingDirectory(ls[labels.DepsJava]),
Steps: steps,
},
Type: TestJob,
}
}
func GenerateJavaJobs(ls labels.LabelSet) (jobs []*Job) {
if !ls[labels.DepsJava].Valid {
return nil
}
return append(jobs, javaTestJob(ls))
}