-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
804ac10
commit 7388340
Showing
2 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# Experimental workflow to automate updating to a new Minecraft snapshot. | ||
name: Auto Snapshot Update | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
mc_version: | ||
description: "Minecraft version to update to" | ||
required: true | ||
yarn_mappings: | ||
description: "Yarn mappings version" | ||
required: true | ||
fabric_loader: | ||
description: "Fabric Loader version" | ||
required: true | ||
fapi_version: | ||
description: "Fabric API version" | ||
required: true | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
update: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
# Include all branches in case the new snapshot branch already exists. | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python 3.12 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.12" | ||
|
||
- name: Set up Java 21 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: "21" | ||
distribution: "microsoft" | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
|
||
- name: Setup Gradle | ||
uses: gradle/actions/setup-gradle@v4 | ||
with: | ||
build-scan-publish: true | ||
build-scan-terms-of-use-url: "https://gradle.com/help/legal-terms-of-use" | ||
build-scan-terms-of-use-agree: "yes" | ||
|
||
- name: Create and checkout new snapshot branch | ||
run: | | ||
BRANCH_NAME="${{ github.event.inputs.mc_version }}" | ||
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | ||
if [ "$CURRENT_BRANCH" = "$BRANCH_NAME" ]; then | ||
echo "Already on branch $BRANCH_NAME. Skipping branch creation." | ||
elif git show-ref --quiet refs/heads/$BRANCH_NAME; then | ||
echo "Branch $BRANCH_NAME already exists but is not currently checked out. Failing the workflow." | ||
exit 1 | ||
else | ||
git checkout -b $BRANCH_NAME | ||
echo "Created and checked out new branch: $BRANCH_NAME" | ||
fi | ||
shell: bash | ||
|
||
- name: Run migrateMappings task | ||
run: | | ||
./gradlew migrateMappings --mappings ${{ github.event.inputs.yarn_mappings }} | ||
shell: bash | ||
|
||
- name: Replace src/main/java with remapped files | ||
run: | | ||
rm -rf ./src/main/java | ||
mv ./remappedSrc ./src/main/java | ||
shell: bash | ||
|
||
- name: Update version constants | ||
run: | | ||
python scripts/update_version_constants.py "${{ github.event.inputs.mc_version }}" "${{ github.event.inputs.yarn_mappings }}" "${{ github.event.inputs.fabric_loader }}" "${{ github.event.inputs.fapi_version }}" | ||
shell: bash | ||
|
||
# To fix any style issues that the migration scripts might cause | ||
- name: Run spotlessApply task | ||
run: ./gradlew spotlessApply | ||
|
||
- name: Commit and push changes | ||
run: | | ||
git config --global user.name "Wurst-Bot" | ||
git config --global user.email "[email protected]" | ||
git add . | ||
git commit -m "[Wurst-Bot] Update to ${{ github.event.inputs.mc_version }}" | ||
git push --set-upstream origin ${{ github.event.inputs.mc_version }} | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import argparse | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("mc_version", help="Minecraft version") | ||
parser.add_argument("yarn_mappings", help="Yarn mappings version") | ||
parser.add_argument("fabric_loader", help="Fabric Loader version") | ||
parser.add_argument("fapi_version", help="Fabric API version") | ||
args = parser.parse_args() | ||
|
||
# Read gradle.properties | ||
print("Updating gradle.properties...") | ||
with open("gradle.properties", "r") as f: | ||
lines = f.readlines() | ||
|
||
# Define replacements | ||
replacements = { | ||
"minecraft_version": lambda v: args.mc_version, | ||
"yarn_mappings": lambda v: args.yarn_mappings, | ||
"loader_version": lambda v: args.fabric_loader, | ||
"fabric_version": lambda v: args.fapi_version, | ||
"mod_version": lambda v: v[: v.index("MC") + 2] + args.mc_version, | ||
} | ||
|
||
# Update lines | ||
for i, line in enumerate(lines): | ||
if line.startswith("#"): | ||
continue | ||
parts = line.split("=") | ||
if len(parts) != 2: | ||
continue | ||
key = parts[0] | ||
if key.strip() not in replacements: | ||
continue | ||
old_value = parts[1] | ||
new_value = replacements[key.strip()](old_value) | ||
print(f"{key}={old_value} -> {new_value}") | ||
lines[i] = f"{key}={new_value}\n" | ||
|
||
# Save modified gradle.properties | ||
with open("gradle.properties", "w") as f: | ||
f.writelines(lines) | ||
print("gradle.properties updated.") |