Skip to content

Commit

Permalink
Merge pull request #17 from Erdragh/chore/autopublishing
Browse files Browse the repository at this point in the history
Fix versioning for autopublishing
  • Loading branch information
Erdragh authored Oct 11, 2023
2 parents 7802a29 + 9cf2917 commit 2a5365c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
10 changes: 0 additions & 10 deletions .github/scripts/extract_version.sh

This file was deleted.

33 changes: 18 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,37 @@ jobs:
if: ${{ runner.os != 'Windows' }}
run: chmod +x ./gradlew

- name: extract version
if: ${{ runner.os != 'Windows' }}
id: getversion
run: |
echo "version=$(.github/scripts/extract_version.sh)" >> "$GITHUB_OUTPUT"
- name: gradle clean build
env:
VERSION_NAME: ${{ steps.getversion.outputs.version }}
run: ./gradlew clean build

- name: extract changelog
if: ${{ runner.os == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java
id: getchangelog
env:
VERSION_NAME: ${{ steps.getversion.outputs.version }}
id: changelog
run: |
echo "changelog=$(./gradlew -q printChangelog)" >> "$GITHUB_OUTPUT"
- name: extract version number
if: ${{ runner.os == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java
id: version
run: |
echo "version=$(./gradlew -q printVersion)" >> "$GITHUB_OUTPUT"
- name: extract version display name
if: ${{ runner.os == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java
id: versionDisplay
run: |
echo "versionDisplay=$(./gradlew -q printVersionDisplay)" >> "$GITHUB_OUTPUT"
# windows throws an error if the second parameter for
# echo is not set, which it will never be, because it's
# only set for Linux
- name: show version
if: ${{ runner.os == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java
run: echo ${{ steps.getversion.outputs.version }}
run: echo ${{ steps.version.outputs.version }}

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

- name: capture build artifacts
Expand All @@ -107,5 +109,6 @@ jobs:
uses: ncipollo/release-action@v1
with:
artifacts: "LICENSE,build/libs/*.jar"
body: ${{ steps.getchangelog.outputs.changelog }}
tag: ${{ steps.getversion.outputs.version }}
body: ${{ steps.changelog.outputs.changelog }}
tag: ${{ steps.version.outputs.version }}
name: ${{ steps.versionDisplay.outputs.versionDisplay }}
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ plugins {
version = project.mod_version
group = project.maven_group

// Formats the mod version to include the Minecraft version and build number (if present)
// example: 1.0.0+1.18.2-100
String runNumber = System.getenv("GITHUB_RUN_NUMBER")
String build = runNumber != null ? "build.$runNumber" : "local"
version = "$mod_version-$build+mc$minecraft_version"

repositories {
mavenCentral()
maven {
Expand Down
14 changes: 8 additions & 6 deletions gradle/publishing/publishing.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ ext /*-ra properties*/ {

properties.forEach ((k, v) -> set(k, v))

versionEnv = System.getenv("VERSION_NAME")

if (versionEnv != null) {
version = versionEnv
}

version_valid = versionValidForPublishing(version)
published_version_name = version_valid ? makeName(version, minecraft_version, display_name) : "INVALID"
changelog_text = getChangelog(file(changelog_file))
Expand All @@ -28,6 +22,14 @@ tasks.register("printChangelog") {
println(changelog_text)
}

tasks.register("printVersionDisplay") {
println(published_version_name)
}

tasks.register("printVersion") {
println(version)
}

static String makeName(String version, String minecraftVersion, String displayName) {
String projectVersion = "v" + version.split("-build")[0].replace("-", ".")
String rawPatch = System.getenv("PATCH_NUMBER")
Expand Down

0 comments on commit 2a5365c

Please sign in to comment.