Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
orchestr7 committed Jan 14, 2025
1 parent 14b46bc commit 01d2cc3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
6 changes: 5 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ plugins {
kotlin("jvm") version ("2.1.0")
java
id("com.akuleshov7.buildutils.publishing-configuration")
id("com.akuleshov7.vercraft.plugin-gradle") version("0.0.2")
// id("com.akuleshov7.vercraft.plugin-gradle") version("0.0.2")
}

println("=== ${System.getenv("GITHUB_HEAD_REF")}")
println("=== ${System.getenv("GITHUB_REF_NAME")}")
println("=== ${System.getenv("GITHUB_REF")}")
5 changes: 5 additions & 0 deletions core/src/main/kotlin/com/akuleshov7/vercraft/core/Branch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import org.eclipse.jgit.api.Git
import org.eclipse.jgit.lib.Ref
import org.eclipse.jgit.revwalk.RevCommit

public const val GITLAB_BRANCH_REF: String = "CI_COMMIT_REF_NAME"
public const val GITHUB_BRANCH_REF: String = "GITHUB_REF_NAME"
public const val BITBUCKET_BRANCH_REF: String = "BITBUCKET_BRANCH"
public const val VERCRAFT_BRANCH_REF: String = "VERCRAFT_BRANCH"

public class Branch(git: Git, public val ref: Ref) {
public val gitLog: List<RevCommit> = git.log().add(ref.objectId).call().toList()

Expand Down
28 changes: 26 additions & 2 deletions core/src/main/kotlin/com/akuleshov7/vercraft/core/Releases.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,34 @@ public class Releases public constructor(private val git: Git) {
logger.warn(
"$ERROR_PREFIX your current HEAD is detached (no branch is checked out). " +
"Usually this happens on CI platforms, which check out particular commit. " +
"Please pass the branch which you are trying to process to VerCraftю"
"Trying to resolve branch name using known CI ENV variables: " +
"$GITLAB_BRANCH_REF, $GITHUB_BRANCH_REF, $BITBUCKET_BRANCH_REF."
)

throw NullPointerException("Current checked out branch is null (looks like your current HEAD is detached)")
val branchName = System.getenv(GITLAB_BRANCH_REF)
?: System.getenv(GITHUB_BRANCH_REF)
?: System.getenv(BITBUCKET_BRANCH_REF)
?: System.getenv(VERCRAFT_BRANCH_REF)
?: run {
logger.warn(
"$ERROR_PREFIX following variables are not defined in current env" +
"$GITLAB_BRANCH_REF, $GITHUB_BRANCH_REF, $BITBUCKET_BRANCH_REF" +
"Please pass the branch name which you are trying to process now explicitly " +
"to VerCraft by setting ENV variable \$VERCRAFT_BRANCH_REF. "
)
throw NullPointerException(
"Current HEAD is detached and CI env variables with the branch name are not set, so" +
"not able to determine the original branch name."
)
}

Branch(
git,
git.branchList()
.setListMode(REMOTE)
.call()
.first { it.name.endsWith(branchName) }
)
}

public val version: VersionCalculator = VersionCalculator(git, this, currentCheckoutBranch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ public class VersionCalculator(
dateFormat.timeZone = TimeZone.getDefault()
val formattedDate = dateFormat.format(Date(commit.commitTime * 1000L))

return SemVer(NO_MAJOR, NO_MINOR, distance + 1).setPrefix("$formattedDate-$branch")
return SemVer(NO_MAJOR, NO_MINOR, distance + 1)
.setPrefix("$formattedDate-$branch")
.setPostFix(commit.name.substring(0, 5))
}
}

Expand Down

0 comments on commit 01d2cc3

Please sign in to comment.