Skip to content

Commit 881188f

Browse files
committed
uncommitted+unpushed changes prevent publishing release
1 parent f81935b commit 881188f

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

buildSrc/src/main/kotlin/common.gradle.kts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,34 @@ if (isAndroid) {
113113
val token = properties["github_api_key"]
114114
check(token != null && token is String) { "github_api_key not provided in local.properties" }
115115

116-
dependsOn("assembleRelease")
116+
val workingTreeCleanExec = providers.exec {
117+
executable("git")
118+
args("diff", "--quiet", "--exit-code", rootDir.absolutePath)
119+
isIgnoreExitValue = true
120+
}
121+
val workingTreeClean = workingTreeCleanExec.result.orNull?.exitValue == 0
122+
123+
providers.exec {
124+
executable("git")
125+
args("fetch")
126+
isIgnoreExitValue = true
127+
}
128+
129+
val allCommitsPushedExec = providers.exec {
130+
executable("git")
131+
args("diff", "--quiet", "--exit-code", "origin/main..main")
132+
isIgnoreExitValue = true
133+
}
134+
val allCommitsPushed = allCommitsPushedExec.result.orNull?.exitValue == 0
135+
136+
if (workingTreeClean && allCommitsPushed) {
137+
dependsOn("assembleRelease")
138+
}
117139

118-
doFirst {
140+
doFirst action@{
141+
check(workingTreeClean) { "Commit all changes before creating release." }
142+
check(allCommitsPushed) { "Sync remote before creating release." }
143+
119144
val packageRelease = project.tasks.getByName<DefaultTask>("packageRelease")
120145

121146
val outputs = packageRelease.outputs.files
@@ -129,7 +154,7 @@ if (isAndroid) {
129154

130155
if (repository.getReleaseByTagName(tagName) != null) {
131156
println("Release $name already exists")
132-
return@doFirst
157+
return@action
133158
}
134159

135160
val release = repository.createRelease(tagName).name(name).draft(true).create()
@@ -158,7 +183,7 @@ if (isAndroid || isAndroidLib) {
158183
}
159184
}
160185

161-
if(isKotlinLib || isKotlinAndroid) {
186+
if (isKotlinLib || isKotlinAndroid) {
162187
dependencies {
163188
add("implementation", "org.jetbrains:annotations:24.0.1")
164189
}

0 commit comments

Comments
 (0)