-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
141 lines (119 loc) · 4.16 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
import org.pkl.core.Version
import java.nio.file.Files
import java.nio.file.Path
import kotlin.io.path.isDirectory
plugins {
kotlin("jvm").version(libs.versions.kotlin)
alias(libs.plugins.pkl)
}
kotlin {
jvmToolchain(17)
}
repositories {
mavenCentral()
}
dependencies {
testImplementation(libs.pklCore)
implementation(libs.pklDoc)
}
// True if environment variable CI is set
val isInCi = System.getenv("CI") != null
// allow to pass
val envSkipPublishCheck = System.getenv("CI_SKIP_PUBLISH_CHECK") != null
// The git repo url
val repositoryUrl = "https://github.com/AOEPeople/pkl-pantry"
// The Github API endpoint for the repo
val repositoryApiUrl = repositoryUrl.replace(Regex("github.com/"), "api.github.com/repos/")
// The package URI prefix (points to github pages)
val packageUriPrefix = "package://opensource.aoe.com/pkl-pantry/packages"
// The output directory (gradle default)
val outputDir = layout.buildDirectory
// List of packages
val projectDirs: List<File> =
Files.list(Path.of("packages"))
.filter { it.isDirectory() }
.map { it.toFile() }
.toList()
// PKL Gradle-Plugin configuration
pkl {
project {
resolvers {
register("resolveProjects") {
projectDirectories.from(projectDirs)
}
}
packagers {
register("createPackages") {
projectDirectories.from(projectDirs)
outputPath.set(outputDir.dir("generated/packages/%{name}/%{version}"))
skipPublishCheck = if (envSkipPublishCheck) true else !isInCi
}
}
}
pkldocGenerators {
register("pkldoc") {
outputDir = layout.projectDirectory.dir("docs")
sourceModules.addAll(
fileTree("docs/packages")
.matching {
include("*@*")
// TODO: Remove this exclusion once package doc generation works for them
exclude("com.gitlab.ci.golang@*")
exclude("com.gitlab.ci.docker@*")
}
.map {
"${packageUriPrefix}/${it.name.substring(it.name.lastIndexOf("/") + 1)}"
}
.toList()
)
}
}
}
// Add pkldoc task to documentation group
val pklDocs = tasks.named("pkldoc") {
group = "documentation"
}
// Build task depends on createReleases
tasks.build {
dependsOn(prepareReleases)
}
// Task from PKL Gradle-Plugin to be added to 'build' group
val resolveProjects = tasks.named("resolveProjects") {
group = "build"
inputs.files(fileTree("packages/") { include("PklProject") })
outputs.files(fileTree("packages/") { include("PklProject.deps.json") })
}
// Task from PKL Gradle-Plugin to be added to 'build' group
val createPackages = tasks.named("createPackages") {
group = "build"
dependsOn.add(resolveProjects)
}
// Task to generate packages and move the files to the right places
val prepareReleases by tasks.registering {
group = "build"
dependsOn(createPackages)
inputs.files(projectDirs)
doLast {
val releaseDir = file(outputDir.dir("releases"))
releaseDir.deleteRecursively()
for (i in projectDirs.indices) {
val dir = projectDirs[i]
println(dir.name)
val allVersions = file(outputDir.dir("generated/packages/${dir.name}")).list()
if (allVersions == null) {
println("∅")
continue
}
val latestVersion = allVersions.map(Version::parse).sortedWith(Version.comparator()).last()
val pkg = "${dir.name}@$latestVersion"
print("$pkg: ")
for (artifact in file(outputDir.dir("generated/packages/${dir.name}/$latestVersion")).listFiles()!!) {
artifact.copyTo(releaseDir.resolve("${pkg}/${artifact.name}"), true)
if (isInCi && !artifact.path.endsWith("zip") && !artifact.path.endsWith("sha256")) {
artifact.copyTo(projectDir.resolve("docs/packages/${artifact.name}"), true)
}
}
println("✅")
}
}
}