diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 9456a68..f58ba1d 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -14,6 +14,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + - name: Get tags + run: git fetch --tags origin - name: Setup Java JDK uses: actions/setup-java@v4.2.1 with: @@ -38,6 +40,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + - name: Get tags + run: git fetch --tags origin - name: Setup Java JDK uses: actions/setup-java@v4.2.1 with: @@ -60,6 +64,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + - name: Get tags + run: git fetch --tags origin - name: Setup Java JDK uses: actions/setup-java@v4.2.1 with: diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 64f7f15..9dc98b8 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -159,18 +159,29 @@ publishing { } @Suppress("UnstableApiUsage") -val gitCurrentTag = providers.exec { commandLine("git", "describe", "--abbrev=0", "--tags") } - .standardOutput.asText.map { it.trim() } +private val gitRevListTags = providers.exec { + commandLine("git", "rev-list", "--tags", "--max-count=1") +}.standardOutput.asText.map { it.trim() } + +@Suppress("UnstableApiUsage") +private val gitCurrentTag = providers.exec { + commandLine("git", "describe", "--tags", gitRevListTags.get()) +}.standardOutput.asText.map { it.trim() } // get git shortSha for version @Suppress("UnstableApiUsage") -val gitSha = providers.exec { commandLine("git", "rev-parse", "--short", "HEAD") } +private val gitSha = providers.exec { commandLine("git", "rev-parse", "--short", "HEAD") } .standardOutput.asText.map { it.trim() } mavenPublishing { // If gradle property release true remove sha from version - version = if (project.hasProperty("release")) gitCurrentTag.get() - else "${gitCurrentTag.get()}-${gitSha.get()}" + version = if ( + providers.systemProperty("release").isPresent || providers.gradleProperty("release").isPresent + ) { + gitCurrentTag.get() + } else { + "${gitCurrentTag.get()}-${gitSha.get()}" + } coordinates("com.chrisjenx.yakcov", "library", version = version.toString()) publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) signAllPublications()