Skip to content

Commit

Permalink
Merge 8772915 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Oct 20, 2022
2 parents 8d5f4fe + 8772915 commit e717a5a
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 25 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ Set environment variables `MAVEN_GPG_KEY`, `MAVEN_GPG_PASSWORD`

```
cd /path/to/thelib
java -jar mavence.jar central my.domain:thelib
java -jar mavence.jar central
```

This single command will do all the necessary work: build, signing, staging
Expand All @@ -308,7 +308,7 @@ test the package without sending it anywhere.

```
cd /path/to/thelib
java -jar mavence.jar local my.domain:thelib
java -jar mavence.jar local
```

### Publish to Staging
Expand All @@ -318,7 +318,7 @@ Set environment variables `MAVEN_GPG_KEY`, `MAVEN_GPG_PASSWORD`

```
cd /path/to/thelib
java -jar mavence.jar stage my.domain:thelib
java -jar mavence.jar stage
```

This will push the package to
Expand All @@ -334,7 +334,7 @@ receives the result as JSON.
Bash:

```
JSON=$(java -jar mavence.jar local my.domain:thelib)
JSON=$(java -jar mavence.jar local)
echo $JSON
```
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "io.github.rtmigo"
version = "0.1.2" // -SNAPSHOT
version = "0.2.0" // -SNAPSHOT

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/Build.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// DO NOT EDIT. Generated by Gradle task "generateBuildKt"
object Build {
const val version = "0.1.2-SNAPSHOT"
const val version = "0.2.0"
const val date = "2022-10-20"
}
17 changes: 13 additions & 4 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.options.*
import kotlinx.coroutines.runBlocking
import maven.*
import stages.build.*
import stages.sign.*
import stages.upload.*
import java.nio.file.*


class Cli : NoOpCliktCommand(
Expand All @@ -27,12 +29,19 @@ class Cli : NoOpCliktCommand(
override fun run() = Unit
}

private suspend fun gaa(): GroupArtifact {
val ad = ArtifactDir(Paths.get("."))
return GroupArtifact(ad.group(), ad.artifact())
}

open class Local(help: String="Build, publish to $m2str") : CliktCommand(help = help) {
val groupAndArtifact by argument("<artifact>")
//val groupAndArtifact by argument("<artifact>")

override fun run() = runBlocking {
cmdLocal(GroupArtifact.parse(groupAndArtifact), isFinal = true)
//val gw = Paths.get(".").toGradlew()
//gw.
//val ad = ArtifactDir(Paths.get("."))
cmdLocal(gaa(), isFinal = true)
Unit
}
}
Expand All @@ -51,7 +60,7 @@ open class Stage(help: String = "Build, sign, publish to OSSRH Staging") :

override fun run() = runBlocking {
cmdSign(
cmdLocal(GroupArtifact.parse(this@Stage.groupAndArtifact)),
cmdLocal(gaa()),
key = GpgPrivateKey(gpgKey),
pass = GpgPassphrase(gpgPwd)
).use {
Expand All @@ -67,7 +76,7 @@ open class Stage(help: String = "Build, sign, publish to OSSRH Staging") :
class Central : Stage(help = "Build, sign, publish to OSSRH Staging, release to Central") {
override fun run() = runBlocking {
cmdSign(
cmdLocal(GroupArtifact.parse(groupAndArtifact)),
cmdLocal(gaa()),
key = GpgPrivateKey(gpgKey),
pass = GpgPassphrase(gpgPwd)
).use { signed ->
Expand Down
35 changes: 23 additions & 12 deletions src/main/kotlin/stages/build/Gradle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import ExpectedException
import GradlewFile



import ProjectRootDir
import com.aballano.mnemonik.memoizeSuspend
import com.github.pgreze.process.*

import maven.*
import tools.rethrowingState
import java.nio.file.*
import kotlin.io.path.absolute
import kotlin.io.path.exists
Expand Down Expand Up @@ -57,7 +57,7 @@ suspend fun ArtifactDir.gradleClean() {
check(result.resultCode == 0)
}

suspend fun GradlewFile.getVersion(): String {
suspend fun GradlewFile.getGradleVersion(): String {
val res = process(
this.path.toString(), "--version",
stdout = Redirect.CAPTURE
Expand All @@ -71,8 +71,8 @@ suspend fun GradlewFile.getVersion(): String {
}
}

suspend fun GradlewFile.setVersion(newVersion: String) {
val oldVersion = this.getVersion()
suspend fun GradlewFile.setGradleVersion(newVersion: String) {
val oldVersion = this.getGradleVersion()
if (oldVersion == newVersion) {
println("Current version is $oldVersion. No need to change.")
return
Expand All @@ -85,7 +85,7 @@ suspend fun GradlewFile.setVersion(newVersion: String) {
)
.also { check(it.resultCode == 0) }

check(this.getVersion() == newVersion) { "Failed to change version" }
check(this.getGradleVersion() == newVersion) { "Failed to change version" }
}

/// Returns all the keys that were added or removed, and also all the keys associated
Expand All @@ -94,7 +94,10 @@ internal fun <K, V> keysOfChanges(old: Map<K, V>, new: Map<K, V>): List<K> =
(old.keys + new.keys).filter { (old[it] ?: 0) != (new[it] ?: 0) }


suspend fun GradlewFile.publishAndDetect(ga: GroupArtifact, publicationName: String?): MetadataLocalXmlFile {
suspend fun GradlewFile.publishAndDetect(
ga: GroupArtifact,
publicationName: String?
): MetadataLocalXmlFile {
//val old = readUpdateTimes()
fun xml() = ga.expectedLocalXmlFile(ga)

Expand All @@ -111,7 +114,8 @@ suspend fun GradlewFile.publishAndDetect(ga: GroupArtifact, publicationName: Str

check(newXml.file.exists()) { "File '${newXml.file} not found'" }
check(newXml.lastUpdated != oldLastUpdated) {
"'lastUpdated' value was not changed in ${newXml.file}"}
"'lastUpdated' value was not changed in ${newXml.file}"
}

return newXml
//val new = readUpdateTimes()
Expand Down Expand Up @@ -171,12 +175,12 @@ private suspend fun GradlewFile.tasks(): List<String> =
}


private suspend fun gradleProperties(d: ArtifactDir): Map<String, String> =
d.path.toGradlew().let {
private suspend fun gradleProperties(artidir: ArtifactDir): Map<String, String> =
artidir.path.toGradlew().let {
process(
it.path.toString(),
"-q", "properties",
directory = it.path.parent.toFile(),
directory = artidir.path.toFile(),
stdout = Redirect.CAPTURE
)
}.let {
Expand All @@ -193,8 +197,15 @@ private suspend fun gradleProperties(d: ArtifactDir): Map<String, String> =
private val cachedProperties = ::gradleProperties.memoizeSuspend()

suspend fun ArtifactDir.gradleVersion() = cachedProperties(this)["version"]!!
suspend fun ArtifactDir.group() = Group(cachedProperties(this)["group"]!!)
suspend fun ArtifactDir.artifact() = Group(cachedProperties(this)["archivesBaseName"]!!)

suspend fun ArtifactDir.group(): Group = rethrowingState(
{ "Failed to detect the package Group in ${this.path}" },
{ Group(cachedProperties(this)["group"]!!) })

suspend fun ArtifactDir.artifact(): Artifact = rethrowingState(
{ "Failed to detect the Artifact in ${this.path}" },
{ Artifact(cachedProperties(this)["archivesBaseName"]!!) })


data class Dependency(val notation: Notation, val scope: String)

Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/GradleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.nio.file.*
class GradleTest {
@Test
fun testVersion() = runBlocking {
Paths.get(".").toGradlew().getVersion()[0].isDigit().shouldBeTrue()
Paths.get(".").toGradlew().getGradleVersion()[0].isDigit().shouldBeTrue()
}

@Test
Expand Down
6 changes: 4 additions & 2 deletions src/test/python/test_uber.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import unittest
from pathlib import Path

deployable_project = Path("src/test/sample/deployable")
deployable_project = Path("src/test/sample/deployable/libr")
assert deployable_project.exists()


Expand All @@ -12,7 +12,9 @@ def test_build_local(self):
# check that our program provides clean stdout with JSON only
stdout = subprocess.check_output(
["java", "-jar", Path("build/libs/mavence.uber.jar").absolute(),
"local", "io.github.rtmigo:libr"],
"local",
#"io.github.rtmigo:libr"
],
cwd=deployable_project
)
print("stdout:", stdout)
Expand Down

0 comments on commit e717a5a

Please sign in to comment.