|
| 1 | +# Experimental workflow to automate updating to a new Minecraft snapshot. |
| 2 | + |
| 3 | +# Currently this is very similar to the semi-automatic scripts I already use, |
| 4 | +# but moving them to GitHub Actions means I don't have to be around to start |
| 5 | +# them. This should allow for further automation in the future. |
| 6 | + |
| 7 | +# TODO: |
| 8 | +# - Add more thorough automated testing where it runs the game, creates a test |
| 9 | +# world and takes screenshots, similar to what Fabric API does in their |
| 10 | +# GitHub Actions workflow. |
| 11 | +# - Set up a server to trigger this workflow when a new snapshot is out and |
| 12 | +# Fabric has updated to it. This might end up running twice per snapshot, |
| 13 | +# because there is no way to know ahead of time if the previous Fabric API |
| 14 | +# build still works or if we have to wait for a new build made specifically |
| 15 | +# for the new snapshot. |
| 16 | +# - Add a step to automatically release the new snapshot build if all tests |
| 17 | +# have passed. This will only ever run on small snapshots that don't break |
| 18 | +# anything, but should save a ton of time at the end of each snapshot cycle |
| 19 | +# when Mojang is spamming tiny pre-releases every day. |
| 20 | + |
| 21 | +# In case it isn't obvious, these todos are very ambitious and might not end |
| 22 | +# up working as planned. |
| 23 | + |
| 24 | +name: Auto Snapshot Update |
| 25 | + |
| 26 | +on: |
| 27 | + workflow_dispatch: |
| 28 | + inputs: |
| 29 | + mc_version: |
| 30 | + description: "Minecraft version to update to" |
| 31 | + required: true |
| 32 | + yarn_mappings: |
| 33 | + description: "Yarn mappings version" |
| 34 | + required: true |
| 35 | + fabric_loader: |
| 36 | + description: "Fabric Loader version" |
| 37 | + required: true |
| 38 | + fapi_version: |
| 39 | + description: "Fabric API version" |
| 40 | + required: true |
| 41 | + distinct_id: |
| 42 | + description: "Automatically set by the return-dispatch action (leave blank if running manually)" |
| 43 | + required: false |
| 44 | + |
| 45 | +permissions: |
| 46 | + # To push changes to the new snapshot branch. |
| 47 | + contents: write |
| 48 | + # To trigger the CI workflow. |
| 49 | + actions: write |
| 50 | + |
| 51 | +jobs: |
| 52 | + update: |
| 53 | + runs-on: ubuntu-latest |
| 54 | + steps: |
| 55 | + |
| 56 | + - name: Echo distinct ID ${{ github.event.inputs.distinct_id }} |
| 57 | + run: echo ${{ github.event.inputs.distinct_id }} |
| 58 | + |
| 59 | + - name: Checkout repository |
| 60 | + uses: actions/checkout@v4 |
| 61 | + with: |
| 62 | + # Include all branches in case the new snapshot branch already exists. |
| 63 | + fetch-depth: 0 |
| 64 | + |
| 65 | + - name: Set up Python 3.12 |
| 66 | + uses: actions/setup-python@v5 |
| 67 | + with: |
| 68 | + python-version: "3.12" |
| 69 | + |
| 70 | + - name: Set up Java 21 |
| 71 | + uses: actions/setup-java@v4 |
| 72 | + with: |
| 73 | + java-version: "21" |
| 74 | + distribution: "microsoft" |
| 75 | + |
| 76 | + - name: Grant execute permission for gradlew |
| 77 | + run: chmod +x gradlew |
| 78 | + |
| 79 | + - name: Setup Gradle |
| 80 | + uses: gradle/actions/setup-gradle@v4 |
| 81 | + with: |
| 82 | + build-scan-publish: true |
| 83 | + build-scan-terms-of-use-url: "https://gradle.com/help/legal-terms-of-use" |
| 84 | + build-scan-terms-of-use-agree: "yes" |
| 85 | + |
| 86 | + - name: Create and checkout new snapshot branch |
| 87 | + run: | |
| 88 | + BRANCH_NAME="${{ github.event.inputs.mc_version }}" |
| 89 | + CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) |
| 90 | + |
| 91 | + if [ "$CURRENT_BRANCH" = "$BRANCH_NAME" ]; then |
| 92 | + echo "Already on branch $BRANCH_NAME. Skipping branch creation." |
| 93 | + elif git show-ref --quiet refs/heads/$BRANCH_NAME; then |
| 94 | + echo "Branch $BRANCH_NAME already exists but is not currently checked out. Failing the workflow." |
| 95 | + exit 1 |
| 96 | + else |
| 97 | + git checkout -b $BRANCH_NAME |
| 98 | + echo "Created and checked out new branch: $BRANCH_NAME" |
| 99 | + fi |
| 100 | +
|
| 101 | + - name: Run migrateMappings task |
| 102 | + run: | |
| 103 | + ./gradlew migrateMappings --mappings ${{ github.event.inputs.yarn_mappings }} |
| 104 | +
|
| 105 | + - name: Replace src/main/java with remapped files |
| 106 | + run: | |
| 107 | + rm -rf ./src/main/java |
| 108 | + mv ./remappedSrc ./src/main/java |
| 109 | +
|
| 110 | + - name: Update version constants |
| 111 | + run: | |
| 112 | + python scripts/update_version_constants.py \ |
| 113 | + "${{ github.event.inputs.mc_version }}" \ |
| 114 | + "${{ github.event.inputs.yarn_mappings }}" \ |
| 115 | + "${{ github.event.inputs.fabric_loader }}" \ |
| 116 | + "${{ github.event.inputs.fapi_version }}" |
| 117 | +
|
| 118 | + # To fix any style issues that the migration scripts might cause |
| 119 | + - name: Run spotlessApply task |
| 120 | + run: ./gradlew spotlessApply |
| 121 | + |
| 122 | + - name: Commit and push changes |
| 123 | + run: | |
| 124 | + git config --global user.name "Wurst-Bot" |
| 125 | + git config --global user.email "[email protected]" |
| 126 | + git add . |
| 127 | + git commit -m "[Wurst-Bot] Update to ${{ github.event.inputs.mc_version }}" |
| 128 | + git push --set-upstream origin ${{ github.event.inputs.mc_version }} |
| 129 | +
|
| 130 | + - name: Trigger CI on the new branch |
| 131 | + id: ci_dispatch |
| 132 | + uses: codex-/return-dispatch@v2 |
| 133 | + with: |
| 134 | + token: ${{ github.token }} |
| 135 | + owner: Wurst-Imperium |
| 136 | + repo: Wurst7 |
| 137 | + ref: ${{ github.event.inputs.mc_version }} |
| 138 | + workflow: gradle.yml |
| 139 | + |
| 140 | + - name: Wait for CI to finish (run ${{ steps.ci_dispatch.outputs.run_id }}) |
| 141 | + uses: codex-/await-remote-run@v1 |
| 142 | + with: |
| 143 | + token: ${{ github.token }} |
| 144 | + owner: Wurst-Imperium |
| 145 | + repo: Wurst7 |
| 146 | + run_id: ${{ steps.ci_dispatch.outputs.run_id }} |
| 147 | + run_timeout_seconds: 600 # 10 minutes |
0 commit comments