Skip to content

Commit f75b52c

Browse files
authored
Fix "v1.18.1" Version-related issues (#10)
Revert "Fix tag format for publish workflow": - This reverts commit 28b26aa. - The preceding 'v' causes version detection to fail in addon mods. Will start using version tags without a preceding 'v' going forward. Fix DataFixers Version parsing: - Fixes #9 - "v1.18.1" erroneously parsed as 0.18.1 due to the preceding 'v'. This could potentially become a problem as Version could erroneously detect a pre-1.10.5 version, triggering DataFixers. - Pattern matching will now ignore a single 'v' before a numeric token. - Add JUnit test checking for desired behaviors with Version::parse - Also refactor GregTechVersion to parse RFG generated version tag instead of hard-coded values, as 1.18.1 was reporting itself as 1.18.0.
1 parent a8895de commit f75b52c

File tree

4 files changed

+71
-12
lines changed

4 files changed

+71
-12
lines changed

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: Publish
44
on:
55
push:
66
tags:
7-
- 'v[0-9]+.[0-9]+.[0-9]+' # any semver tag, e.g. 1.2.3
7+
- '[0-9]+.[0-9]+.[0-9]+' # any semver tag, e.g. 1.2.3
88

99
env:
1010
# link to the changelog with a format code for the version
@@ -63,4 +63,4 @@ jobs:
6363
caches
6464
jdks
6565
notifications
66-
wrapper
66+
wrapper

src/main/java/gregtech/GregTechVersion.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@
44

55
public final class GregTechVersion {
66

7-
public static final int MAJOR = 1;
8-
//This number is incremented every major feature update
9-
public static final int MINOR = 18;
10-
//This number is incremented every time the feature is added, or bug is fixed. resets every major version change
11-
public static final int REVISION = 0;
12-
//This number is incremented every build, and never reset. Should always be 0 in the repo code.
13-
public static final int BUILD = 0;
14-
15-
public static final Version VERSION = new Version(MAJOR, MINOR, REVISION, BUILD);
7+
public static final Version VERSION = Version.parse(GTInternalTags.VERSION);
168

179
private GregTechVersion() {
1810
}

src/main/java/gregtech/api/util/Version.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public Version(int... nums) {
2222
}
2323

2424
public static Version parse(String vStr) {
25-
final Pattern p = Pattern.compile("(\\d+).*");
25+
final Pattern p = Pattern.compile("v?(\\d+).*");
2626
return new Version(Arrays.stream(vStr.split(Pattern.quote(".")))
2727
.map(s -> {
2828
Matcher m = p.matcher(s);
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package gregtech.api.util;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.*;
6+
7+
public class VersionTest {
8+
9+
/**
10+
* Workaround for Nomifactory 1.2.2.x worlds with Bansoukou-patched version string
11+
* so that they are properly remapped on world load
12+
*/
13+
@Test
14+
public void parse_omits_text_after_numbers() {
15+
String version = "1.8.4.419-exa3";
16+
Version expected = new Version(1, 8, 4, 419);
17+
assertEquals("Failed to omit non-numeric trailing text", expected, Version.parse(version));
18+
}
19+
20+
/**
21+
* As a contingency against crashing, map non-numeric tokens to zeroes
22+
*/
23+
@Test public void parse_maps_text_to_zero() {
24+
String version = "lorem.ipsum.foo.bar";
25+
Version expected = new Version(0, 0, 0, 0);
26+
assertEquals("Failed to map non-numeric text to zero", expected, Version.parse(version));
27+
}
28+
29+
/**
30+
* If there's a preceding "v" which started getting added by the build script
31+
* when I switched to using git tags for version numbering, we need to ignore it
32+
* and consider just the number.
33+
*/
34+
@Test
35+
public void parse_ignores_v_before_number() {
36+
// Bug fix confirmation - formerly detected '0.18.1'
37+
String version = "v1.18.1";
38+
Version expected = new Version(1, 18, 1);
39+
assertEquals("Failed to detect version string with single preceding 'v'", expected, Version.parse(version));
40+
}
41+
42+
/**
43+
* Make sure that dev builds properly parse the version string too.
44+
*/
45+
@Test
46+
public void parse_handles_RFG_dirty_tags() {
47+
// RFG-generated version strings look like this when you have uncommitted changes
48+
String version = "v1.18.1.dirty";
49+
Version expected = new Version(1, 18, 1);
50+
assertEquals("Failed to parse simple dirty tag", expected, Version.parse(version));
51+
52+
// RFG-generated version strings look like this when you have local commits plus uncommitted changes
53+
version = "v1.18.1-2-abcdef12.dirty";
54+
assertEquals("Failed to parse complex dirty tag", expected, Version.parse(version));
55+
}
56+
57+
/**
58+
* Ensures that 'v' handling doesn't break other rules.
59+
*/
60+
@Test
61+
public void parse_handles_other_v_conditions() {
62+
// two 'v' counts as text, v followed by non-numbers is still text, single v is not ignored between digits
63+
String version = "vv1.vfoo.1v8";
64+
Version expected = new Version(0, 0, 1);
65+
assertEquals("Parsing failed to handle normal logic with 'v' related conditions", expected, Version.parse(version));
66+
}
67+
}

0 commit comments

Comments
 (0)