Skip to content

Commit

Permalink
Merge pull request orchestr7#76 from akuleshov7/feature/release-snapshot
Browse files Browse the repository at this point in the history
Adding support for snapshop releases
  • Loading branch information
orchestr7 authored Oct 13, 2021
2 parents 3107ffa + 550310b commit f2f0edd
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 deletions.
22 changes: 19 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,35 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
os: [ ubuntu-latest, windows-latest, macos-latest ]
steps:
- name: Checkout
uses: actions/[email protected]
with:
# release workflow should have access to all tags
fetch-depth: 0
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 1.11
- name: Status git before
run: git status
- uses: burrunan/gradle-cache-action@v1
name: Gradle release with caches caching
with:
arguments: publishToSonatype closeSonatypeStagingRepository
gradle-version: wrapper
# Until https://github.com/burrunan/gradle-cache-action/issues/42 is addressed, gradle should be run as a separate step
- name: gradle release from tag
# if workflow is triggered after push of a tag, deploy full release
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: ./gradlew --build-cache -Prelease linkReleaseExecutableMultiplatform publishToSonatype
- name: gradle snapshot release
# if workflow is triggered after push to a branch, deploy snapshot
if: ${{ startsWith(github.ref, 'refs/heads/') }}
run: ./gradlew --build-cache -Prelease -Preckon.stage=snapshot linkReleaseExecutableMultiplatform publishToSonatype
shell: bash
- name: Status git after
if: ${{ always() }}
run: git status

github_release:
needs: release
Expand Down
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ dependencies {
implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.15.0")
implementation("io.github.gradle-nexus:publish-plugin:1.1.0")
implementation("org.ajoberstar.reckon:reckon-gradle:0.13.0")
implementation("org.ajoberstar.grgit:grgit-core:4.1.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private fun Project.configureNexusPublishing() {
sonatype {
// only for users registered in Sonatype after 24 Feb 2021
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/"))
username.set(property("sonatypeUsername") as String)
password.set(property("sonatypePassword") as String)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,57 @@

package com.akuleshov7.buildutils

import org.ajoberstar.grgit.Grgit
import org.ajoberstar.reckon.gradle.ReckonExtension
import org.ajoberstar.reckon.gradle.ReckonPlugin
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure

@Suppress("MISSING_KDOC_ON_FUNCTION", "MISSING_KDOC_TOP_LEVEL")
/**
* Configures how project version is determined.
*
* @throws GradleException if there was an attempt to run release build with dirty working tree
*/
fun Project.configureVersioning() {
apply<ReckonPlugin>()

val isSnapshot = hasProperty("reckon.stage") && property("reckon.stage") == "snapshot"
configure<ReckonExtension> {
scopeFromProp()
stageFromProp("alpha", "rc", "final") // version string will be based on last commit; when checking out a tag, that tag will be used
if (isSnapshot) {
// we should build snapshots only for snapshot publishing, so it requires explicit parameter
snapshotFromProp()
} else {
stageFromProp("alpha", "rc", "final")
}
}

// to activate release, provide `-Prelease` or `-Prelease=true`. To deactivate, either omit the property, or set `-Prelease=false`.
val isRelease = hasProperty("release") && (property("release") as String != "false")
if (isRelease) {
val grgit = project.findProperty("grgit") as Grgit // grgit property is added by reckon plugin
val status = grgit.repository.jgit.status().call()
if (!status.isClean) {
throw GradleException(
"Release build will be performed with not clean git tree; aborting. " +
"Untracked files: ${status.untracked}, uncommitted changes: ${status.uncommittedChanges}"
)
}
}
if (isSnapshot) {
val grgit = project.findProperty("grgit") as Grgit // grgit property is added by reckon plugin
// A terrible hack to remove all pre-release tags. Because in semver `0.1.0-SNAPSHOT` < `0.1.0-alpha`, in snapshot mode
// we remove tags like `0.1.0-alpha`, and then reckoned version will still be `0.1.0-SNAPSHOT` and it will be compliant.
val preReleaseTagNames = grgit.tag.list()
.sortedByDescending { it.commit.dateTime }
.takeWhile {
// take latest tags that are pre-release
!it.name.matches(Regex("""^v\d+\.\d+\.\d+$"""))
}
.map { it.name }
grgit.tag.remove { this.names = preReleaseTagNames }
}
}

0 comments on commit f2f0edd

Please sign in to comment.