Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 21 additions & 7 deletions .github/workflows/pre_release_on_develop_merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,52 @@ on:
- develop

jobs:
build-and-release:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up JDK 18
uses: actions/setup-java@v3
with:
java-version: '18'
distribution: 'adopt'
cache: maven

- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build and Test with Maven
run: mvn verify

build-and-release:
needs: build-and-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 18
uses: actions/setup-java@v3
with:
java-version: '18'
distribution: 'adopt'
cache: maven
- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build with Maven
run: mvn package

- name: Extract Version from POM
id: extract_version
run: echo "version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_OUTPUT

- name: Generate Timestamp
id: gen_timestamp
run: echo "timestamp=$(date +'%Y%m%d_%H%M%S')" >> $GITHUB_OUTPUT

- name: Create Pre-release
id: create_release
uses: actions/create-release@v1
Expand All @@ -47,7 +62,6 @@ jobs:
release_name: Pre-release ${{ steps.extract_version.outputs.version }} (${{ steps.gen_timestamp.outputs.timestamp }})
draft: false
prerelease: true

- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.dazednconfused</groupId>
<artifactId>macatalauncher</artifactId>
<version>0.3.3</version>
<version>0.4.0</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static void openReleaseInDefaultBrowser(Version tag) {
public static Optional<Version> getLatestReleaseTag() {
LOGGER.info("Querying latest release's tag from internet repository...");

return Try.of(() -> getLatestReleaseTagFromGithub(GITHUB_REPOSITORY_OWNER, GITHUB_REPOSITORY_NAME, false))
return Try.of(() -> getLatestReleaseTagFromGithub(GITHUB_REPOSITORY_OWNER, GITHUB_REPOSITORY_NAME, true))
.map(Version::new)
.onFailure(t -> LOGGER.error("There was an error retrieving the latest release from remote repository [{}/{}]", GITHUB_REPOSITORY_OWNER, GITHUB_REPOSITORY_NAME, t))
.toJavaOptional();
Expand Down
80 changes: 59 additions & 21 deletions src/main/java/com/dazednconfused/catalauncher/update/Version.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,59 @@
package com.dazednconfused.catalauncher.update;

import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* @see <a href="https://stackoverflow.com/a/11024200">https://stackoverflow.com/a/11024200</a>
* */
public class Version implements Comparable<Version> {

private static final Pattern VERSION_PATTERN = Pattern.compile("^(?:prerelease-)?v?([0-9]+(\\.[0-9]+)*)(?:-(.+))?$");

private final String semver;
private final String preReleaseTag;
private final boolean isPreRelease;

public final String get() {
public String get() {
return this.semver;
}

public String getPreReleaseTag() {
return this.preReleaseTag;
}

public boolean isPreRelease() {
return this.isPreRelease;
}

/**
* Constructor.
* */
public Version(String semver) {
if (semver == null) {
* Constructs a Version object from a version string.
*
* @param versionString the version string, e.g., "v1.2.3", "prerelease-v1.2.3-alpha", etc.
*
* @throws IllegalArgumentException if the version string is null or does not match the expected format
*/
public Version(String versionString) {
if (versionString == null) {
throw new IllegalArgumentException("Version cannot be null");
}
if (!semver.matches("v?[0-9]+(\\.[0-9]+)*")) {
Matcher matcher = VERSION_PATTERN.matcher(versionString);
if (!matcher.matches()) {
throw new IllegalArgumentException("Invalid version format");

}
if (semver.startsWith("v")) {
// prune any potential version tags starting with a 'v'
semver = semver.substring(1);
}

this.semver = semver;
this.isPreRelease = versionString.startsWith("prerelease-");
this.semver = matcher.group(1);
this.preReleaseTag = matcher.group(3);
}

@Override
public int compareTo(Version that) {
if (that == null) {
return 1;
}
String[] thisParts = this.get().split("\\.");
String[] thatParts = that.get().split("\\.");
String[] thisParts = this.semver.split("\\.");
String[] thatParts = that.semver.split("\\.");
int length = Math.max(thisParts.length, thatParts.length);
for (int i = 0; i < length; i++) {
int thisPart = i < thisParts.length ? Integer.parseInt(thisParts[i]) : 0;
Expand All @@ -50,6 +65,29 @@ public int compareTo(Version that) {
return 1;
}
}

// if base versions are equal, pre-releases are considered lower than releases
if (this.isPreRelease && !that.isPreRelease) {
return -1;
}
if (!this.isPreRelease && that.isPreRelease) {
return 1;
}

// optionally, compare pre-release tags lexicographically if both are pre-releases
if (this.isPreRelease) {
if (this.preReleaseTag == null && that.preReleaseTag != null) {
return -1;
}
if (this.preReleaseTag != null && that.preReleaseTag == null) {
return 1;
}
if (this.preReleaseTag != null) {
return this.preReleaseTag.compareTo(that.preReleaseTag);
}
}

// if both versions are equal, return 0
return 0;
}

Expand All @@ -58,22 +96,22 @@ public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (this.getClass() != that.getClass()) {
if (that == null || this.getClass() != that.getClass()) {
return false;
}
return this.compareTo((Version) that) == 0;
}

@Override
public int hashCode() {
return Objects.hashCode(semver);
return Objects.hash(semver, preReleaseTag, isPreRelease);
}

@Override
public String toString() {
return this.semver;
if (isPreRelease && preReleaseTag != null) {
return "prerelease-" + semver + "-" + preReleaseTag;
}
return semver;
}
}
Loading