This repository has been archived by the owner on Feb 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
174 lines (164 loc) · 7.15 KB
/
build.gradle.kts
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import org.jetbrains.kotlin.util.prefixIfNot
import org.apache.commons.configuration2.builder.fluent.Configurations
import org.ajoberstar.grgit.Grgit
import org.ajoberstar.grgit.Branch
import org.ajoberstar.grgit.Credentials
import org.ajoberstar.grgit.operation.BranchListOp
@Suppress("RemoveRedundantBackticks")
plugins {
`distribution`
`maven-publish`
kotlin("jvm").apply(false)
kotlin("multiplatform").apply(false)
kotlin("plugin.allopen").apply(false)
kotlin("plugin.noarg").apply(false)
kotlin("plugin.serialization").apply(false)
id("kotlinx-atomicfu").apply(false)
id("org.ajoberstar.grgit")
id("org.jetbrains.kotlinx.benchmark").apply(false)
id("com.github.johnrengelman.shadow").apply(false)
id("com.github.hierynomus.license").apply(false)
}
group = "com.epam.drill.plugins"
val kotlinVersion: String by extra
val kotlinxCollectionsVersion: String by extra
val kotlinxCoroutinesVersion: String by extra
val kotlinxSerializationVersion: String by extra
val sharedLibsLocalPath: String by extra
val adminLocalPath: String by extra
repositories {
mavenLocal()
mavenCentral()
}
buildscript {
dependencies.classpath("org.apache.commons:commons-configuration2:2.9.0")
dependencies.classpath("commons-beanutils:commons-beanutils:1.9.4")
}
if(version == Project.DEFAULT_VERSION) {
val fromEnv: () -> String? = {
System.getenv("GITHUB_REF")?.let { Regex("refs/tags/v(.*)").matchEntire(it)?.groupValues?.get(1) }
}
val fromGit: () -> String? = {
val gitdir: (Any) -> Boolean = { projectDir.resolve(".git").isDirectory }
takeIf(gitdir)?.let {
val gitrepo = Grgit.open { dir = projectDir }
val gittag = gitrepo.describe {
tags = true
longDescr = true
match = listOf("v[0-9]*.[0-9]*.[0-9]*")
}
gittag?.trim()?.removePrefix("v")?.replace(Regex("-[0-9]+-g[0-9a-f]+$"), "")?.takeIf(String::any)
}
}
version = fromEnv() ?: fromGit() ?: version
}
subprojects {
val constraints = setOf(
dependencies.constraints.create("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"),
dependencies.constraints.create("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"),
dependencies.constraints.create("org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion"),
dependencies.constraints.create("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"),
dependencies.constraints.create("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"),
dependencies.constraints.create("org.jetbrains.kotlinx:kotlinx-collections-immutable:$kotlinxCollectionsVersion"),
dependencies.constraints.create("org.jetbrains.kotlinx:kotlinx-collections-immutable-jvm:$kotlinxCollectionsVersion"),
dependencies.constraints.create("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion"),
dependencies.constraints.create("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:$kotlinxCoroutinesVersion"),
dependencies.constraints.create("org.jetbrains.kotlinx:kotlinx-coroutines-debug:$kotlinxCoroutinesVersion"),
dependencies.constraints.create("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:$kotlinxCoroutinesVersion"),
dependencies.constraints.create("org.jetbrains.kotlinx:kotlinx-serialization-core:$kotlinxSerializationVersion"),
dependencies.constraints.create("org.jetbrains.kotlinx:kotlinx-serialization-core-jvm:$kotlinxSerializationVersion"),
dependencies.constraints.create("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion"),
dependencies.constraints.create("org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:$kotlinxSerializationVersion"),
dependencies.constraints.create("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$kotlinxSerializationVersion"),
)
configurations.all {
dependencyConstraints += constraints
}
}
distributions {
val pluginConfigJson by tasks.creating(Copy::class) {
group = "distribution"
val pluginConfigTemplate = file("plugin_config.json")
val pluginConfigTemporary = file("$buildDir/tmp/${pluginConfigTemplate.name}").apply {
parentFile.mkdirs()
writeText(pluginConfigTemplate.readText().replace("{version}", project.version.toString()))
}
from(pluginConfigTemporary)
into("$buildDir/config")
}
main.get().contents {
from(
tasks.getByPath(":test2code-admin:shadowJar"),
tasks.getByPath(":test2code-agent:shadowJar"),
pluginConfigJson
)
into("/")
}
create("test").contents {
from(
tasks.getByPath(":test2code-admin:shadowJar"),
tasks.getByPath(":test2code-agent:testShadowJar"),
pluginConfigJson
)
into("/")
}
}
publishing {
publications.create<MavenPublication>("test2codeZip") {
artifact(tasks.distZip.get())
}
}
@Suppress("UNUSED_VARIABLE")
tasks {
val adminDir = projectDir.resolve(adminLocalPath)
val adminRef: String by extra
val updateAdmin by registering {
group = "other"
doLast {
val gitrepo = Grgit.open { dir = adminDir }
val branches = gitrepo.branch.list { mode = BranchListOp.Mode.LOCAL }
val branchToName: (Branch) -> String = { it.name }
val branchIsCreate: (String) -> Boolean = { !branches.map(branchToName).contains(it) }
gitrepo.fetch()
gitrepo.checkout {
branch = adminRef
startPoint = adminRef.takeIf(branchIsCreate)?.prefixIfNot("origin/")
createBranch = branchIsCreate(adminRef)
}
gitrepo.pull()
}
}
val sharedLibsDir = projectDir.resolve(sharedLibsLocalPath)
val sharedLibsRef: String by extra
val updateSharedLibs by registering {
group = "other"
doLast {
val gitrepo = Grgit.open { dir = sharedLibsDir }
val branches = gitrepo.branch.list { mode = BranchListOp.Mode.LOCAL }
val branchToName: (Branch) -> String = { it.name }
val branchIsCreate: (String) -> Boolean = { !branches.map(branchToName).contains(it) }
gitrepo.fetch()
gitrepo.checkout {
branch = sharedLibsRef
startPoint = sharedLibsRef.takeIf(branchIsCreate)?.prefixIfNot("origin/")
createBranch = branchIsCreate(sharedLibsRef)
}
gitrepo.pull()
}
}
val tagSharedLibs by registering {
group = "other"
doLast {
val tag = "${project.name}-v${project.version}"
val gitrepo = Grgit.open {
dir = sharedLibsDir
credentials = Credentials(System.getenv("SHARED_LIBS_USER"), System.getenv("SHARED_LIBS_PASSWORD"))
}
gitrepo.tag.add { name = tag }
gitrepo.push { refsOrSpecs = listOf("tags/$tag") }
val properties = Configurations().propertiesBuilder(file("gradle.properties"))
properties.configuration.setProperty("sharedLibsRef", tag)
properties.save()
}
}
}