Skip to content
Snippets Groups Projects
Commit d48afe89 authored by Sebastian's avatar Sebastian Committed by Mikolai Gütschow
Browse files

Building releases happens while detached, so store branch and tag in BuildData

parent c244fa0a
No related branches found
No related tags found
1 merge request!198Building releases happens while detached, so store branch and tag in BuildData
Pipeline #10488 passed
......@@ -22,6 +22,7 @@ import org.eclipse.jgit.api.Git
import org.eclipse.jgit.lib.Constants
import org.eclipse.jgit.lib.Ref
import org.eclipse.jgit.revwalk.RevCommit
import org.eclipse.jgit.revwalk.RevWalk
import org.eclipse.jgit.submodule.SubmoduleWalk
import org.gradle.api.GradleScriptException
import org.gradle.api.internal.artifacts.PreResolvedResolvableArtifact
......@@ -125,7 +126,7 @@ open class GenerateBuildDataSourceTask : AbstractBuildDataTask() {
val dirBriar = repositoryCore.directory
val gitBriar = Git.open(dirBriar)
// Get head ref and it's name => current hash
// Get head ref and its name => current hash
val head = repository.resolve(Constants.HEAD)
val gitHash = head.name + if (status.hasUncommittedChanges()) "-dirty" else ""
......@@ -140,14 +141,40 @@ open class GenerateBuildDataSourceTask : AbstractBuildDataTask() {
val commitTime = first.commitTime * 1000L
// Get current branch, if any
var gitBranch = "<unknown>"
var gitBranch: String? = null
val prefix = "refs/heads/"
val fullBranch = repository.fullBranch
if (fullBranch.startsWith(prefix)) {
gitBranch = fullBranch.substring(prefix.length)
}
// Get head ref and it's name => current core hash
// Build list of tags ordered by creation date. We do this to make sure that when we map
// commits to tags below, a commit that has multiple tags pointing to it maps to the latest tag
// (like a beta tag that is later promoted to a release tag).
val walk = RevWalk(repository)
val tagsByCreationDate = git.tagList().call().also {
it.sortBy { tag ->
val revTag = walk.parseTag(tag.objectId)
revTag.taggerIdent.`when`
}
}
// Build map of commits to tags that point to them
val commitToTag = tagsByCreationDate.associateBy { tag ->
val peeled = repository.refDatabase.peel(tag)
val call = git.log().add(peeled.peeledObjectId).call()
call.iterator().next()
}
// Get current tag, if any
var gitTag: String? = null
val prefixTags = "refs/tags/"
val tag = commitToTag[first]
if (tag != null && tag.name.startsWith(prefixTags)) {
gitTag = tag.name.substring(prefixTags.length)
}
// Get head ref and its name => current core hash
val coreHead = repositoryCore.resolve(Constants.HEAD)
val coreGitHash = coreHead.name
......@@ -183,7 +210,7 @@ open class GenerateBuildDataSourceTask : AbstractBuildDataTask() {
val file = path.resolve("$className.kt")
val content = createSource(
packageName, className, version,
commitTime, gitHash, gitBranch,
commitTime, gitHash, gitBranch, gitTag,
coreGitHash, coreVersion, artifacts
)
val input: InputStream = ByteArrayInputStream(
......@@ -213,11 +240,14 @@ open class GenerateBuildDataSourceTask : AbstractBuildDataTask() {
version: String,
gitTime: Long,
gitHash: String,
gitBranch: String,
gitBranch: String?,
gitTag: String?,
coreGitHash: String,
coreVersion: String,
artifacts: List<VersionedArtifact>,
) = FileBuilder().apply {
val branch = if (gitBranch == null) "null" else "\"$gitBranch\""
val tag = if (gitTag == null) "null" else "\"$gitTag\""
line("// this file is generated, do not edit")
line("package $packageName")
line()
......@@ -227,7 +257,8 @@ open class GenerateBuildDataSourceTask : AbstractBuildDataTask() {
line(" val VERSION = \"$version\"")
line(" val GIT_TIME = ${gitTime}L")
line(" val GIT_HASH = \"$gitHash\"")
line(" val GIT_BRANCH = \"$gitBranch\"")
line(" val GIT_BRANCH: String? = $branch")
line(" val GIT_TAG: String? = $tag")
line(" val CORE_HASH = \"$coreGitHash\"")
line(" val CORE_VERSION = \"$coreVersion\"")
line()
......
......@@ -102,7 +102,12 @@ private class Main : CliktCommand(
LOG.i { "Build info:" }
LOG.i { " Git hash ${BuildData.GIT_HASH}" }
LOG.i { " Commit time ${formatter.format(buildTime)}" }
LOG.i { " Branch ${BuildData.GIT_BRANCH}" }
if (BuildData.GIT_BRANCH != null)
LOG.i { " Branch ${BuildData.GIT_BRANCH}" }
if (BuildData.GIT_TAG != null)
LOG.i { " Tag ${BuildData.GIT_TAG}" }
if (BuildData.GIT_BRANCH == null && BuildData.GIT_TAG == null)
LOG.i { " Neither branch nor tag detected" }
val dataDir = getDataDir()
val app =
......
......@@ -52,17 +52,19 @@ fun AboutDialog(
val buildTime = Instant.ofEpochMilli(BuildData.GIT_TIME).atZone(ZoneId.systemDefault()).toLocalDateTime()
// rows displayed in table
val lines = listOf(
i18n("about.copyright") to "The Briar Project", // NON-NLS
i18n("about.license") to "GNU Affero General Public License v3", // NON-NLS
i18n("about.version") to BuildData.VERSION,
i18n("about.version.core") to BuildData.CORE_VERSION,
"Git branch" to BuildData.GIT_BRANCH, // NON-NLS
"Git hash" to BuildData.GIT_HASH, // NON-NLS
"Commit time" to DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(buildTime), // NON-NLS
i18n("about.website") to "https://briarproject.org",
i18n("about.contact") to "desktop@briarproject.org", // NON-NLS
)
val lines = buildList<Pair<String, String>> {
add(i18n("about.copyright") to "The Briar Project") // NON-NLS
add(i18n("about.license") to "GNU Affero General Public License v3") // NON-NLS
add(i18n("about.version") to BuildData.VERSION)
add(i18n("about.version.core") to BuildData.CORE_VERSION)
if (BuildData.GIT_BRANCH != null) add("Git branch" to BuildData.GIT_BRANCH) // NON-NLS
if (BuildData.GIT_TAG != null) add("Git tag" to BuildData.GIT_TAG) // NON-NLS
if (BuildData.GIT_BRANCH == null && BuildData.GIT_TAG == null) add("Git branch/tag" to "None detected") // NON-NLS
add("Git hash" to BuildData.GIT_HASH) // NON-NLS
add("Commit time" to DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(buildTime)) // NON-NLS
add(i18n("about.website") to "https://briarproject.org")
add(i18n("about.contact") to "desktop@briarproject.org") // NON-NLS
}
BriarDialog(onClose = onClose) {
val box = this
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment