Skip to content

Commit

Permalink
githubReleases + semversioning
Browse files Browse the repository at this point in the history
  • Loading branch information
cworsnop-figure committed Apr 14, 2022
1 parent b6d5923 commit 457992e
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 68 deletions.
57 changes: 0 additions & 57 deletions .github/workflows/docker.yaml

This file was deleted.

61 changes: 61 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Release

on:
workflow_dispatch:
inputs:
versionModifier:
description: 'Version Modifier'
default: 'patch'
type: choice
required: false
options:
- 'patch'
- 'minor'
- 'major'
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Build with Gradle
run: ./gradlew -i clean build --refresh-dependencies :generateVersionFile githubRelease
if: ${{ github.ref_name == 'main' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Outputs
run: |-
echo "::set-output name=semVersion::$(cat build/semver/version.txt | head -1)"
echo "::set-output name=semVersionTag::$(cat build/semver/version.txt | tail -1)"
id: ci-release-create-outputs
shell: bash
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=provenanceio/p8e-cee-api
VERSION={{ steps.ci-release-create-outputs.outputs.semVersion }}
TAGS=${{ steps.ci-release-create-outputs.outputs.semVersionTag }}
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push service docker
uses: docker/build-push-action@v2
with:
file: service/docker/Dockerfile
context: .
push: true
tags: ${{ steps.prep.outputs.tags }}
104 changes: 93 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import net.swiftzer.semver.SemVer

buildscript {
dependencies {
classpath("net.swiftzer.semver:semver:1.1.2")
classpath("com.github.breadmoirai:github-release:2.2.12")
}
}

plugins {
kotlin("jvm") version Versions.Kotlin
id("java")
id("maven-publish")
}

allprojects {
val project = this
group = "io.provenance.p8e-cee-api"
version = this.findProperty("artifactVersion")?.toString()
?: "1.0-snapshot"

repositories {
mavenCentral()
}
id("com.github.breadmoirai.github-release") version "2.2.12"
id("io.github.nefilim.gradle.semver-plugin") version "0.3.10"
}

subprojects {
Expand Down Expand Up @@ -45,3 +46,84 @@ java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

semver {
tagPrefix("v")
initialVersion("0.1.0")
findProperty("semver.overrideVersion")?.toString()?.let { overrideVersion(it) }
val semVerModifier = findProperty("semver.modifier")?.toString()?.let { buildVersionModifier(it) } ?: { nextPatch() }
versionModifier(semVerModifier)
}

/**
* The code below is a workaround for [gradle/gradle#20016](https://github.com/gradle/gradle/issues/20016) derived from
* [platform-portal@14319ed/docs/semver.md](https://github.com/FigureTechnologies/platform-portal/blob/14319ed7e97d88a1b8cbb2f2f7708cc0660dc518/docs/semver.md#limiting-dependencies-to-release-versions)
* to prevent version strings like `"1.0.+"` from resolving to pre-release versions.
* You can adjust the string set constants or comment the code out entirely to allow pre-release versions to be used.
*/

val invalidQualifiers = setOf("alpha", "beta", "rc", "nightly")
val onlyReleaseArtifacts = setOf("p8e-cee-api")
val whiteListedMavenGroups = setOf("tech.figure", "io.provenance")

configurations.all {
resolutionStrategy {
componentSelection {
all {
when {
(
onlyReleaseArtifacts.any { candidate.moduleIdentifier.name.startsWith(it) } &&
!candidate.version.toSemVer()?.preRelease.isNullOrEmpty()
) -> {
reject("Rejecting prerelease version for OnlyReleaseArtifact[$candidate]")
}
(
whiteListedMavenGroups.none { candidate.group.startsWith(it) } &&
invalidQualifiers.any { candidate.version.contains(it) }
) -> {
reject("Invalid qualifier versions for $candidate")
}
}
}
}
}
}

fun String?.toSemVer(): SemVer? =
try {
this?.let { versionString ->
SemVer.parse(versionString)
}
} catch (e: Exception) {
project.logger.info("Failed to parse semantic version from string '$this'")
null
}


val semVersion = semver.version
allprojects {
val project = this
group = "io.provenance.p8e-cee-api"
version = semVersion

repositories {
mavenCentral()
}
}

val githubTokenValue = findProperty("githubToken")?.toString() ?: System.getenv("GITHUB_TOKEN")
githubRelease {
token(githubTokenValue)
owner("provenance-io")
targetCommitish("main")
draft(false)
prerelease(false)
repo("p8e-cee-api")
tagName(semver.versionTagName)
body(changelog())

overwrite(false)
dryRun(false)
apiEndpoint("https://api.github.com")
client
}

0 comments on commit 457992e

Please sign in to comment.