Skip to content

Commit

Permalink
Refactor snapshot versioning and deployment process
Browse files Browse the repository at this point in the history
Removed time-based version suffix for snapshots in build.gradle.kts and replaced it with an approach dependent on the environment variables "RUN_NUMBER" and "RUN_ATTEMPT". Included these variables into the action workflow publish-snapshot.yml
  • Loading branch information
lamba92 committed Dec 8, 2023
1 parent 2c1ef96 commit 046267d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ jobs:
GRADLE_ENTERPRISE_KEY: ${{ secrets.GRADLE_ENTERPRISE_KEY }}
MAVEN_SPACE_PASSWORD: ${{ secrets.MAVEN_SPACE_PASSWORD }}
MAVEN_SPACE_USERNAME: ${{ secrets.MAVEN_SPACE_USERNAME }}
RUN_NUMBER: ${{ github.run_number }}
RUN_ATTEMPT: ${{ github.run_attempt }}
35 changes: 14 additions & 21 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
@file:Suppress("UnstableApiUsage")

import kotlinx.datetime.Clock
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
import org.jetbrains.intellij.tasks.PublishPluginTask
import org.jetbrains.packagesearch.gradle.lafFile
import org.jetbrains.packagesearch.gradle.logCategoriesFile
Expand All @@ -12,6 +9,7 @@ import org.jetbrains.packagesearch.gradle.patchSettingsFile
import org.jetbrains.packagesearch.gradle.patchTextRegistryFile
import org.jetbrains.packagesearch.gradle.registryTextFile
import org.jetbrains.packagesearch.gradle.settingsFile
import kotlin.math.max


plugins {
Expand Down Expand Up @@ -95,21 +93,17 @@ tasks {
prepareSandbox {
runtimeClasspathFiles = tooling
}
val snapshotDateSuffix = buildString {
val now = Clock.System.now().toLocalDateTime(TimeZone.UTC)
append(now.year)
append(now.monthNumber)
append(now.dayOfMonth)
append(now.hour.toString().padStart(2, '0'))
append(now.minute.toString().padStart(2, '0'))
append(now.second.toString().padStart(2, '0'))
}

val runNumber = System.getenv("RUN_NUMBER")?.toInt() ?: 0
val runAttempt = System.getenv("RUN_ATTEMPT")?.toInt() ?: 0
val snapshotMinorVersion = max(0, runNumber + runAttempt - 1)
val versionString = project.version.toString()

patchPluginXml {
pluginId = pkgsPluginId
val versionString = project.version.toString()
version = when {
versionString.endsWith("-SNAPSHOT") ->
"${versionString.removePrefix("-SNAPSHOT")}.$snapshotDateSuffix"
"${versionString.removePrefix("-SNAPSHOT")}.$snapshotMinorVersion"

else -> versionString
}
Expand All @@ -118,20 +112,19 @@ tasks {
group = "intellij"
from(shadowJar) {
rename {
"package-search-plugin" + when {
it.endsWith("-SNAPSHOT.jar") ->
it.replace("-SNAPSHOT.jar", ".$snapshotDateSuffix.jar")
.also { logger.lifecycle("Snapshot version -> $it") }
"package-search-plugin-" + when {
versionString.endsWith("-SNAPSHOT") ->
versionString.replace("-SNAPSHOT", ".$snapshotMinorVersion")

else -> it
}
else -> versionString
} + ".jar"
}
}
from(tooling) {
rename { "gradle-tooling.jar" }
}
into("$pkgsPluginId/lib")
archiveFileName.set("packagesearch-plugin.zip")
archiveFileName = "packagesearch-plugin.zip"
destinationDirectory = layout.buildDirectory.dir("distributions")
}

Expand Down

0 comments on commit 046267d

Please sign in to comment.