diff --git a/build.gradle.kts b/build.gradle.kts index 8eb1bc8..5363f5c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } group = "io.github.rtmigo" -version = "0.3.1-SNAPSHOT" // +version = "0.4.0" // -SNAPSHOT repositories { mavenCentral() diff --git a/src/main/kotlin/Build.kt b/src/main/kotlin/Build.kt index f78d114..8093eb0 100644 --- a/src/main/kotlin/Build.kt +++ b/src/main/kotlin/Build.kt @@ -1,5 +1,5 @@ // DO NOT EDIT. Generated by Gradle task "generateBuildKt" object Build { - const val version = "0.3.0" + const val version = "0.4.0" const val date = "2022-10-21" } \ No newline at end of file diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 70ab487..50eef91 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -4,13 +4,13 @@ **/ import com.github.ajalt.clikt.core.* -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 tools.rethrowingState import java.nio.file.* import kotlin.io.path.absolute @@ -24,7 +24,7 @@ class Cli : NoOpCliktCommand( init { versionOption(Build.version) { "$commandName $it (${Build.date})\n" + - "MIT (c) Artsiom iG \n" + + "ISC (c) Artsiom iG \n" + "http://github.com/rtmigo/mavence" } } @@ -41,6 +41,20 @@ private suspend fun gaa(): GroupArtifact { data class CliConfig(val trace: Boolean) +open class CheckCentral : CliktCommand( + help = "Check that environment is set for publishing to Maven Central") { + override fun run() = catchingCommand(this) { + fun checkVar(k: String) = rethrowingState( + { "Environment variable $k is not set." }, + { check(System.getenv(k).isNotBlank()) }) + checkVar(EnvVarNames.MAVEN_GPG_KEY) + checkVar(EnvVarNames.MAVEN_GPG_PASSWORD) + checkVar(EnvVarNames.SONATYPE_USERNAME) + checkVar(EnvVarNames.SONATYPE_PASSWORD) + System.err.println("At first glance, everything is OK.") + } +} + open class Local(help: String = "Build, publish to $m2str") : CliktCommand(help = help) { override fun run() = catchingCommand(this) { cmdLocal(gaa(), isFinal = true) @@ -48,17 +62,26 @@ open class Local(help: String = "Build, publish to $m2str") : CliktCommand(help } } +object EnvVarNames { + const val MAVEN_GPG_KEY = "MAVEN_GPG_KEY" + const val MAVEN_GPG_PASSWORD = "MAVEN_GPG_PASSWORD" + const val SONATYPE_USERNAME = "SONATYPE_USERNAME" + const val SONATYPE_PASSWORD = "SONATYPE_PASSWORD" +} + + + open class Stage(help: String = "Build, sign, publish to OSSRH Staging") : Local(help = help) { - val gpgKey by option("--gpg-key", envvar = "MAVEN_GPG_KEY").required() - val gpgPwd by option("--gpg-password", envvar = "MAVEN_GPG_PASSWORD").required() + val gpgKey by option("--gpg-key", envvar = EnvVarNames.MAVEN_GPG_KEY).required() + val gpgPwd by option("--gpg-password", envvar = EnvVarNames.MAVEN_GPG_PASSWORD).required() protected val sonatypeUser by option( "--sonatype-username", - envvar = "SONATYPE_USERNAME").required() + envvar = EnvVarNames.SONATYPE_USERNAME).required() protected val sonatypePassword by option( "--sonatype-password", - envvar = "SONATYPE_PASSWORD").required() + envvar = EnvVarNames.SONATYPE_PASSWORD).required() override fun run() = catchingCommand(this) { cmdSign( @@ -102,13 +125,13 @@ fun catchingCommand(cmd: CliktCommand, block: suspend () -> Unit) { e.printStackTrace() else System.err.println("ERROR: $e") - System.err.println("Run with --trace to see full stack trace.") + System.err.println("Run with --trace to see full stack trace.") } } fun main(args: Array) { Cli() - .subcommands(Local(), Stage(), Central()) + .subcommands(Local(), Stage(), Central(), CheckCentral()) .main(args) } \ No newline at end of file