Add version in log, command and api
A task has been added to generate a BuildVersions file when building the project. Project's version can be found in that file at runtime. Also centralized declaration of the dependencies versions to buildSrc.
This commit is contained in:
parent
6bffd418e8
commit
9d460eeee5
@ -1,8 +1,10 @@
|
||||
import Versions.ktor
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTests
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath("app.cash.sqldelight:gradle-plugin:2.0.1")
|
||||
classpath("app.cash.sqldelight:gradle-plugin:${Versions.sqlDelight}")
|
||||
}
|
||||
repositories {
|
||||
google()
|
||||
@ -11,9 +13,9 @@ buildscript {
|
||||
}
|
||||
|
||||
plugins {
|
||||
kotlin("multiplatform") version "1.9.23"
|
||||
kotlin("plugin.serialization") version "1.9.23"
|
||||
id("app.cash.sqldelight") version "2.0.1"
|
||||
kotlin("multiplatform") version Versions.kotlin
|
||||
kotlin("plugin.serialization") version Versions.kotlin
|
||||
id("app.cash.sqldelight") version Versions.sqlDelight
|
||||
}
|
||||
|
||||
allprojects {
|
||||
@ -30,6 +32,42 @@ allprojects {
|
||||
}
|
||||
}
|
||||
|
||||
/** Get the current git commit hash. */
|
||||
fun gitCommitHash(): String {
|
||||
val stream = ByteArrayOutputStream()
|
||||
project.exec {
|
||||
commandLine = "git rev-parse --verify --long HEAD".split(" ")
|
||||
standardOutput = stream
|
||||
}
|
||||
return String(stream.toByteArray()).split("\n").first()
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a `BuildVersions` file in build/generated-src containing the current git commit and the lightning-kmp version.
|
||||
* See https://stackoverflow.com/a/74771876 for details.
|
||||
*/
|
||||
val buildVersionsTask by tasks.registering(Sync::class) {
|
||||
group = "build"
|
||||
from(
|
||||
resources.text.fromString(
|
||||
"""
|
||||
|package fr.acinq.lightning
|
||||
|
|
||||
|object BuildVersions {
|
||||
| const val phoenixdCommit = "${gitCommitHash()}"
|
||||
| const val phoenixdVersion = "${project.version}-${gitCommitHash().take(7)}"
|
||||
| const val lightningKmpVersion = "${Versions.lightningKmp}"
|
||||
|}
|
||||
|
|
||||
""".trimMargin()
|
||||
)
|
||||
) {
|
||||
rename { "BuildVersions.kt" }
|
||||
into("fr/acinq/lightning")
|
||||
}
|
||||
into(layout.buildDirectory.dir("generated/kotlin/"))
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvm()
|
||||
|
||||
@ -59,13 +97,11 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
val ktorVersion = "2.3.8"
|
||||
fun ktor(module: String) = "io.ktor:ktor-$module:$ktorVersion"
|
||||
|
||||
sourceSets {
|
||||
commonMain {
|
||||
kotlin.srcDir(buildVersionsTask.map { it.destinationDir })
|
||||
dependencies {
|
||||
implementation("fr.acinq.lightning:lightning-kmp:1.6.2-FEECREDIT-2-SNAPSHOT")
|
||||
implementation("fr.acinq.lightning:lightning-kmp:${Versions.lightningKmp}")
|
||||
// ktor serialization
|
||||
implementation(ktor("serialization-kotlinx-json"))
|
||||
// ktor server
|
||||
@ -81,20 +117,20 @@ kotlin {
|
||||
implementation(ktor("client-auth"))
|
||||
implementation(ktor("client-json"))
|
||||
|
||||
implementation("com.squareup.okio:okio:3.8.0")
|
||||
implementation("com.github.ajalt.clikt:clikt:4.2.2")
|
||||
implementation("app.cash.sqldelight:coroutines-extensions:2.0.1")
|
||||
implementation("com.squareup.okio:okio:${Versions.okio}")
|
||||
implementation("com.github.ajalt.clikt:clikt:${Versions.clikt}")
|
||||
implementation("app.cash.sqldelight:coroutines-extensions:${Versions.sqlDelight}")
|
||||
}
|
||||
}
|
||||
jvmMain {
|
||||
dependencies {
|
||||
implementation("app.cash.sqldelight:sqlite-driver:2.0.1")
|
||||
implementation("app.cash.sqldelight:sqlite-driver:${Versions.sqlDelight}")
|
||||
implementation(ktor("client-okhttp"))
|
||||
}
|
||||
}
|
||||
nativeMain {
|
||||
dependencies {
|
||||
implementation("app.cash.sqldelight:native-driver:2.0.1")
|
||||
implementation("app.cash.sqldelight:native-driver:${Versions.sqlDelight}")
|
||||
}
|
||||
}
|
||||
linuxMain {
|
||||
@ -123,3 +159,4 @@ sqldelight {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
6
buildSrc/build.gradle.kts
Normal file
6
buildSrc/build.gradle.kts
Normal file
@ -0,0 +1,6 @@
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
}
|
9
buildSrc/src/main/kotlin/Versions.kt
Normal file
9
buildSrc/src/main/kotlin/Versions.kt
Normal file
@ -0,0 +1,9 @@
|
||||
object Versions {
|
||||
val kotlin = "1.9.23"
|
||||
val lightningKmp = "1.6.2-FEECREDIT-2-SNAPSHOT"
|
||||
val sqlDelight = "2.0.1"
|
||||
val okio = "3.8.0"
|
||||
val clikt = "4.2.2"
|
||||
val ktor = "2.3.8"
|
||||
fun ktor(module: String) = "io.ktor:ktor-$module:$ktor"
|
||||
}
|
@ -6,6 +6,7 @@ import fr.acinq.bitcoin.ByteVector32
|
||||
import fr.acinq.bitcoin.Script
|
||||
import fr.acinq.bitcoin.utils.Either
|
||||
import fr.acinq.bitcoin.utils.toEither
|
||||
import fr.acinq.lightning.BuildVersions
|
||||
import fr.acinq.lightning.Lightning.randomBytes32
|
||||
import fr.acinq.lightning.NodeParams
|
||||
import fr.acinq.lightning.bin.db.SqlitePaymentsDb
|
||||
@ -78,6 +79,7 @@ class Api(private val nodeParams: NodeParams, private val peer: Peer, private va
|
||||
authenticate {
|
||||
get("getinfo") {
|
||||
val info = NodeInfo(
|
||||
version = BuildVersions.phoenixdVersion,
|
||||
nodeId = nodeParams.nodeId,
|
||||
channels = peer.channels.values.map { Channel.from(it) }
|
||||
)
|
||||
|
@ -21,6 +21,7 @@ import com.github.ajalt.mordant.rendering.TextColors.*
|
||||
import com.github.ajalt.mordant.rendering.TextStyles.bold
|
||||
import com.github.ajalt.mordant.rendering.TextStyles.underline
|
||||
import fr.acinq.bitcoin.Chain
|
||||
import fr.acinq.lightning.BuildVersions
|
||||
import fr.acinq.lightning.Lightning.randomBytes32
|
||||
import fr.acinq.lightning.LiquidityEvents
|
||||
import fr.acinq.lightning.NodeParams
|
||||
@ -64,7 +65,9 @@ import kotlin.time.Duration.Companion.milliseconds
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
|
||||
fun main(args: Array<String>) = Phoenixd().main(args)
|
||||
fun main(args: Array<String>) = Phoenixd()
|
||||
.versionOption(BuildVersions.phoenixdVersion, names = setOf("--version", "-v"))
|
||||
.main(args)
|
||||
|
||||
class LiquidityOptions : OptionGroup(name = "Liquidity Options") {
|
||||
val autoLiquidity by option("--auto-liquidity", help = "Amount automatically requested when inbound liquidity is needed").choice(
|
||||
@ -198,6 +201,8 @@ class Phoenixd : CliktCommand() {
|
||||
|
||||
}
|
||||
}
|
||||
consoleLog(cyan("version: ${BuildVersions.phoenixdVersion}"))
|
||||
consoleLog(cyan("lightning-kmp: ${BuildVersions.lightningKmpVersion}"))
|
||||
consoleLog(cyan("datadir: ${FileSystem.SYSTEM.canonicalize(datadir)}"))
|
||||
consoleLog(cyan("chain: $chain"))
|
||||
consoleLog(cyan("autoLiquidity: ${liquidityOptions.autoLiquidity}"))
|
||||
|
@ -57,6 +57,7 @@ sealed class ApiType {
|
||||
|
||||
@Serializable
|
||||
data class NodeInfo(
|
||||
val version: String,
|
||||
val nodeId: PublicKey,
|
||||
val channels: List<Channel>
|
||||
)
|
||||
|
@ -12,6 +12,7 @@ import com.github.ajalt.clikt.sources.MapValueSource
|
||||
import fr.acinq.bitcoin.Base58Check
|
||||
import fr.acinq.bitcoin.Bech32
|
||||
import fr.acinq.bitcoin.ByteVector32
|
||||
import fr.acinq.lightning.BuildVersions
|
||||
import fr.acinq.lightning.bin.conf.readConfFile
|
||||
import fr.acinq.lightning.bin.homeDirectory
|
||||
import fr.acinq.lightning.payment.Bolt11Invoice
|
||||
@ -26,11 +27,13 @@ import io.ktor.client.statement.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import io.ktor.server.util.*
|
||||
import io.ktor.util.*
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
fun main(args: Array<String>) =
|
||||
PhoenixCli()
|
||||
.versionOption(BuildVersions.phoenixdVersion, names = setOf("--version", "-v"))
|
||||
.subcommands(GetInfo(), GetBalance(), ListChannels(), GetOutgoingPayment(), GetIncomingPayment(), ListIncomingPayments(), CreateInvoice(), PayInvoice(), SendToAddress(), CloseChannel())
|
||||
.main(args)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user