Skip to content

Commit

Permalink
feature: Use commit-and-tag-version for Release Management
Browse files Browse the repository at this point in the history
  • Loading branch information
wba2hi committed Nov 7, 2023
1 parent 0521031 commit ea0866a
Show file tree
Hide file tree
Showing 10 changed files with 775 additions and 206 deletions.
8 changes: 8 additions & 0 deletions .versionrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"bumpFiles": [
{
"filename": "version",
"type": "plain-text"
}
]
}
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ android {
applicationId = "org.eclipse.kuksa.testapp"
minSdk = 27
targetSdk = 34
versionCode = rootProject.extra["projectVersionCode"].toString().toInt()
versionCode = 1
versionName = rootProject.extra["projectVersion"].toString()
vectorDrawables {
useSupportLibrary = true
Expand Down
59 changes: 59 additions & 0 deletions buildSrc/src/main/kotlin/org/eclipse/kuksa/util/Version.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/

package org.eclipse.kuksa.util

import java.util.Locale

class Version(semanticVersion: String) {

val major: Int

val minor: Int

val patch: Int

var suffix: String = ""

val version: String
get() {
var version = "$major.$minor.$patch"
if (suffix.isNotEmpty()) {
version += "-$suffix"
}
return version
}

val versionCode: Int
get() {
val decorator = "10"
val paddedMajorVersion = String.format(Locale.ROOT, "%02d", major)
val paddedMinorVersion = String.format(Locale.ROOT, "%02d", minor)
val paddedPatchVersion = String.format(Locale.ROOT, "%02d", patch)

return "$decorator$paddedMajorVersion$paddedMinorVersion$paddedPatchVersion".toInt()
}

init {
val versions = semanticVersion.trim().split(".")
major = versions[0].toInt()
minor = versions[1].toInt()
patch = versions[2].toInt()
}
}
102 changes: 0 additions & 102 deletions buildSrc/src/main/kotlin/org/eclipse/kuksa/util/VersionProperties.kt

This file was deleted.

60 changes: 17 additions & 43 deletions buildSrc/src/main/kotlin/version.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,68 +1,42 @@
import org.eclipse.kuksa.util.VersionProperties
import org.eclipse.kuksa.util.Version

val properties = VersionProperties("$rootDir/version.properties")
properties.load()
val file = File("$rootDir/version")
val semanticVersion = file.readText()
val version = Version(semanticVersion)

rootProject.extra["projectVersion"] = properties.version
rootProject.extra["projectVersionCode"] = properties.versionCode

tasks.register("increaseMajorVersion") {
group = "version"
doLast {
properties.major += 1
properties.minor = 0
properties.patch = 0
properties.store()
}
}

tasks.register("increaseMinorVersion") {
group = "version"
doLast {
properties.minor += 1
properties.patch = 0
properties.store()
}
}

tasks.register("increasePatchVersion") {
group = "version"
doLast {
properties.patch += 1
properties.store()
}
}
updateExtras()

tasks.register("setReleaseVersion") {
group = "version"
doLast {
properties.suffix = ""
properties.store()
version.suffix = ""

updateExtras()
}
}

tasks.register("setSnapshotVersion") {
group = "version"
doLast {
properties.suffix = "SNAPSHOT"
properties.store()
version.suffix = "SNAPSHOT"

updateExtras()
}
}

tasks.register("printVersion") {
group = "version"
doLast {
val version = properties.version
val version = version.version

println("VERSION=$version")
}

mustRunAfter("setReleaseVersion", "setSnapshotVersion")
}

tasks.register("printVersionCode") {
group = "version"
doLast {
val versionCode = properties.versionCode

println("VERSION_CODE=$versionCode")
}
fun updateExtras() {
rootProject.extra["projectVersion"] = version.version
rootProject.extra["projectVersionCode"] = version.versionCode
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
"devDependencies": {
"@commitlint/cli": "^17.6.6",
"@commitlint/config-conventional": "^17.6.6",
"commit-and-tag-version": "^11.3.0",
"husky": "^8.0.3"
},
"scripts": {
"postinstall": "husky install"
"postinstall": "husky install",
"release": "commit-and-tag-version"
}
}
19 changes: 19 additions & 0 deletions standard-version-updater.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// standard-version-updater.js
const stringifyPackage = require('stringify-package')
const detectIndent = require('detect-indent')
const detectNewline = require('detect-newline')

module.exports.readVersion = function (contents) {
return JSON.parse(contents).tracker.package.version;
}

module.exports.writeVersion = function (contents, version) {
const versions = version.split(".")
const major = versions[0]
const minor = versions[1]
const patch = versions[2]

return `MAJOR=${major}
MINOR=${minor}
PATCH=${PATCH}`
}
1 change: 1 addition & 0 deletions version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0
6 changes: 0 additions & 6 deletions version.properties

This file was deleted.

Loading

0 comments on commit ea0866a

Please sign in to comment.