Skip to content

Commit

Permalink
Small exercise in gradle task bumping versions
Browse files Browse the repository at this point in the history
  • Loading branch information
james-millner committed Apr 8, 2024
1 parent 062c5d3 commit 2565c55
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 19 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = false
max_line_length = 120
tab_width = 4

[Makefile]
indent_style = tab
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ build
/.idea/
.DS_STORE
/Makefile
/.tool-versions
/.editorconfig
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Kotlin Fit Converter

[![Kotlin](https://img.shields.io/badge/kotlin-1.9.23-blue.svg)](https://kotlinlang.org/)
[![Latest Release](https://img.shields.io/badge/0.4.5-Alpha-red)](https://github.com/example/garmin-fit-converter/releases)
[![Latest Release](https://img.shields.io/badge/0.4.6-alpha-red)](https://github.com/example/garmin-fit-converter/releases)
[![Gradle Build & Test](https://github.com/james-millner/kotlin-fit-converter/actions/workflows/gradle.yml/badge.svg)](https://github.com/james-millner/kotlin-fit-converter/actions/workflows/gradle.yml)

The Kotlin Fit Converter Library is a Kotlin-based utility that allows users to convert Garmin FIT files into different formats.
Expand Down
Binary file removed external-jar/fit.jar
Binary file not shown.
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
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

Expand All @@ -57,11 +57,11 @@ 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

Expand Down
72 changes: 66 additions & 6 deletions kotlin-fit-converter-lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.FileWriter

/*
* This file was generated by the Gradle 'init' task.
Expand Down Expand Up @@ -29,16 +31,15 @@ plugins {
}

group = "kjm.fit.converter"
version = "0.4.5-alpha"
version = "0.4.6-alpha"

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}

dependencies {
implementation(files("../external-jar/fit.jar"))

implementation("com.garmin:fit:21.135.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.6.3")

Expand All @@ -50,10 +51,18 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.2")
}

val jvmTargetMajorVersion = 21

// Apply a specific Java toolchain to ease working on different environments.
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(19))
languageVersion.set(JavaLanguageVersion.of(jvmTargetMajorVersion))
}
}

tasks.withType<KotlinCompile>() {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_21)
}
}

Expand Down Expand Up @@ -111,4 +120,55 @@ tasks.register("copyDokkaDocs") {
logger.warn("Dokka documentation directory not found. Please ensure Dokka has been executed.")
}
}
}
}

tasks.register("bumpVersionAndUpdateReadme") {
group = "versioning"
description = "Bumps the version and updates the README file"

doLast {
// Split the current version string into components
val versionParts = version.toString().split("-")
val versionComponents = versionParts[0].split(".").map { it.toInt() }.toMutableList()
val preRelease = if (versionParts.size > 1) "-${versionParts[1]}" else ""

// Increment the patch version
versionComponents[2]++

// Construct the new version string
val newVersionString = "${versionComponents.joinToString(".")}$preRelease"

// Update the version in the build.gradle.kts file
val buildFile = File("kotlin-fit-converter-lib/build.gradle.kts")
val buildFileLines = buildFile.readLines()
val updatedBuildFileLines = buildFileLines.map { line ->
if (line.startsWith("version =")) {
"version = \"$newVersionString\""
} else {
line
}
}

FileWriter(buildFile).use { writer ->
updatedBuildFileLines.forEach { writer.write("$it\n") }
}

// Update the version badge in the README file
val readmeFile = File("README.md")
val readmeFileLines = readmeFile.readLines()
val updatedReadmeFileLines = readmeFileLines.map { line ->
if (line.contains("[![Latest Release]")) {
val newBadge = "[![Latest Release](https://img.shields.io/badge/$newVersionString-red)](https://github.com/example/garmin-fit-converter/releases)"
newBadge
} else {
line
}
}

FileWriter(readmeFile).use { writer ->
updatedReadmeFileLines.forEach { writer.write("$it\n") }
}

println("Version bumped to $newVersionString and README file updated")
}
}
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pluginManagement {

plugins {
// Apply the foojay-resolver plugin to allow automatic download of JDKs
id("org.gradle.toolchains.foojay-resolver-convention") version "0.4.0"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
}

rootProject.name = "kotlin-fit-converter"
Expand Down

0 comments on commit 2565c55

Please sign in to comment.