Skip to content

Commit

Permalink
#545 Allow "v" prefix for version numbers (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada authored Mar 15, 2024
1 parent f97ed72 commit 6d9a297
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: "1.22"
cache-dependency-path: .github/workflows/ci-build.yml
- name: Install Go tools
run: go install github.com/google/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_linux_build_on_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: "1.22"
- name: Cache Go modules
uses: actions/cache@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_on_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: "1.22"
- name: Cache Go modules
uses: actions/cache@v4
with:
Expand Down
1 change: 1 addition & 0 deletions doc/changes/changes_4.2.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Code name:

* #546: Updated template for file `.settings/org.eclipse.jdt.core.prefs`
* #542: Prefixed release letter on GitHub with version number
* #545: Fix parsing of Go version numbers with a `v` prefix

## Dependency Updates

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,28 @@ public List<ValidationFinding> validate() {
LOG.info(() -> "No git tag exists, accepting " + this.projectVersion + " as valid.");
return emptyList();
}
final String previousVersion = latestReleaseCommit.get().getTag();
if (isValidSuccessor(previousVersion)) {
final String previousGitTag = latestReleaseCommit.get().getTag();
if (isValidSuccessor(previousGitTag)) {
return emptyList();
}
return List.of(SimpleValidationFinding.withMessage(ExaError.messageBuilder("E-PK-CORE-184")
.message("Project version {{current version}} is not a valid successor of {{previous version}}.",
this.projectVersion, previousVersion)
this.projectVersion, previousGitTag)
.mitigation("Only increment one of major, minor or patch version.").toString()).build());
}

private boolean isValidSuccessor(final String previousVersion) {
final Semver current = new Semver(this.projectVersion).toStrict();
final Semver previous = new Semver(previousVersion).toStrict();
private boolean isValidSuccessor(final String previousGitTag) {
final Semver current = parseVersion(this.projectVersion);
final Semver previous = parseVersion(previousGitTag);
return previous.nextMajor().equals(current) //
|| previous.nextMinor().equals(current) //
|| previous.nextPatch().equals(current);
}

private Semver parseVersion(String version) {
if (version.startsWith("v")) {
version = version.substring(1);
}
return new Semver(version);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: "1.22"
cache-dependency-path: |
go.sum
**/go.sum
.github/workflows/project-keeper-verify.yml
.github/workflows/project-keeper.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches: ["main"]
pull_request:
workflow_dispatch:

jobs:
build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class VersionIncrementValidatorTest {
@CsvSource(nullValues = "NULL", value = { //
"NULL, 1.2.3, NULL", //
"1.2.3, 1.2.4, NULL", //
"1.2.3, v1.2.4, NULL", //
"v1.2.3, 1.2.4, NULL", //
"1.2.3, 1.3.0, NULL", //
"1.2.3, 2.0.0, NULL", //
"0.0.0, 0.0.1, NULL", //
Expand All @@ -44,14 +46,16 @@ class VersionIncrementValidatorTest {
"1.0.0, 1.1.0, NULL", //
"1.0.0, 2.0.0, NULL", //
"1.2.3, 1.2.3, E-PK-CORE-184: Project version '1.2.3' is not a valid successor of '1.2.3'.",
"1.2.3, v1.2.3, E-PK-CORE-184: Project version 'v1.2.3' is not a valid successor of '1.2.3'.",
"v1.2.3, 1.2.3, E-PK-CORE-184: Project version '1.2.3' is not a valid successor of 'v1.2.3'.",
"1.2.3, 1.2.2, E-PK-CORE-184: Project version '1.2.2' is not a valid successor of '1.2.3'.",
"1.2.3, 1.2.5, E-PK-CORE-184: Project version '1.2.5' is not a valid successor of '1.2.3'.",
"1.2.3, 1.1.0, E-PK-CORE-184: Project version '1.1.0' is not a valid successor of '1.2.3'.",
"1.2.3, 1.4.0, E-PK-CORE-184: Project version '1.4.0' is not a valid successor of '1.2.3'.",
"1.2.3, 0.0.0, E-PK-CORE-184: Project version '0.0.0' is not a valid successor of '1.2.3'.",
"1.2.3, 3.0.0, E-PK-CORE-184: Project version '3.0.0' is not a valid successor of '1.2.3'.", })
void validation(final String previousVersion, final String currentVersion, final String expectedFinding) {
final List<String> findings = getFindings(previousVersion, currentVersion);
void validation(final String previousGitTag, final String currentVersion, final String expectedFinding) {
final List<String> findings = getFindings(previousGitTag, currentVersion);
if (expectedFinding == null) {
assertThat(findings, emptyIterable());
} else {
Expand All @@ -60,9 +64,9 @@ void validation(final String previousVersion, final String currentVersion, final
}
}

private List<String> getFindings(final String previousVersion, final String currentVersion) {
private List<String> getFindings(final String previousGitTag, final String currentVersion) {
when(gitRepoMock.findLatestReleaseCommit(null)) //
.thenReturn(Optional.ofNullable(previousVersion) //
.thenReturn(Optional.ofNullable(previousGitTag) //
.map(v -> new TaggedCommit(null, v)));
return testee(currentVersion).validate().stream() //
.map(SimpleValidationFinding.class::cast) //
Expand Down

0 comments on commit 6d9a297

Please sign in to comment.