Files
de.captica.expert.devops/gradle/build-version.gradle
2024-03-25 16:35:50 +01:00

74 lines
2.0 KiB
Groovy

/*
* Enables version handling on build process
*
* Project: gradle
* Author: Marc Böhm <marc.boehm@captica.de>
* License: MIT License (see LICENSE.md)
*
* Copyright (c) captica GmbH est. 2021
*/
// Load external plugins
buildscript {
repositories {
gradlePluginPortal()
mavenCentral()
}
dependencies {
classpath 'me.qoomon:gradle-git-versioning-plugin:6.4.3'
}
}
// Apply plugins
apply plugin: me.qoomon.gradle.gitversioning.GitVersioningPlugin
// Setup versions handling
gitVersioning.apply {
refs {
branch('(feature|bugfix)/(?<feature>.+)') {
version = '${ref.feature}-SNAPSHOT'
}
branch('release/v(?<version>.*)') {
version = '${ref.version}-RC'
}
branch('.+') {
version = '${ref}-SNAPSHOT'
}
tag('v(?<version>.*)') {
version = '${ref.version}'
}
}
// optional fallback configuration in case of no matching ref configuration
rev {
version = '${commit}'
}
}
// Simple task to write the env shell script to register version env vars
task writeVersionFile() {
doLast {
new File(buildDir, 'env-setup.sh').text = """
#!/bin/sh
# Default env vars
export CAPTICA_APPLICATION_VERSION=${version}
export CAPTICA_APPLICATION_NAME=${project.name}
export CAPTICA_APPLICATION_FILE_BINARY=${bootJar.archiveFileName.get()}
export CAPTICA_APPLICATION_PORT=${applicationPort}
export CAPTICA_APPLICATION_JAVA_VERSION=${java.sourceCompatibility}
# Gitea/Github specific env variables
echo "CAPTICA_APPLICATION_VERSION=\$CAPTICA_APPLICATION_VERSION" >> \$GITHUB_ENV
echo "CAPTICA_APPLICATION_FILE_BINARY=\$CAPTICA_APPLICATION_FILE_BINARY" >> \$GITHUB_ENV
echo "CAPTICA_APPLICATION_NAME=\$CAPTICA_APPLICATION_NAME" >> \$GITHUB_ENV
echo "CAPTICA_APPLICATION_PORT=\$CAPTICA_APPLICATION_PORT" >> \$GITHUB_ENV
echo "CAPTICA_APPLICATION_JAVA_VERSION=\$CAPTICA_APPLICATION_JAVA_VERSION" >> \$GITHUB_ENV
"""
}
}
// Link up version file task to bootJar
tasks.named('bootJar').configure {
dependsOn writeVersionFile
}