The Gradle Semantic Versioning
is a sophisticated gradle plugin, helping developers to update their versions of gradle builds,
by processing through the git history.
Setting up the plugin requires the following steps:
-
Add the Plugin to your
build.gradle.kts
plugins { id("io.datalbry.plugin.semver") version "<version>" }
-
The version can now be updated using
./gradlew updateReleaseVersion
The Plugin supports adding multiple version schemas, this might be especially useful for alpha and beta releases.
-
Add the Pre Release Version in the
build.gradle.kts
semver { version("snapshot", "SNAPSHOT") version("alpha", "alpha.{COMMIT_TIMESTAMP}") }
-
The version can now be updated using:
-
./gradlew updateSnapshotVersion
for snapshot version -
./gradlew updateAlphaVersion
for alpha version
-
NOTE: The latest versions can be found [here](https://github.com/datalbry/gradle-semver-plugin/tags).
The plugin does not support creating GitHub releases natively. The plugin utilizes git tags to create Releases and writes the release-notes to the git tag. Fortunately this can easily be used to create GitHub Releases using a simple GitHub action.
The following GitHub action derives the latest version using the commit history and also creates a git tag containing the release notes as message.
name: Release
on:
workflow_dispatch:
jobs:
release:
name: Release Version
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
with:
# Number of commits to fetch. 0 indicates all history for all branches and tags.
fetch-depth: 0
- name: Set up JDK
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '15'
- name: Build and test
run: ./gradlew check -i
# This step will update the version in the `gradle.properties` to the latest one calculated by the commit history
- name: Update Version
run: >
./gradlew updateReleaseVersion -i
# -----------------------------------------------
# --- You should add your specific steps here ---
# -----------------------------------------------
-
# This will create a git tag with the latest version, including the RELEASE-NOTES in the tag message
- name: Tag
run: >
./gradlew tag -i
- name: Generate Commit Message
run: |
echo "##[set-output name=message;][CI] Release version $(./gradlew -q printVersion)"
id: generate_commit_message
- name: Push Commit
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: ${{ steps.generate_commit_message.outputs.message }}
push_options: --follow-tags
Creating the following action creates a Github Release whenever a semantic Release Tag is being pushed.
name: Create GitHub Release
on:
push:
tags: [
'v[0-9]+.[0-9]+.[0-9]+',
'v[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+'
]
jobs:
release-notes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
- name: Get Release Notes from Tag
run: 'echo "$(git tag -l --format="%(contents:body)" $GITHUB_REF_NAME)" > RELEASE_NOTES'
- name: Create Release
uses: softprops/action-gh-release@v1
with:
body_path: RELEASE_NOTES
The Plugin is highly configurable. The following parameters can be set using either the extension or can be passed as parameters.
Parameter | Description | Value | Default |
---|---|---|---|
|
The location of the properties file to write the version property to |
|
|
|
Adds a new version, such as SNAPSHOT, Alpha or Beta to the plugin. Versions are completely configurable. |
|
|
|
Adds type alias for the Release Notes Formatter. E.g. ( |
|
( |
The version templates of the semver plugin MUST fulfill the SemVer standard. Besides that, we support the following placeholder:
Placeholder | Substitution |
---|---|
|
Will be substituted with the timestamp of the latest commit (epoch millis). |
|
Will be substituted with the current timestamp (epoch millis). |
Copyright 2021 DataLbry Technologies UG
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
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.