Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2c48129
Add Git integration with enums, Maven parameters, and process utilities
bsels Jan 21, 2026
46a17e9
Add unit tests for `Git` enum covering methods and functionality
bsels Jan 21, 2026
aaf4bd7
Add unit tests for `ProcessUtils` covering `gitCommit` and `gitStashF…
bsels Jan 21, 2026
4a8ce9b
Add customizable commit messages for version and Markdown file updates
bsels Jan 21, 2026
07b2469
Replace `%d` placeholders with `{key}` syntax for customizable commit…
bsels Jan 22, 2026
29d163a
Refactor file deletion logic and add file stashing in `UpdatePomMojo`
bsels Jan 22, 2026
ef5715e
Add unit tests for `Utils.prepareFormatString`
bsels Jan 22, 2026
1270ab7
Created version Markdown file for 1 project(s)
bsels Jan 22, 2026
ffac1bf
Created version Markdown file for 1 project(s)
bsels Jan 22, 2026
c60be0b
Add `ProcessBuilder` mocks and assertions for Git operations in unit …
bsels Jan 22, 2026
ce6e6a4
Update README with new configuration properties for customizable comm…
bsels Jan 22, 2026
2a6c854
Add support for executing scripts during version updates
bsels Jan 23, 2026
be95b86
Add script execution for version updates
bsels Jan 23, 2026
78fac86
Update README to document `versioning.update.scripts`
bsels Jan 23, 2026
1a55db9
Add unit tests for `ProcessUtils.executeScripts`
bsels Jan 24, 2026
d370050
Add unit tests for script execution in `UpdatePomMojoTest`
bsels Jan 24, 2026
e039e22
Add `update-readme.sh` script to automate README version updates
bsels Jan 24, 2026
fe2bc56
Update Git operation mode and integrate README version update script
bsels Jan 24, 2026
386cb43
Fix variable quoting in `update-readme.sh` for `GIT_STASH` check
bsels Jan 24, 2026
e7dad8e
Created version Markdown file for 1 project(s)
bsels Jan 24, 2026
a35a31d
Improve README formatting and clarify `versioning.update.scripts` det…
bsels Jan 24, 2026
267b213
Update script path handling to use absolute paths in `UpdatePomMojo`
bsels Jan 24, 2026
1b3e034
Add JaCoCo plugin for code coverage reporting
bsels Jan 24, 2026
f7dbed0
Add JaCoCo plugin for code coverage reporting
bsels Jan 24, 2026
a4f6934
Configure JaCoCo report format and adjust coverage report packaging i…
bsels Jan 24, 2026
239fb9b
Strip trailing whitespace in YAML generation and tests
bsels Jan 24, 2026
e4fe7dc
Add placeholder-based string formatting utility and tests
bsels Jan 24, 2026
fd2ab64
Add support for customizable version header format in changelog updates
bsels Jan 24, 2026
1c49fe1
Rename `versioning.version.file` to `versioning.version.header` and u…
bsels Jan 24, 2026
1641a5b
Fix inconsistent case usage of 'Markdown' in method documentation and…
bsels Jan 24, 2026
dffbc5c
Add `MAVEN_GPG_PASSPHRASE` secret to release workflow and simplify Ma…
bsels Jan 24, 2026
01ef5e4
Make version header configurable with placeholders for version and da…
bsels Jan 24, 2026
0dacda4
Add support for artifact identification parameter and custom serializ…
bsels Jan 24, 2026
a7987ba
Add key-based deserialization for `MavenArtifact` and enhance YAML se…
bsels Jan 24, 2026
d82b0aa
Add tests for custom (de)serialization of `MavenArtifact`
bsels Jan 24, 2026
644b0a5
Add tests for artifact-only versioning and version bump in multiple m…
bsels Jan 24, 2026
1d752ec
Created version Markdown file for 1 project(s)
bsels Jan 24, 2026
c6b8b98
Document support for configurable artifact identification modes. Upda…
bsels Jan 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions .github/workflows/push-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,12 @@ jobs:
set -e
./mvnw --no-transfer-progress --batch-mode install -Dgpg.skip
CURRENT_VERSION=$(./mvnw --no-transfer-progress --batch-mode help:evaluate -Dexpression=project.version -q -DforceStdout)
./mvnw --no-transfer-progress --batch-mode io.github.bsels:semantic-version-maven-plugin:$CURRENT_VERSION:update
./mvnw --no-transfer-progress --batch-mode io.github.bsels:semantic-version-maven-plugin:$CURRENT_VERSION:update \
-Dversioning.update.scripts=./update-readme.sh -Dversioning.git=COMMIT
VERSION=$(./mvnw --no-transfer-progress --batch-mode help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Update version in README
- name: Create tag and push
run: |
sed -i 's/<version>[0-9]\+[.][0-9]\+[.][0-9]\+<\/version>/<version>${{ steps.bumpVersion.outputs.version }}<\/version>/g' README.md
- name: Commit changes
run: |
git add .versioning CHANGELOG.md pom.xml
git commit -am "Released ${{ steps.bumpVersion.outputs.version }} [skip ci]"
git tag "v${{ steps.bumpVersion.outputs.version }}"
git push
git push origin tag "v${{ steps.bumpVersion.outputs.version }}"
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/release-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
required: true
type: string
permissions:
contents: read
contents: write
jobs:
build:
name: Build
Expand Down Expand Up @@ -43,5 +43,13 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SERVER_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
SERVER_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_KEY_PASSWORD }}
run: |
./mvnw --batch-mode --no-transfer-progress clean deploy -Dgpg.passphrase=${{ secrets.GPG_KEY_PASSWORD }}
./mvnw --batch-mode --no-transfer-progress clean deploy
- name: Zip coverage report
working-directory: ./target/site/jacoco
run: |
zip -r9 ../../../coverage-report.zip *
- name: Attach coverage report to release
run: |
gh release upload ${{ github.event.release.tag_name }} coverage-report.zip
9 changes: 9 additions & 0 deletions .versioning/versioning-20260122190538.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
io.github.bsels:semantic-version-maven-plugin: "PATCH"
---

Bumped dependencies:

- Jackson from 2.20.1 to 2.21.0
- JUnit from 6.0.1 to 6.0.2
- Central publishing maven plugin from 0.9.0 to 0.10.0
5 changes: 5 additions & 0 deletions .versioning/versioning-20260122190648.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
io.github.bsels:semantic-version-maven-plugin: "MINOR"
---

Added support for git for automated stashing or committing from files.
5 changes: 5 additions & 0 deletions .versioning/versioning-20260124102122.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
io.github.bsels:semantic-version-maven-plugin: "MINOR"
---

Support additional script execution during version bump for more customization
5 changes: 5 additions & 0 deletions .versioning/versioning-20260124134430.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
io.github.bsels:semantic-version-maven-plugin: "MINOR"
---

Make the version header configurable with placeholders for the version and the date and allow custom date formats.
5 changes: 5 additions & 0 deletions .versioning/versioning-20260124151654.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
io.github.bsels:semantic-version-maven-plugin: "MINOR"
---

Added mode to only use artifact ID as identifier in the file based versioning.
71 changes: 48 additions & 23 deletions README.md

Large diffs are not rendered by default.

33 changes: 29 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<properties>
<java.version>17</java.version>
<!--region Plugin versions -->
<jacoco.version>0.8.14</jacoco.version>
<maven.plugin.api.version>3.9.12</maven.plugin.api.version>
<maven.enforcer.plugin.version>3.6.2</maven.enforcer.plugin.version>
<maven.dependency.plugin.version>3.9.0</maven.dependency.plugin.version>
Expand All @@ -49,13 +50,13 @@
<maven.gpg.plugin.version>3.2.8</maven.gpg.plugin.version>
<maven.javadoc.plugin.version>3.12.0</maven.javadoc.plugin.version>
<maven.source.plugin.version>3.4.0</maven.source.plugin.version>
<central.publishing.maven.plugin.version>0.9.0</central.publishing.maven.plugin.version>
<central.publishing.maven.plugin.version>0.10.0</central.publishing.maven.plugin.version>
<!--endregion-->
<!--region Dependency versions -->
<assertj.version>3.27.6</assertj.version>
<commonmark.version>0.27.0</commonmark.version>
<jackson.version>2.20.1</jackson.version>
<junit.version>6.0.1</junit.version>
<jackson.version>2.21.0</jackson.version>
<junit.version>6.0.2</junit.version>
<maven.plugin.version>3.15.2</maven.plugin.version>
<mockito.version>5.21.0</mockito.version>
<!--endregion-->
Expand All @@ -69,6 +70,30 @@

<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<formats>
<format>HTML</format>
</formats>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
Expand Down Expand Up @@ -119,7 +144,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<argLine>-javaagent:${org.mockito:mockito-core:jar}</argLine>
<argLine>@{argLine} -javaagent:${org.mockito:mockito-core:jar}</argLine>
</configuration>
</plugin>
<plugin>
Expand Down
55 changes: 52 additions & 3 deletions src/main/java/io/github/bsels/semantic/version/BaseMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import io.github.bsels.semantic.version.models.MavenArtifact;
import io.github.bsels.semantic.version.models.SemanticVersionBump;
import io.github.bsels.semantic.version.models.VersionMarkdown;
import io.github.bsels.semantic.version.parameters.ArtifactIdentifier;
import io.github.bsels.semantic.version.parameters.Git;
import io.github.bsels.semantic.version.parameters.Modus;
import io.github.bsels.semantic.version.utils.MarkdownUtils;
import io.github.bsels.semantic.version.utils.ProcessUtils;
import io.github.bsels.semantic.version.utils.Utils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
Expand Down Expand Up @@ -123,13 +126,30 @@ public abstract sealed class BaseMojo extends AbstractMojo permits CreateVersion
@Parameter(property = "versioning.directory", required = true, defaultValue = ".versioning")
protected Path versionDirectory = Path.of(".versioning");

/// Represents the Git version control system configuration for the Maven plugin.
/// Used to manage versioning-related operations specific to Git.
///
/// By default, the value is set to [Git#NO_GIT],
/// indicating that no Git-specific actions will be performed unless explicitly configured.
///
/// This field can be overridden by specifying the Maven property `versioning.git`.
@Parameter(property = "versioning.git", required = true, defaultValue = "NO_GIT")
protected Git git = Git.NO_GIT;

/// Indicates whether the original POM file and CHANGELOG file should be backed up before modifying its content.
///
/// This parameter is configurable via the Maven property `versioning.backup`.
/// When set to `true`, a backup of the POM/CHANGELOG file will be created before any updates are applied.
/// The default value for this parameter is `false`, meaning no backup will be created unless explicitly specified.
@Parameter(property = "versioning.backup", defaultValue = "false")
boolean backupFiles = false;
@Parameter(property = "versioning.backup", required = true, defaultValue = "false")
protected boolean backupFiles = false;

/// Specifies the mode of artifact identification within a repository or dependency context.
/// This parameter is configurable via the Maven property `versioning.identifier`.
/// The default value is [ArtifactIdentifier#GROUP_ID_AND_ARTIFACT_ID],
/// which includes both the group ID and artifact ID.
@Parameter(property = "versioning.identifier", required = true, defaultValue = "GROUP_ID_AND_ARTIFACT_ID")
protected ArtifactIdentifier identifier = ArtifactIdentifier.GROUP_ID_AND_ARTIFACT_ID;

/// Default constructor for the BaseMojo class.
/// Initializes the instance by invoking the superclass constructor.
Expand Down Expand Up @@ -210,7 +230,12 @@ protected final List<VersionMarkdown> getVersionMarkdowns() throws MojoExecution
.toList();
List<VersionMarkdown> parsedMarkdowns = new ArrayList<>();
for (Path markdownFile : markdownFiles) {
parsedMarkdowns.add(MarkdownUtils.readVersionMarkdown(log, markdownFile));
parsedMarkdowns.add(MarkdownUtils.readVersionMarkdown(
log,
markdownFile,
identifier,
session.getCurrentProject().getGroupId()
));
}
versionMarkdowns = List.copyOf(parsedMarkdowns);
} catch (IOException e) {
Expand Down Expand Up @@ -333,6 +358,7 @@ protected void writeMarkdownFile(Node markdownNode, Path markdownFile)
} else {
MarkdownUtils.writeMarkdownFile(markdownFile, markdownNode, backupFiles);
}
stashFiles(List.of(markdownFile));
}

/// Simulates writing to a file by using a [StringWriter].
Expand All @@ -354,6 +380,29 @@ protected void dryRunWriteFile(MojoThrowingConsumer<StringWriter> consumer, Path
}
}

/// Stashes the provided list of file paths using Git if stashing is enabled and not in dry-run mode.
///
/// @param files the list of file paths to be stashed
/// @throws MojoExecutionException if an error occurs during the stashing process
protected void stashFiles(List<Path> files) throws MojoExecutionException {
if (!dryRun && git.isStash()) {
ProcessUtils.gitStashFiles(files);
}
}

/// Commits changes to a Git repository if specific conditions are met.
/// The commit operation will only be performed when:
/// - Git commit mode is enabled ([Git#isCommit] returns true)
/// - Dry-run mode is disabled (dryRun is false)
///
/// @param message The commit message to use for the commit operation.
/// @throws MojoExecutionException If the commit operation fails.
protected void commit(String message) throws MojoExecutionException {
if (!dryRun && git.isCommit()) {
ProcessUtils.gitCommit(message);
}
}

/// Functional interface that represents an operation that accepts a single input
/// and can throw [MojoExecutionException] and [MojoFailureException].
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.bsels.semantic.version;

import io.github.bsels.semantic.version.models.MavenArtifact;
import io.github.bsels.semantic.version.models.PlaceHolderWithType;
import io.github.bsels.semantic.version.models.SemanticVersionBump;
import io.github.bsels.semantic.version.utils.MarkdownUtils;
import io.github.bsels.semantic.version.utils.ProcessUtils;
Expand All @@ -13,6 +14,7 @@
import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.commonmark.node.Node;

Expand Down Expand Up @@ -56,6 +58,24 @@ public final class CreateVersionMarkdownMojo extends BaseMojo {
SemanticVersionBump.PATCH, SemanticVersionBump.MINOR, SemanticVersionBump.MAJOR
);

/// Represents the commit message for creating a version Markdown file.
/// This variable is essential for customizing the commit message applied when creating a version Markdown file.
///
/// The placeholder `"{numberOfProjects}"` is used to dynamically insert the number of projects for which
/// the version file was created into the message.
///
/// Attributes:
/// - property: Specifies the configuration property key to override this value.
/// - required: Signifies that this parameter is mandatory.
/// - defaultValue: If not explicitly specified,
/// defaults to `"Created version Markdown file for {numberOfProjects} project(s)"`.
@Parameter(
property = "versioning.commit.message.create",
required = true,
defaultValue = "Created version Markdown file for {numberOfProjects} project(s)"
)
String commitMessage = "Created version Markdown file for {numberOfProjects} project(s)";

/// Default constructor for the CreateVersionMarkdownMojo class.
/// Invokes the superclass constructor to initialize the instance.
/// This constructor is typically used by the Maven framework during the build lifecycle.
Expand All @@ -79,6 +99,11 @@ public CreateVersionMarkdownMojo() {
/// @throws MojoFailureException if the operation to process or create the version Markdown file fails.
@Override
protected void internalExecute() throws MojoExecutionException, MojoFailureException {
commitMessage = Utils.prepareFormatString(
commitMessage,
List.of(new PlaceHolderWithType("numberOfProjects", "d"))
);

Log log = getLog();
List<MavenArtifact> projects = getProjectsInScope()
.map(mavenProject -> new MavenArtifact(mavenProject.getGroupId(), mavenProject.getArtifactId()))
Expand All @@ -93,14 +118,15 @@ protected void internalExecute() throws MojoExecutionException, MojoFailureExcep
return;
}

YamlFrontMatterBlock versionBumpHeader = MarkdownUtils.createVersionBumpsHeader(log, selectedProjects);
YamlFrontMatterBlock versionBumpHeader = MarkdownUtils.createVersionBumpsHeader(log, selectedProjects, identifier);
Node inputMarkdown = createChangelogEntry();
inputMarkdown.prependChild(versionBumpHeader);

Path versioningFolder = getVersioningFolder();
Utils.createDirectoryIfNotExists(versioningFolder);
Path versioningFile = Utils.resolveVersioningFile(versioningFolder);
writeMarkdownFile(inputMarkdown, versioningFile);
commit(commitMessage.formatted(selectedProjects.size()));
}

/// Creates a changelog entry by either taking user input directly or by leveraging an external editor.
Expand Down
Loading