Skip to content

Commit 9cf2917

Browse files
committed
update version generation
1 parent a4615bd commit 9cf2917

File tree

4 files changed

+33
-27
lines changed

4 files changed

+33
-27
lines changed

.github/scripts/extract_version.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,35 +58,37 @@ jobs:
5858
if: ${{ runner.os != 'Windows' }}
5959
run: chmod +x ./gradlew
6060

61-
- name: extract version
62-
if: ${{ runner.os != 'Windows' }}
63-
id: getversion
64-
run: |
65-
echo "version=$(.github/scripts/extract_version.sh)" >> "$GITHUB_OUTPUT"
66-
6761
- name: gradle clean build
68-
env:
69-
VERSION_NAME: ${{ steps.getversion.outputs.version }}
7062
run: ./gradlew clean build
7163

7264
- name: extract changelog
7365
if: ${{ runner.os == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java
74-
id: getchangelog
75-
env:
76-
VERSION_NAME: ${{ steps.getversion.outputs.version }}
66+
id: changelog
7767
run: |
7868
echo "changelog=$(./gradlew -q printChangelog)" >> "$GITHUB_OUTPUT"
7969
70+
- name: extract version number
71+
if: ${{ runner.os == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java
72+
id: version
73+
run: |
74+
echo "version=$(./gradlew -q printVersion)" >> "$GITHUB_OUTPUT"
75+
76+
- name: extract version display name
77+
if: ${{ runner.os == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java
78+
id: versionDisplay
79+
run: |
80+
echo "versionDisplay=$(./gradlew -q printVersionDisplay)" >> "$GITHUB_OUTPUT"
81+
8082
# windows throws an error if the second parameter for
8183
# echo is not set, which it will never be, because it's
8284
# only set for Linux
8385
- name: show version
8486
if: ${{ runner.os == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java
85-
run: echo ${{ steps.getversion.outputs.version }}
87+
run: echo ${{ steps.version.outputs.version }}
8688

8789
- name: show changelog
8890
if: ${{ runner.os == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java
89-
run: echo "${{ steps.getchangelog.outputs.changelog }}"
91+
run: echo "${{ steps.changelog.outputs.changelog }}"
9092
continue-on-error: true
9193

9294
- name: capture build artifacts
@@ -107,5 +109,6 @@ jobs:
107109
uses: ncipollo/release-action@v1
108110
with:
109111
artifacts: "LICENSE,build/libs/*.jar"
110-
body: ${{ steps.getchangelog.outputs.changelog }}
111-
tag: ${{ steps.getversion.outputs.version }}
112+
body: ${{ steps.changelog.outputs.changelog }}
113+
tag: ${{ steps.version.outputs.version }}
114+
name: ${{ steps.versionDisplay.outputs.versionDisplay }}

build.gradle

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ plugins {
77
id "com.matthewprenger.cursegradle" version "1.+" // curseforge publishing
88
}
99

10-
var versionEnv = System.getenv("VERSION_NAME")
11-
version = versionEnv != null ? verisonEnv : project.mod_version
10+
version = project.mod_version
1211
group = project.maven_group
1312

13+
// Formats the mod version to include the Minecraft version and build number (if present)
14+
// example: 1.0.0+1.18.2-100
15+
String runNumber = System.getenv("GITHUB_RUN_NUMBER")
16+
String build = runNumber != null ? "build.$runNumber" : "local"
17+
version = "$mod_version-$build+mc$minecraft_version"
18+
1419
repositories {
1520
mavenCentral()
1621
maven {

gradle/publishing/publishing.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ tasks.register("printChangelog") {
2222
println(changelog_text)
2323
}
2424

25+
tasks.register("printVersionDisplay") {
26+
println(published_version_name)
27+
}
28+
29+
tasks.register("printVersion") {
30+
println(version)
31+
}
32+
2533
static String makeName(String version, String minecraftVersion, String displayName) {
2634
String projectVersion = "v" + version.split("-build")[0].replace("-", ".")
2735
String rawPatch = System.getenv("PATCH_NUMBER")

0 commit comments

Comments
 (0)