diff --git a/.github/workflows/pushpr.yaml b/.github/workflows/pushpr.yaml new file mode 100644 index 0000000..241b6cc --- /dev/null +++ b/.github/workflows/pushpr.yaml @@ -0,0 +1,58 @@ +name: push and pr release + +on: + push: + branches: + - main + - develop + paths-ignore: + - '**.md' + pull_request: + branches: + - develop + paths-ignore: + - '**.md' + +jobs: + build-and-publish: + runs-on: ubuntu-latest + + steps: + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + java-version: '11' + distribution: 'zulu' + + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Restore Gradle cache + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Build and Release Main + if: ${{ github.ref_name == 'main' }} + run: | + ./gradlew --no-daemon clean build -Psemver.main.scope=patch -PgitHubTokenProp=${{ github.token }} -Pgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} publishPlugins githubRelease + + - name: Build and Release Develop + if: ${{ github.ref_name == 'develop' }} + run: | + ./gradlew --no-daemon clean build -Psemver.develop.stage=beta -PgitHubTokenProp=${{ github.token }} -Pgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} + + - name: Build and Release Branch + if: ${{ github.ref_name != 'develop' && github.ref_name != 'main' }} + run: | + ./gradlew --no-daemon clean build -Psemver.develop.stage=alpha -PgitHubTokenProp=${{ github.token }} -Pgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} + + - name: Stop Gradle daemons + run: ./gradlew --stop \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 66459d4..1e990dd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,6 +6,8 @@ plugins { `maven-publish` alias(libs.plugins.gradlePluginPublish) alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.semver) + alias(libs.plugins.githubrelease) } /* @@ -13,7 +15,6 @@ plugins { */ group = "io.github.nefilim.gradle" description = "Modified Git Flow based semver plugin" -version = "0.0.6" inner class ProjectInfo { val longName = "Gradle Semver Plugin" @@ -102,12 +103,4 @@ pluginBundle { website = info.website vcsUrl = info.website tags = info.tags -} - -//val publishPlugins = tasks.findByPath(":plugin:publishPlugins") - -//tasks.publishPlugins { -//// from(docsFileJar) -// dependsOn("publishPluginJar") -// dependsOn("publishPluginJavaDocsJar") -//} \ No newline at end of file +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5a8c819..cf09d15 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,9 +1,12 @@ [versions] -kotest = "4.6.4" kotlin = "1.6.10" + arrow = "1.0.1" +github-release = "2.2.12" jgit = "6.0.0.202111291000-r" +kotest = "5.0.2" semverCore = "0.1.0-beta.9" +semverPlugin = "0.0.6" [libraries] kotest-junit5-jvm = { module = "io.kotest:kotest-runner-junit5-jvm", version.ref = "kotest" } @@ -17,4 +20,6 @@ kotlin-testing = [ "kotest-junit5-jvm", "kotest-assertions-core-jvm" ] [plugins] gradlePluginPublish = { id = "com.gradle.plugin-publish", version = "0.18.0" } -kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } \ No newline at end of file +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +semver = { id = "io.github.nefilim.gradle.semver-plugin", version.ref = "semverPlugin" } +githubrelease = { id = "com.github.breadmoirai.github-release", version.ref = "github-release" } \ No newline at end of file diff --git a/src/main/kotlin/io/github/nefilim/gradle/semver/CalculatedVersionFlow.kt b/src/main/kotlin/io/github/nefilim/gradle/semver/CalculatedVersionFlow.kt index 29c35c8..fc5799d 100644 --- a/src/main/kotlin/io/github/nefilim/gradle/semver/CalculatedVersionFlow.kt +++ b/src/main/kotlin/io/github/nefilim/gradle/semver/CalculatedVersionFlow.kt @@ -37,7 +37,7 @@ internal fun SemVerPluginContext.calculatedVersionFlow( val commitCount = git.commitsSinceBranchPoint(branchPoint, main).bind() git.calculateDevelopBranchVersion(main, develop, tags).map { it.getOrElse { - project.semverMessage("unable to determine last version, using initialVersion [${config.initialVersion}]") + project.semverMessage("unable to determine last version from main branch, using initialVersion [${config.initialVersion}]") config.initialVersion }.copy(stageNum = commitCount) }.bind() @@ -69,9 +69,6 @@ internal fun SemVerPluginContext.calculatedVersionFlow( }).bind() } } - else -> { - SemVerError.UnsupportedBranch(currentBranch.refName).left() - } } } diff --git a/src/main/kotlin/io/github/nefilim/gradle/semver/Gradle.kt b/src/main/kotlin/io/github/nefilim/gradle/semver/Gradle.kt index dc7142d..12abba9 100644 --- a/src/main/kotlin/io/github/nefilim/gradle/semver/Gradle.kt +++ b/src/main/kotlin/io/github/nefilim/gradle/semver/Gradle.kt @@ -17,10 +17,10 @@ internal fun SemVerPluginContext.generateVersionFile() { createNewFile() writeText( """ - |$version - |${config.tagPrefix}$version - | - """.trimMargin() + |$version + |${config.tagPrefix}$version + | + """.trimMargin() ) } } diff --git a/src/main/kotlin/io/github/nefilim/gradle/semver/SemVerPlugin.kt b/src/main/kotlin/io/github/nefilim/gradle/semver/SemVerPlugin.kt index ecced80..3a20725 100644 --- a/src/main/kotlin/io/github/nefilim/gradle/semver/SemVerPlugin.kt +++ b/src/main/kotlin/io/github/nefilim/gradle/semver/SemVerPlugin.kt @@ -36,24 +36,45 @@ public class SemVerPlugin: Plugin { target.semverMessage("semver for ${target.name}: ${target.version}") } } else { - target.semverMessage("semver plugin can't work if the project is not a git repository") + target.semverMessage("the current directory is not part of a git repo, cannot determine project semantic version number, please initialize a git repo with main & develop branches") } } } private fun SemVerPluginContext.calculateVersionFlow(): Either { - val allBranches = git.branchList().setListMode(ListBranchCommand.ListMode.ALL).call().toList() - val mainRefName = allBranches.first { setOf(GitRef.MainBranch.RefName, GitRef.MainBranch.RemoteOriginRefName).contains(it.name) }.name - val developRefName = allBranches.first { setOf(GitRef.DevelopBranch.RefName, GitRef.DevelopBranch.RemoteOriginRefName).contains(it.name) }.name - project.logger.lifecycle("found main: $mainRefName, develop: $developRefName") return either.eager { - val main = git.buildBranch(mainRefName, config).bind() as GitRef.MainBranch - val develop = git.buildBranch(developRefName, config).bind() as GitRef.DevelopBranch - val current = git.buildBranch(repository.fullBranch, config).bind() - calculatedVersionFlow( - main, - develop, - current, - ).bind() + val allBranches = Either.catch { git.branchList().setListMode(ListBranchCommand.ListMode.ALL).call().toList() }.mapLeft { SemVerError.Git(it) }.bind() + val mainRefName = allBranches.firstOrNull { setOf(GitRef.MainBranch.RefName, GitRef.MainBranch.RemoteOriginRefName).contains(it.name) }?.name + val developRefName = allBranches.firstOrNull { setOf(GitRef.DevelopBranch.RefName, GitRef.DevelopBranch.RemoteOriginRefName).contains(it.name) }?.name + when { + mainRefName == null -> { + missingRequiredBranch(GitRef.MainBranch.Name) + config.initialVersion + } + developRefName == null -> { + missingRequiredBranch(GitRef.DevelopBranch.Name) + config.initialVersion + } + else -> { + project.logger.lifecycle("found main: $mainRefName, develop: $developRefName") + val main = git.buildBranch(mainRefName, config).bind() as GitRef.MainBranch + val develop = git.buildBranch(developRefName, config).bind() as GitRef.DevelopBranch + val current = git.buildBranch(repository.fullBranch, config).bind() + calculatedVersionFlow( + main, + develop, + current, + ).bind() + } + } } +} + +private fun SemVerPluginContext.missingRequiredBranch(branchName: String) { + project.logger.warn(""" + |could not find [$branchName] branch, defaulting to initial version: ${config.initialVersion} + | please create the following required branches: + | main + | ∟ develop + """.trimMargin()) } \ No newline at end of file