11 Commits

Author SHA1 Message Date
hlaeja
81cc9291dd [RELEASE] - Release version: 0.4.0 2025-08-18 10:28:16 +00:00
6bc006f7cb fix publish plugin 2025-08-18 11:11:03 +02:00
hlaeja
a1078b1e79 [RELEASE] - Bump version 2025-07-29 16:33:01 +00:00
hlaeja
8a73d50dda [RELEASE] - Release version: 0.3.0 2025-07-29 16:33:00 +00:00
ab177c4205 update gradlew 2025-07-29 18:32:10 +02:00
533d92e822 update project 2025-07-29 18:26:28 +02:00
35bbea6000 add GitHub action
- add action run checks
- add action release
- remove release.sh
2025-07-29 18:26:28 +02:00
496b0234c4 [RELEASE] - bump version 2024-12-10 23:00:31 +01:00
468779e115 [RELEASE] - release version: 0.2.0 2024-12-10 23:00:28 +01:00
ff1239e592 add ConfigExtension
- update README.md with Extension Config
- add configExtension to CorePlugin
- add ConfigExtension
- add environment variable in Test tasks
- update catalog version
- update dependencies in build.gradle.kts
2024-12-10 17:37:20 +01:00
494843592a [RELEASE] - bump version 2024-11-01 19:50:15 +00:00
15 changed files with 266 additions and 145 deletions

View File

@@ -21,12 +21,14 @@ tab_width = 2
# noinspection EditorConfigKeyCorrectness
[*.{kt,kts}]
ij_kotlin_packages_to_use_import_on_demand = unset
ij_kotlin_allow_trailing_comma_on_call_site = true
ij_kotlin_allow_trailing_comma = true
ktlint_standard_import-ordering = disabled
ktlint_standard_no-empty-first-line-in-class-body = disabled
ij_kotlin_allow_trailing_comma_on_call_site = true
ij_kotlin_packages_to_use_import_on_demand = unset
ktlint_standard_chain-method-continuation = disabled
ktlint_standard_class-signature = disabled
ktlint_standard_function-signature = disabled
ktlint_standard_parameter-list-wrapping = disabled
ktlint_standard_import-ordering = disabled
ktlint_standard_multiline-expression-wrapping = disabled
ktlint_standard_no-empty-first-line-in-class-body = disabled
ktlint_standard_parameter-list-wrapping = disabled
ktlint_standard_string-template-indent = disabled

12
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,12 @@
name: Release
on:
workflow_dispatch:
jobs:
release:
uses: swordsteel/hlaeja-common-workflows/.github/workflows/release.yml@master
secrets:
CI_BOT_PAT: ${{ secrets.CI_BOT_PAT }}
with:
TYPE: plugin

12
.github/workflows/run-checks.yml vendored Normal file
View File

@@ -0,0 +1,12 @@
name: Pull request validation
on:
pull_request:
paths-ignore:
- '.github/**'
jobs:
validate:
uses: swordsteel/hlaeja-common-workflows/.github/workflows/run-checks.yml@master
secrets:
CI_BOT_PAT: ${{ secrets.CI_BOT_PAT }}

View File

@@ -12,11 +12,15 @@ The GitExtension enhances versioning by dynamically appending the Git hash befor
The InfoExtension provides information for name and version, vendor name, and UTC timestamp.
## Releasing plugin
### Extension Config
Run `release.sh` script from `master` branch.
The ConfigExtension provides a find or findOrDefault for getting a property or environment.
## Publishing plugin
## Releasing Plugin
Run release pipeline from `master` branch.
## Publishing Plugin
### Publish plugin locally
@@ -27,7 +31,7 @@ Run `release.sh` script from `master` branch.
### Publish plugin to repository
```shell
./gradlew clean build publish
./gradlew clean build publishAllPublicationsToGitHubPackagesRepository
```
### Global gradle properties

View File

@@ -8,9 +8,9 @@ import java.time.format.DateTimeFormatter.ofPattern
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType.SARIF
plugins {
alias(hlaeja.plugins.io.gitlab.arturbosch.detekt)
alias(hlaeja.plugins.gradle.detekt)
alias(hlaeja.plugins.gradle.ktlint)
alias(hlaeja.plugins.kotlin.jvm)
alias(hlaeja.plugins.org.jlleitschuh.gradle.ktlint)
`kotlin-dsl`
`maven-publish`
@@ -19,9 +19,11 @@ plugins {
dependencies {
implementation(hlaeja.org.eclipse.jgit)
testImplementation(hlaeja.io.mockk)
testImplementation(hlaeja.assertj.core)
testImplementation(hlaeja.junit.jupiter.params)
testImplementation(hlaeja.kotlin.reflect)
testImplementation(hlaeja.kotlin.test)
testImplementation(hlaeja.org.junit.jupiter.params)
testImplementation(hlaeja.mockk)
}
gradlePlugin.plugins.create("hlaeja-core-plugin") {
@@ -72,7 +74,6 @@ publishing {
}
}
}
publications.create<MavenPublication>("mavenJava") { from(components["java"]) }
}
tasks {
@@ -82,9 +83,10 @@ tasks {
register("buildInfo") {
group = "hlaeja"
description = "Prints the project name and version"
val projectName = project.name
val projectVersion = project.version
doLast {
println("Project Name: ${project.name} Version: ${project.version}")
println("Project Name: $projectName Version: $projectVersion")
}
}
withType<Detekt> {
@@ -112,6 +114,8 @@ tasks {
}
}
withType<Test> {
// Set TEST_ENV environment variable for test execution
environment["TEST_ENV"] = "hlæja"
useJUnitPlatform()
}
}

View File

@@ -1,3 +1,3 @@
kotlin.code.style=official
version=0.1.0
catalog=0.1.0
version=0.4.0
catalog=0.12.0

Binary file not shown.

View File

@@ -1,6 +1,7 @@
#Sat Oct 19 21:09:25 BST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

47
gradlew vendored Normal file → Executable file
View File

@@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
@@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -80,13 +82,11 @@ do
esac
done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@@ -114,7 +114,7 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
CLASSPATH="\\\"\\\""
# Determine the Java command to use to start the JVM.
@@ -133,22 +133,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@@ -193,18 +200,28 @@ if "$cygwin" || "$msys" ; then
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.

41
gradlew.bat vendored
View File

@@ -13,8 +13,10 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@@ -25,7 +27,8 @@
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@@ -40,13 +43,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
@@ -56,32 +59,34 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
set CLASSPATH=
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal

View File

@@ -1,89 +0,0 @@
#!/bin/sh
### This should be a pipeline, but for this example let use this ###
check_active_branch() {
if [ "$(git rev-parse --abbrev-ref HEAD)" != "$1" ]; then
echo "Error: The current branch is not $1."
exit 1
fi
}
check_uncommitted_changes() {
if [ -n "$(git status --porcelain)" ]; then
echo "Error: There are uncommitted changes in the repository."
exit 1
fi
}
prepare_environment() {
git fetch origin
}
check_last_commit() {
last_commit_message=$(git log -1 --pretty=format:%s)
if [ "$last_commit_message" = "[RELEASE] - bump version" ]; then
echo "Warning: Nothing to release!!!"
exit 1
fi
}
check_differences() {
if ! git diff --quiet origin/"$1" "$1"; then
echo "Error: The branches origin/$1 and $1 have differences."
exit 1
fi
}
un_snapshot_version() {
sed -i "s/\($1\s*=\s*[0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/" gradle.properties
}
current_version() {
awk -F '=' '/version\s*=\s*[0-9.]*/ {gsub(/^ +| +$/,"",$2); print $2}' gradle.properties
}
stage_files() {
for file in "$@"; do
if git diff --exit-code --quiet -- "$file"; then
echo "No changes in $file"
else
git add "$file"
echo "Changes in $file staged for commit"
fi
done
}
commit_change() {
stage_files gradle.properties
git commit -m "[RELEASE] - $1"
git push --porcelain origin master
}
add_release_tag() {
gitTag="v$(current_version)"
git tag -a "$gitTag" -m "Release version $gitTag"
git push --porcelain origin "$gitTag"
}
snapshot_version() {
new_version="$(current_version | awk -F '.' '{print $1 "." $2+1 ".0"}')"
sed -i "s/\(version\s*=\s*\)[0-9.]*/\1$new_version-SNAPSHOT/" gradle.properties
}
# check and prepare for release
check_active_branch master
check_uncommitted_changes
prepare_environment
check_last_commit
check_differences master
# un-snapshot version for release
un_snapshot_version version
un_snapshot_version catalog
# release changes and prepare for next release
commit_change "release version: $(current_version)"
add_release_tag
snapshot_version
commit_change 'bump version'

View File

@@ -1,11 +1,13 @@
package ltd.hlaeja.plugin
import ltd.hlaeja.plugin.extension.ConfigExtension
import ltd.hlaeja.plugin.extension.InfoExtension
import ltd.hlaeja.plugin.extension.GitExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import ltd.hlaeja.plugin.extension.InfoExtension.Companion.PLUGIN_NAME as INFO_PLUGIN_NAME
import ltd.hlaeja.plugin.extension.GitExtension.Companion.PLUGIN_NAME as GIT_PLUGIN_NAME
import ltd.hlaeja.plugin.extension.ConfigExtension.Companion.PLUGIN_NAME as CONFIG_PLUGIN_NAME
@Suppress("unused")
class CorePlugin : Plugin<Project> {
@@ -16,13 +18,21 @@ class CorePlugin : Plugin<Project> {
override fun apply(project: Project) {
gitExtension(project)
infoExtension(project)
configExtension(project)
}
private fun configExtension(
project: Project,
): ConfigExtension = project.extensions
.create(CONFIG_PLUGIN_NAME, ConfigExtension::class.java, project)
private fun infoExtension(
project: Project,
): InfoExtension = project.extensions.create(INFO_PLUGIN_NAME, InfoExtension::class.java, project)
): InfoExtension = project.extensions
.create(INFO_PLUGIN_NAME, InfoExtension::class.java, project)
private fun gitExtension(
project: Project,
): GitExtension = project.extensions.create(GIT_PLUGIN_NAME, GitExtension::class.java, project)
): GitExtension = project.extensions
.create(GIT_PLUGIN_NAME, GitExtension::class.java, project)
}

View File

@@ -0,0 +1,31 @@
package ltd.hlaeja.plugin.extension
import java.lang.System.getenv
import org.gradle.api.Project
abstract class ConfigExtension(private val project: Project) {
companion object {
const val PLUGIN_NAME = "config"
const val EMPTY = ""
}
fun find(
property: String,
environment: String,
): String? = findProperty(property) ?: findEnvironment(environment)
fun findOrDefault(
property: String,
environment: String,
default: String = EMPTY,
): String = findProperty(property) ?: findEnvironment(environment) ?: default
private fun findProperty(
property: String,
) = project.findProperty(property)?.toString()
private fun findEnvironment(
environment: String,
): String? = getenv(environment)
}

View File

@@ -12,7 +12,7 @@ abstract class GitExtension(private val project: Project) {
private const val HASH_LENGTH = 8
private const val SNAPSHOT = "-SNAPSHOT"
private const val UNAVAILABLE = "n/a"
private val PRIMARY_BRANCHES = setOf("master")
private val PRIMARY_BRANCHES = setOf("master", "develop")
}
fun version(): String = when {

View File

@@ -0,0 +1,112 @@
package ltd.hlaeja.plugin.extension
import org.assertj.core.api.Assertions.assertThat
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
/**
* This test uses TEST_ENV set in gradle test task, and project extension to pretend to be a project property.
*/
class ConfigExtensionTest {
companion object {
const val EXTENSION = "config"
const val PLUGIN_ID = "ltd.hlaeja.plugin.hlaeja-core-plugin"
const val PROJECT_NAME = "test-project"
const val SNAPSHOT_VERSION = "0.0.0-SNAPSHOT"
}
lateinit var project: Project
lateinit var configExtension: ConfigExtension
@BeforeEach
fun beforeEach() {
project = ProjectBuilder.builder()
.withName(PROJECT_NAME)
.build()
project.version = SNAPSHOT_VERSION
project.pluginManager.apply(PLUGIN_ID)
project.extensions.add(
"testProperty",
object {
override fun toString(): String = "hlæja"
},
)
configExtension = project.extensions.getByName(EXTENSION) as ConfigExtension
}
@Nested
inner class FindTest {
@Test
fun `property or environment find property`() {
// when
val result = configExtension.find("testProperty", "TEST_PROPERTY")
// then
assertThat(result).isEqualTo("hlæja")
}
@Test
fun `property or environment find environment`() {
// when
val result = configExtension.find("test_env", "TEST_ENV")
// then
assertThat(result).isEqualTo("hlæja")
}
@Test
fun `property or environment find nothing`() {
// when
val result = configExtension.find("test", "TEST")
// then
assertThat(result).isNull()
}
}
@Nested
inner class FindOrDefaultTest {
@Test
fun `property, environment, or default find property`() {
// when
val result = configExtension.findOrDefault("testProperty", "TEST_PROPERTY")
// then
assertThat(result).isEqualTo("hlæja")
}
@Test
fun `property, environment, or default find environment`() {
// when
val result = configExtension.findOrDefault("test_env", "TEST_ENV")
// then
assertThat(result).isEqualTo("hlæja")
}
@Test
fun `property, environment, or default find empty`() {
// when
val result = configExtension.findOrDefault("test", "TEST")
// then
assertThat(result).isEmpty()
}
@Test
fun `property, environment, or default find defined response`() {
// when
val result = configExtension.findOrDefault("test", "TEST", "value")
// then
assertThat(result).isEqualTo("value")
}
}
}