From 35ef2a62d0af69f2756cc59919d9834152f661e1 Mon Sep 17 00:00:00 2001 From: secret_online Date: Thu, 2 Jan 2025 09:08:31 +1300 Subject: [PATCH] Use tilde range in update workflow --- .github/actions/update-versions/action.yml | 2 ++ .github/actions/update-versions/index.js | 21 ++++++++++++++++--- .../workflows/update-minecraft-version.yml | 4 +++- package-lock.json | 8 +++---- package.json | 2 +- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/.github/actions/update-versions/action.yml b/.github/actions/update-versions/action.yml index 03064b4..9bf4e80 100644 --- a/.github/actions/update-versions/action.yml +++ b/.github/actions/update-versions/action.yml @@ -4,6 +4,8 @@ description: Get versions of the game for the build and test workflow inputs: minecraft-version: description: Minecraft version to update to. If not supplied, falls back to latest version. + max-minecraft-version: + description: Maximum Minecraft version if there are known incompatibilities with later minor versions. If not specified then it's assumed that any future minor version will be compatible. ignore-mod-dependencies: description: Ignore mod dependency versions diff --git a/.github/actions/update-versions/index.js b/.github/actions/update-versions/index.js index f9d145e..0922188 100644 --- a/.github/actions/update-versions/index.js +++ b/.github/actions/update-versions/index.js @@ -33,6 +33,18 @@ function getUpdateVersion() { return allVersions.latest.release; } +/** + * @returns {string | null} + */ +function getMaxUpdateVersion() { + const inputValue = getInput("max-minecraft-version"); + if (inputValue) { + return inputValue; + } + + return null; +} + const versionToUpdate = getUpdateVersion(); const updateVersionInfo = await getMinecraftVersion(versionToUpdate); @@ -58,7 +70,7 @@ async function getNewVersionRange() { throw new Error(`No versions matched range ${recommendsRange}`); } - const maxMatchingInfo = await getMinecraftVersion( + const minMatchingInfo = await getMinecraftVersion( minMatchingSemver.toString() ); @@ -66,7 +78,7 @@ async function getNewVersionRange() { const isSameMinor = updateSemver.minor === minMatchingSemver.minor; const isSameJava = updateVersionInfo.javaVersion.majorVersion === - maxMatchingInfo.javaVersion.majorVersion; + minMatchingInfo.javaVersion.majorVersion; // Note: If changing this so multiple minor versions are allowed to co-exist, // make sure to update the version range logic further down. @@ -81,11 +93,14 @@ async function getNewVersionRange() { return versionToUpdate; } + const maxUpdateVersion = getMaxUpdateVersion(); // Current rules mean that the minor version is always the same, so we can use a range here // Also we're assuming middle versions are compatible. This should always be the case, but // I can't wait to eat my words on that one. const simplified = trimAllZeroVersions( - `${minMatchingSemver.toString()} - ${versionToUpdate}` + maxUpdateVersion !== null + ? `${minMatchingSemver.toString()} - ${maxUpdateVersion}` + : `~${minMatchingSemver.toString()}` ); info( diff --git a/.github/workflows/update-minecraft-version.yml b/.github/workflows/update-minecraft-version.yml index 8207c32..af7297e 100644 --- a/.github/workflows/update-minecraft-version.yml +++ b/.github/workflows/update-minecraft-version.yml @@ -1,4 +1,5 @@ name: Update Minecraft Version +run-name: Update Minecraft Version (${{ inputs.minecraft-version || 'latest' }}) on: schedule: @@ -17,6 +18,7 @@ on: jobs: update-minecraft: + name: Update Minecraft Version runs-on: ubuntu-latest steps: @@ -43,7 +45,7 @@ jobs: - name: Update files if: steps.update-versions.outputs.has-updates == 'true' run: | - cat src/client/resources/fabric.mod.json | jq '.recommends.minecraft = "~${{ steps.update-versions.outputs.minecraft-version }}" | .depends.java = ">=${{ steps.update-versions.outputs.java-version }}" | .recommends.fabricloader = ">=${{ steps.update-versions.outputs.loader-version }}"' > fabric.mod.json + cat src/client/resources/fabric.mod.json | jq '.recommends.minecraft = "${{ steps.update-versions.outputs.minecraft-version-range }}" | .depends.java = ">=${{ steps.update-versions.outputs.java-version }}" | .recommends.fabricloader = ">=${{ steps.update-versions.outputs.loader-version }}"' > fabric.mod.json rm src/client/resources/fabric.mod.json mv fabric.mod.json src/client/resources/fabric.mod.json diff --git a/package-lock.json b/package-lock.json index a03208d..9f4887b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "semver": "^7.6.3" }, "devDependencies": { - "@types/node": "^22.10.1", + "@types/node": "^22.10.3", "@types/semver": "^7.5.8", "typescript": "^5.7.2" } @@ -63,9 +63,9 @@ } }, "node_modules/@types/node": { - "version": "22.10.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.1.tgz", - "integrity": "sha512-qKgsUwfHZV2WCWLAnVP1JqnpE6Im6h3Y0+fYgMTasNQ7V++CBX5OT1as0g0f+OyubbFqhf6XVNIsmN4IIhEgGQ==", + "version": "22.10.3", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.3.tgz", + "integrity": "sha512-DifAyw4BkrufCILvD3ucnuN8eydUfc/C1GlyrnI+LK6543w5/L3VeVgf05o3B4fqSXP1dKYLOZsKfutpxPzZrw==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 73541e1..f02d010 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "semver": "^7.6.3" }, "devDependencies": { - "@types/node": "^22.10.1", + "@types/node": "^22.10.3", "@types/semver": "^7.5.8", "typescript": "^5.7.2" }