-
-
Notifications
You must be signed in to change notification settings - Fork 8
294 lines (279 loc) · 13.1 KB
/
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# This is a basic workflow that is manually triggered
name: Update
run-name: Update to ${{ inputs.new_version }} from ${{ inputs.old_version }}
permissions:
contents: write
# Controls when the action will run. Workflow runs when manually triggered using the UI
# or API.
on:
workflow_dispatch:
inputs:
old_version:
description: 'Old version'
required: true
patch_src:
description: 'Patches version'
required: false
new_branch:
description: 'New branch'
required: false
new_version:
description: 'New version'
required: true
fix-mapping-error:
description: 'Fix known error(s) in mapping file'
required: false
default: true
type: boolean
copy-extras:
description: 'Copy extras'
required: false
default: true
type: boolean
publish:
description: 'Publish'
required: false
default: false
type: boolean
jobs:
update:
name: Update
runs-on: ubuntu-latest
outputs:
old_version_type: ${{ fromJson(steps.split_version.outputs.result).old_version_type }}
old_version_name: ${{ fromJson(steps.split_version.outputs.result).old_version_name }}
new_version_type: ${{ fromJson(steps.split_version.outputs.result).new_version_type }}
new_version_name: ${{ fromJson(steps.split_version.outputs.result).new_version_name }}
steps:
- name: "Log arguments"
run: |
echo "Old version: ${{ inputs.old_version }}"
echo "Patches version: ${{ inputs.patch_src }}"
echo "New branch: ${{ inputs.new_branch }}"
echo "New version: ${{ inputs.new_version }}"
- uses: actions/github-script@v7
name: Check arguments
env:
OLD_VERSION: ${{ inputs.old_version }}
PATCHES_VERSION: ${{ inputs.patch_src }}
NEW_BRANCH: ${{ inputs.new_branch }}
NEW_VERSION: ${{ inputs.new_version }}
with:
script: |
const oldVersion = process.env.OLD_VERSION;
const patchesVersion = process.env.PATCHES_VERSION;
const newBranch = process.env.NEW_BRANCH;
const newVersion = process.env.NEW_VERSION;
const versionRegex = /^(release|(snapshot|pre)\/[^/]+)\/[^/]+$/;
var failed = 0
if (!versionRegex.test(oldVersion)) {
core.error("Old version needs to be set to a version that is on the old branch and needs to be in the format of either `release/<version>`, `pre/<target>/<version>`, or `snapshot/<target>/<version>`")
failed++;
}
if (patchesVersion == oldVersion) {
core.error("Patches version inputted as the same as the old version only the oldVersion is needed")
failed++;
}
if (patchesVersion != "" && !versionRegex.test(patchesVersion)) {
core.error("Patches version either needs to be kept empty or needs to be set to a version that is on the old branch and needs to be in the format of either `release/<version>`, `pre/<target>/<version>`, or `snapshot/<target>/<version>`")
failed++;
}
if (!versionRegex.test(newVersion)) {
core.error("New version needs to be a version that doesn't exist on the new branch and needs to be in the format of either `release/<version>`, `pre/<target>/<version>`, or `snapshot/<target>/<version>`")
failed++;
}
if (failed > 0) {
core.setFailed(failed + " errors detected in arguments. Check logs for more details")
}
- name: Install fast-xml-parser
run: sudo npm install -g fast-xml-parser
- name: Get library versions
id: lib-versions
run: |
# $1 is name
# $2 is maven-metadata.xml url
get_version() {
echo "$1=$(wget -O - $2 | fxparser -c | jq .metadata.versioning.latest -r)" >> $GITHUB_OUTPUT
}
get_version srgutils https://maven.neoforged.net/releases/net/neoforged/srgutils/maven-metadata.xml
get_version forgeautorenamingtool https://maven.neoforged.net/releases/net/neoforged/AutoRenamingTool/maven-metadata.xml
get_version forgeflower https://maven.neoforged.net/releases/org/vineflower/vineflower/maven-metadata.xml
get_version installertools https://maven.neoforged.net/releases/net/minecraftforge/installertools/maven-metadata.xml
get_version mergetool https://maven.neoforged.net/releases/net/neoforged/mergetool/maven-metadata.xml
get_version jetbrains_annotations https://repo1.maven.org/maven2/org/jetbrains/annotations/maven-metadata.xml
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/github-script@v7
id: split_version
env:
OLD_VERSION: ${{ inputs.old_version }}
NEW_VERSION: ${{ inputs.new_version }}
PATCH_SRC_VERSION: ${{ inputs.patch_src }}
with:
script: |
const oldVersion = process.env.OLD_VERSION.split("/");
const newVersion = process.env.NEW_VERSION.split("/");
var returnValue = {old_version_type: oldVersion[0], old_version_name: oldVersion[oldVersion.length - 1], new_version_type: newVersion[0], new_version_name: newVersion[newVersion.length - 1]}
if (process.env.PATCH_SRC_VERSION) {
var pathSrcVersion = process.env.PATCH_SRC_VERSION.split("/");
returnValue.patch_src_version_name = pathSrcVersion[pathSrcVersion.length - 1]
}
return returnValue;
- name: Set up JDK ${{ vars.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
java-version: '${{ vars.JAVA_VERSION }}'
distribution: 'temurin'
- id: get_versions
run: |
mkdir -p ~/.minecraft/versions/
wget https://piston-meta.mojang.com/mc/game/version_manifest_v2.json -O ~/.minecraft/version_manifest_v2.json
- uses: actions/github-script@v7
env:
OLD_VERSION: ${{ fromJson(steps.split_version.outputs.result).old_version_name }}
NEW_VERSION: ${{ fromJson(steps.split_version.outputs.result).new_version_name }}
PATCH_SRC_VERSION: ${{ fromJson(steps.split_version.outputs.result).patch_src_version_name }}
with:
script: |
const os = require('os')
const fs = require('fs')
const versions = JSON.parse(fs.readFileSync(os.homedir() + '/.minecraft/version_manifest_v2.json', 'utf8')).versions
for (var i = 0; i < versions.length; i++) {
var version = versions[i]
if (version.id == process.env.OLD_VERSION || version.id == process.env.NEW_VERSION || version.id == process.env.PATCH_SRC_VERSION) {
var file = os.homedir() + '/.minecraft/versions/' + version.id + '/' + version.id
io.mkdirP(os.homedir() + '/.minecraft/versions/' + version.id + '/')
await exec.exec('wget ' + version.url + ' -O ' + file + '.json')
var versionJson = JSON.parse(fs.readFileSync(file + '.json', 'utf8'))
await exec.exec('wget ' + versionJson.downloads.client.url + ' -O ' + file + '.jar')
}
}
- name: Update SrgUtils
if: ${{ vars.SRGUTILS_UPDATE == 'true' }}
run: |
sed -i -E "s/SRGUTILS_VERSION = '[0-9]+\.[0-9]+\.[0-9]+'/SRGUTILS_VERSION = '$SRGUTILS_VERSION'/g" build.gradle
sed -i -E "s/net.neoforged:srgutils:[0-9]+\.[0-9]+\.[0-9]+/net.neoforged:srgutils:$SRGUTILS_VERSION/g" buildSrc/build.gradle
env:
SRGUTILS_VERSION: ${{ steps.lib-versions.outputs.srgutils }}
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- if: ${{ inputs.patch_src && inputs.patch_src != inputs.new_version }}
env:
PATCH_SRC: ${{ inputs.patch_src }}
NEW_VERSION: ${{ inputs.new_version }}
run: ./gradlew update -Pold_version=$PATCH_SRC -Pnew_version=$NEW_VERSION
- if: ${{ inputs.patch_src }}
run: cp versions/${{ inputs.new_version }}/joined.tsrg ../old_joined.tsrg
- name: Update task
env:
OLD_VERSION: ${{ inputs.old_version }}
NEW_VERSION: ${{ inputs.new_version }}
run: ./gradlew update -Pold_version=$OLD_VERSION -Pnew_version=$NEW_VERSION
- name: Write summary for update
run: |
cat versions/${{ inputs.new_version }}/statistics.md >> $GITHUB_STEP_SUMMARY
rm -f versions/${{ inputs.new_version }}/statistics.md
- name: Upload metadata
uses: actions/upload-artifact@v4
with:
name: mapping-metadata
path: build/update/data/**/joined_a_meta.json
- if: ${{ inputs.patch_src && inputs.copy-extras }}
run: cp versions/${{ inputs.new_version }}/joined.tsrg ../new_joined.tsrg
- if: ${{ inputs.patch_src != inputs.new_version && inputs.copy-extras }}
run: |
rm -rf versions/${{ inputs.new_version}}/patches
cp -r versions/${{ inputs.patch_src || inputs.old_version }}/patches versions/${{ inputs.new_version}}/patches
- if: ${{ inputs.patch_src && inputs.copy-extras }}
run: |
cd ..
wget https://github.com/coehlrich/remap-patches/releases/download/1.0.6/remap-patches-all.jar
java -jar remap-patches-all.jar old_joined.tsrg new_joined.tsrg MCPConfig/versions/${{ inputs.new_version }}/patches
cd MCPConfig
- run: git add .
- name: Store other updated files
if: ${{ inputs.new_branch && inputs.copy-extras }}
run: |
mkdir ../tmp
for ITEM in buildSrc gradle templates .gitattributes .gitignore build.gradle gradlew gradlew.bat settings.gradle update.gradle
do
echo "Copying $ITEM"
cp -rv ./$ITEM ../tmp/$ITEM
done
- if: ${{ inputs.new_branch }}
run: |
git stash
git checkout ${{ inputs.new_branch }} || git checkout -B ${{ inputs.new_branch }} remotes/origin/main
git push -u origin ${{ inputs.new_branch }}
- if: ${{ inputs.new_branch && inputs.copy-extras }}
run: rm -rf versions/${{ inputs.new_version }}
- if: ${{ inputs.new_branch && !inputs.copy-extras }}
run: |
rm -f versions/${{ inputs.new_version }}/joined.tsrg
rm -f versions/${{ inputs.new_version }}/config.json
rm -rf versions/${{ inputs.new_version }}/inject
- if: ${{ inputs.new_branch }}
run: |
git add .
git stash apply
- name: Restore other updated files
if: ${{ inputs.new_branch && inputs.copy-extras }}
run: |
cp -rvT ../tmp .
git add .
- run: |
git config --global user.name github-actions
git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com
git commit -m "Start ${{ inputs.new_version }}" && git push || true
- name: Update vineflower
if: ${{ vars.FORGEFLOWER_UPDATE == 'true' }}
run: sed -i -E "s/org.vineflower:vineflower:[0-9]+(\.[0-9]+)*/org.vineflower:vineflower:$VINEFLOWER_VERSION/g" $CONFIG
env:
VINEFLOWER_VERSION: ${{ steps.lib-versions.outputs.forgeflower }}
CONFIG: versions/${{ inputs.new_version }}/config.json
- name: Update AutoRenamingTool
if: ${{ vars.FORGEAUTORENAMINGTOOL_UPDATE == 'true' }}
run: sed -i -E "s/net.neoforged:AutoRenamingTool:[0-9]+(\.[0-9]+)*/net.neoforged:AutoRenamingTool:$AUTORENAMINGTOOL_VERSION/g" $CONFIG
env:
AUTORENAMINGTOOL_VERSION: ${{ steps.lib-versions.outputs.forgeautorenamingtool }}
CONFIG: versions/${{ inputs.new_version }}/config.json
- name: Update installertools
if: ${{ vars.INSTALLERTOOLS_UPDATE == 'true' }}
run: sed -i -E "s/net.minecraftforge:installertools:[0-9]+(\.[0-9]+)*/net.minecraftforge:installertools:$INSTALLERTOOLS_VERSION/g" $CONFIG
env:
INSTALLERTOOLS_VERSION: ${{ steps.lib-versions.outputs.installertools }}
CONFIG: versions/${{ inputs.new_version }}/config.json
- name: Update Jetbrains Annotations
if: ${{ vars.JETBRAINS_ANNOTATIONS_UPDATE == 'true' }}
run: sed -i -E "s/org.jetbrains:annotations:[0-9]+(\.[0-9]+)*/org.jetbrains:annotations:$JETBRAINS_ANNOTATIONS_VERSION/g" $CONFIG
env:
JETBRAINS_ANNOTATIONS_VERSION: ${{ steps.lib-versions.outputs.jetbrains_annotations }}
CONFIG: versions/${{ inputs.new_version }}/config.json
- name: Update Mergetool
if: ${{ vars.MERGETOOL_UPDATE == 'true' }}
run: sed -i -E "s/net.neoforged:mergetool:[0-9]+(\.[0-9]+)*/net.neoforged:mergetool:$MERGETOOLS_VERSION/g" $CONFIG
env:
MERGETOOLS_VERSION: ${{ steps.lib-versions.outputs.mergetool }}
CONFIG: versions/${{ inputs.new_version }}/config.json
- name: Push library changes
run: |
git add .
git commit -m "Update libraries" && git push || true
get-diff:
needs: update
name: Get diff
uses: ./.github/workflows/get-diff.yml
with:
old_version: ${{ inputs.old_version }}
new_branch: ${{ inputs.new_branch }}
new_version: ${{ inputs.new_version }}
check:
needs: update
uses: ./.github/workflows/check.yml
with:
branch: ${{ inputs.new_branch || '' }}
version: ${{ inputs.new_version }}
push_changed: true
publish: ${{ inputs.publish }}
secrets: inherit