Skip to content

Commit

Permalink
Use tilde range in update workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
SecretOnline committed Jan 1, 2025
1 parent fab1727 commit 35ef2a6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .github/actions/update-versions/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 18 additions & 3 deletions .github/actions/update-versions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -58,15 +70,15 @@ async function getNewVersionRange() {
throw new Error(`No versions matched range ${recommendsRange}`);
}

const maxMatchingInfo = await getMinecraftVersion(
const minMatchingInfo = await getMinecraftVersion(
minMatchingSemver.toString()
);

const isSameMajor = updateSemver.major === minMatchingSemver.major;
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.
Expand All @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/update-minecraft-version.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Update Minecraft Version
run-name: Update Minecraft Version (${{ inputs.minecraft-version || 'latest' }})

on:
schedule:
Expand All @@ -17,6 +18,7 @@ on:

jobs:
update-minecraft:
name: Update Minecraft Version
runs-on: ubuntu-latest

steps:
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down

0 comments on commit 35ef2a6

Please sign in to comment.