-
-
Notifications
You must be signed in to change notification settings - Fork 420
147 lines (125 loc) · 5.04 KB
/
auto_snapshot_update.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Experimental workflow to automate updating to a new Minecraft snapshot.
# Currently this is very similar to the semi-automatic scripts I already use,
# but moving them to GitHub Actions means I don't have to be around to start
# them. This should allow for further automation in the future.
# TODO:
# - Add more thorough automated testing where it runs the game, creates a test
# world and takes screenshots, similar to what Fabric API does in their
# GitHub Actions workflow.
# - Set up a server to trigger this workflow when a new snapshot is out and
# Fabric has updated to it. This might end up running twice per snapshot,
# because there is no way to know ahead of time if the previous Fabric API
# build still works or if we have to wait for a new build made specifically
# for the new snapshot.
# - Add a step to automatically release the new snapshot build if all tests
# have passed. This will only ever run on small snapshots that don't break
# anything, but should save a ton of time at the end of each snapshot cycle
# when Mojang is spamming tiny pre-releases every day.
# In case it isn't obvious, these todos are very ambitious and might not end
# up working as planned.
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
distinct_id:
description: "Automatically set by the return-dispatch action (leave blank if running manually)"
required: false
permissions:
# To push changes to the new snapshot branch.
contents: write
# To trigger the CI workflow.
actions: write
jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Echo distinct ID ${{ github.event.inputs.distinct_id }}
run: echo ${{ github.event.inputs.distinct_id }}
- 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
- name: Run migrateMappings task
run: |
./gradlew migrateMappings --mappings ${{ github.event.inputs.yarn_mappings }}
- name: Replace src/main/java with remapped files
run: |
rm -rf ./src/main/java
mv ./remappedSrc ./src/main/java
- 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 }}"
# 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 "contact.wurstimperium@gmail.com"
git add .
git commit -m "[Wurst-Bot] Update to ${{ github.event.inputs.mc_version }}"
git push --set-upstream origin ${{ github.event.inputs.mc_version }}
- name: Trigger CI on the new branch
id: ci_dispatch
uses: codex-/return-dispatch@v2
with:
token: ${{ github.token }}
owner: Wurst-Imperium
repo: Wurst7
ref: ${{ github.event.inputs.mc_version }}
workflow: gradle.yml
- name: Wait for CI to finish (run ${{ steps.ci_dispatch.outputs.run_id }})
uses: codex-/await-remote-run@v1
with:
token: ${{ github.token }}
owner: Wurst-Imperium
repo: Wurst7
run_id: ${{ steps.ci_dispatch.outputs.run_id }}
run_timeout_seconds: 600 # 10 minutes