-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
143 lines (122 loc) · 3.74 KB
/
build.gradle.kts
File metadata and controls
143 lines (122 loc) · 3.74 KB
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
134
135
136
137
138
139
140
141
142
143
import io.github.danielliu1123.deployer.PublishingType
import pl.allegro.tech.build.axion.release.domain.PredefinedVersionCreator
plugins {
`maven-publish`
alias(libs.plugins.axion)
alias(libs.plugins.mavenDeployer)
id("tel.schich.javacan.convention.root")
}
tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
}
description = "JavaCAN is a binding to Linux' socketcan subsystem that feels native to Java developers."
private fun Project.getSecret(name: String): Provider<String> = provider {
val env = System.getenv(name)
?.ifBlank { null }
if (env != null) {
return@provider env
}
val propName = name.split("_")
.map { it.lowercase() }
.joinToString(separator = "") { word ->
word.replaceFirstChar { it.uppercase() }
}
.replaceFirstChar { it.lowercase() }
property(propName) as String
}
scmVersion {
tag {
prefix = "javacan-"
}
nextVersion {
suffix = "SNAPSHOT"
separator = "-"
}
versionCreator = PredefinedVersionCreator.SIMPLE.versionCreator
}
val gitVersion: String = scmVersion.version
allprojects {
group = "tel.schich"
version = gitVersion
}
deploy {
// dirs to upload, they will all be packaged into one bundle
dirs = provider {
allprojects
.map { it.layout.buildDirectory.dir("repo").get().asFile }
.filter { it.exists() }
.toList()
}
username = project.getSecret("MAVEN_CENTRAL_PORTAL_USERNAME")
password = project.getSecret("MAVEN_CENTRAL_PORTAL_PASSWORD")
publishingType = if (Constants.CI) {
PublishingType.WAIT_FOR_PUBLISHED
} else {
PublishingType.USER_MANAGED
}
}
tasks.deploy {
for (project in allprojects) {
val publishTasks = project.tasks
.withType<PublishToMavenRepository>()
mustRunAfter(publishTasks)
}
}
val isSnapshot = project.version.toString().endsWith("-SNAPSHOT")
val publishAllToMavenLocal by tasks.registering(DefaultTask::class) {
group = "publishing"
project.subprojects
.flatMap { it.tasks }
.filter { it.enabled }
.filter { it.name == "publishToMavenLocal" }
.forEach {
this@registering.dependsOn(it)
}
}
val testAll by tasks.registering(DefaultTask::class) {
group = "verification"
project.subprojects
.flatMap { it.tasks .withType<Test>() }
.filter { it.enabled }
.forEach {
this@registering.dependsOn(it)
}
}
val mavenCentralDeploy by tasks.registering(DefaultTask::class) {
group = "publishing"
val repo = if (isSnapshot) {
Constants.SNAPSHOTS_REPO
} else {
dependsOn(tasks.deploy)
Constants.RELEASES_REPO
}
for (project in allprojects) {
val publishTasks = project.tasks
.withType<PublishToMavenRepository>()
.matching { it.repository.name == repo }
dependsOn(publishTasks)
}
doFirst {
if (isSnapshot) {
logger.lifecycle("Snapshot deployment!")
} else {
logger.lifecycle("Release deployment!")
}
}
}
val githubActions by tasks.registering(DefaultTask::class) {
group = "publishing"
val deployRefPattern = """^refs/(?:tags/javacan-\d+\.\d+\.\d+|heads/master)$""".toRegex()
val ref = System.getenv("GITHUB_REF")?.ifBlank { null }?.trim()
if (ref != null && deployRefPattern.matches(ref)) {
logger.lifecycle("Job in $ref will deploy!")
dependsOn(mavenCentralDeploy)
} else {
logger.lifecycle("Job will only build!")
for (project in allprojects) {
project.tasks.findByName("assemble")?.let {
dependsOn(it)
}
}
}
}