This repository has been archived by the owner on Nov 29, 2024. It is now read-only.
forked from Vivecraft/VivecraftMod
-
Notifications
You must be signed in to change notification settings - Fork 11
367 lines (317 loc) · 15.9 KB
/
publish-on-release.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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
name: curseforge-modrinth-publish
run-name: Posting jars on Curseforge and Modrinth
on:
release:
types: [ published ]
jobs:
publish:
runs-on: ubuntu-22.04
steps:
- name: fetching asset paths
id: assets
shell: bash
run: |
echo Attachments
fileNames=(${{ github.event.release.assets[0].name }} ${{ github.event.release.assets[1].name }} ${{ github.event.release.assets[2].name }})
filePaths=(${{ github.event.release.assets[0].browser_download_url }} ${{ github.event.release.assets[1].browser_download_url }} ${{ github.event.release.assets[2].browser_download_url }})
for i in 0 1 2 3
do
echo "${fileNames[i]}"
echo "${filePaths[i]}"
if [ -n "${filePaths[i]}" ]; then
curl -L -o "./${fileNames[i]}" "${filePaths[i]}"
fi
if [[ "${fileNames[i]}" == *"fabric"* ]]; then
echo "FABRIC_FILE_NAME=${fileNames[i]}" >> $GITHUB_OUTPUT
echo "FABRIC_FILE_PATH=./${fileNames[i]}" >> $GITHUB_OUTPUT
elif [[ "${fileNames[i]}" == *"neoforge"* ]]; then
echo "NEOFORGE_FILE_NAME=${fileNames[i]}" >> $GITHUB_OUTPUT
echo "NEOFORGE_FILE_PATH=./${fileNames[i]}" >> $GITHUB_OUTPUT
elif [[ "${fileNames[i]}" == *"forge"* ]]; then
echo "FORGE_FILE_NAME=${fileNames[i]}" >> $GITHUB_OUTPUT
echo "FORGE_FILE_PATH=./${fileNames[i]}" >> $GITHUB_OUTPUT
elif [[ "${fileNames[i]}" == *"quilt"* ]]; then
echo "QUILT_FILE_NAME=${fileNames[i]}" >> $GITHUB_OUTPUT
echo "QUILT_FILE_PATH=./${fileNames[i]}" >> $GITHUB_OUTPUT
fi
done
ls -l
- run: echo "fabric is ${{ steps.assets.outputs.FABRIC_FILE_NAME }}"
- run: echo "neoforge is ${{ steps.assets.outputs.NEOFORGE_FILE_NAME }}"
- run: echo "forge is ${{ steps.assets.outputs.FORGE_FILE_NAME }}"
- run: echo "quilt is ${{ steps.assets.outputs.QUILT_FILE_NAME }}"
- name: getting version info from files
id: version
shell: bash
run: |
parse_fabric () {
unzip -o -j "$1" "$2" -d ./fabric
deps=false
bracket=false
parsedVersion=""
depReg='\s+"depends"'
minecraftVersionReg='\s*?"minecraft":\s*?(.+?)*'
wordReg="(.*?),*"
bracketReg="(.*])"
while read -r; do
if [[ $REPLY =~ $depReg ]]; then
deps=true
elif [[ $REPLY =~ $minecraftVersionReg && $deps == "true" ]]; then
if [[ ${BASH_REMATCH[1]} =~ $wordReg ]]; then
parsedVersion=${BASH_REMATCH[1]}
if [[ ${BASH_REMATCH[1]} == "[" ]]; then
bracket=true
fi
fi
elif [[ $bracket == "true" && $REPLY != *"]"* ]]; then
parsedVersion=${parsedVersion}$REPLY
elif [[ $bracket == "true" && $REPLY =~ $bracketReg ]]; then
parsedVersion=${parsedVersion}${BASH_REMATCH[1]}
bracket=false
fi
done < ./fabric/$2
}
parse_forge () {
unzip -o -j "$1" "META-INF/mods.toml" -d ./forge
minecraftDep=false
minecraftIdReg='modId\s+=\s+"minecraft"'
versionRangeReg='versionRange\s+=\s+"(.+?)"'
while read -r; do
if [[ $REPLY =~ $minecraftIdReg ]]; then
minecraftDep=true
echo "$REPLY"
elif [[ $REPLY =~ $versionRangeReg && $minecraftDep == "true" ]]; then
parsedVersion="${BASH_REMATCH[1]}"
echo "${BASH_REMATCH[0]}"
echo "${BASH_REMATCH[1]}"
fi
done < ./forge/mods.toml
}
file=""
if [ -n "${{ steps.assets.outputs.FABRIC_FILE_NAME }}" ]; then
file="${{ steps.assets.outputs.FABRIC_FILE_NAME }}"
elif [ -n "${{ steps.assets.outputs.FORGE_FILE_NAME }}" ]; then
file="${{ steps.assets.outputs.FORGE_FILE_NAME }}"
elif [ -n "${{ steps.assets.outputs.NEOFORGE_FILE_NAME }}" ]; then
file="${{ steps.assets.outputs.NEOFORGE_FILE_NAME }}"
else
file="${{ steps.assets.outputs.QUILT_FILE_NAME }}"
fi
echo "$file"
# save the current IFS value
OLDIFS=$IFS
# set the IFS to the delimiter ("-")
IFS="-"
# split the string into an array, limiting it to a maximum of 3 fields
array=($file)
# restore the IFS value
IFS=$OLDIFS
# alphas or beats should be included in the version
if [ ${array[3]:0:1} = "a" ] || [ ${array[3]:0:1} = "b" ]; then
array[2]=${array[2]}-${array[3]}
fi
release_type="release"
if [ ${array[3]:0:1} = "a" ]; then
release_type="alpha"
elif [ ${array[3]:0:1} = "b" ]; then
release_type="beta"
fi
echo "release type: ${release_type}"
echo "RELEASE_TYPE=${release_type}" >> $GITHUB_OUTPUT
mc_version=${array[1]}
# mod loaders
loaders_fabric=fabric
# check if there is a quilt specific jar
if [ -z "${{ steps.assets.outputs.QUILT_FILE_NAME }}" ]; then
loaders_fabric="${loaders_fabric} quilt"
else
loaders_quilt="quilt"
fi
loaders_forge="forge"
loaders_neoforge="neoforge"
if [ -n "${{ steps.assets.outputs.FABRIC_FILE_NAME }}" ]; then
parse_fabric ${{ steps.assets.outputs.FABRIC_FILE_NAME }} "fabric.mod.json"
echo "FABRIC_MC_VERSIONS="${parsedVersion}"" >> $GITHUB_OUTPUT
fi
if [ -n "${{ steps.assets.outputs.FORGE_FILE_NAME }}" ]; then
parse_forge ${{ steps.assets.outputs.FORGE_FILE_NAME }}
echo "FORGE_MC_VERSIONS="${parsedVersion}"" >> $GITHUB_OUTPUT
fi
if [ -n "${{ steps.assets.outputs.NEOFORGE_FILE_NAME }}" ]; then
parse_forge ${{ steps.assets.outputs.NEOFORGE_FILE_NAME }}
echo "NEOFORGE_MC_VERSIONS="${parsedVersion}"" >> $GITHUB_OUTPUT
fi
if [ -n "${{ steps.assets.outputs.QUILT_FILE_NAME }}" ]; then
parse_fabric ${{ steps.assets.outputs.QUILT_FILE_NAME }} "quilt.mod.json"
echo "QUILT_MC_VERSIONS="${parsedVersion}"" >> $GITHUB_OUTPUT
fi
echo "loaders fabric: ${loaders_fabric}"
echo "LOADERS_FABRIC=${loaders_fabric}" >> $GITHUB_OUTPUT
echo "loaders forge: ${loaders_forge}"
echo "LOADERS_FORGE=${loaders_forge}" >> $GITHUB_OUTPUT
echo "loaders neoforge: ${loaders_neoforge}"
echo "LOADERS_NEOFORGE=${loaders_neoforge}" >> $GITHUB_OUTPUT
echo "loaders quilt: ${loaders_quilt}"
echo "LOADERS_QUILT=${loaders_quilt}" >> $GITHUB_OUTPUT
mod_name="${array[0]^} $mc_version-${array[2]}"
echo "file name fabric: '${mod_name}-fabric'"
echo "VERSION_NAME_FABRIC=${mod_name}-fabric" >> $GITHUB_OUTPUT
echo "file name forge: '${mod_name}-forge'"
echo "VERSION_NAME_FORGE=${mod_name}-forge" >> $GITHUB_OUTPUT
echo "file name neoforge: '${mod_name}-neoforge'"
echo "VERSION_NAME_NEOFORGE=${mod_name}-neoforge" >> $GITHUB_OUTPUT
echo "file name quilt: '${mod_name}-quilt'"
echo "VERSION_NAME_QUILT=${mod_name}-quilt" >> $GITHUB_OUTPUT
# modrinth mod versions
base_version="$mc_version-${array[2]}"
echo "MOD_VERSION_FABRIC=${base_version}-fabric" >> $GITHUB_OUTPUT
echo "MOD_VERSION_FORGE=${base_version}-forge" >> $GITHUB_OUTPUT
echo "MOD_VERSION_NEOFORGE=${base_version}-neoforge" >> $GITHUB_OUTPUT
echo "MOD_VERSION_QUILT=${base_version}-quilt" >> $GITHUB_OUTPUT
echo "MOD_VERSION=${base_version}" >> $GITHUB_OUTPUT
- run: echo "release type is ${{ steps.version.outputs.RELEASE_TYPE }}"
- run: echo "fabric mc versions are ${{ steps.version.outputs.FABRIC_MC_VERSIONS }}"
- run: echo "fabric mod version ${{ steps.version.outputs.MOD_VERSION_FABRIC }}"
- run: echo "forge mc versions are ${{ steps.version.outputs.FORGE_MC_VERSIONS }}"
- run: echo "forge mod version ${{ steps.version.outputs.MOD_VERSION_FORGE }}"
- run: echo "neoforge mc versions are ${{ steps.version.outputs.NEOFORGE_MC_VERSIONS }}"
- run: echo "neoforge mod version ${{ steps.version.outputs.MOD_VERSION_NEOFORGE }}"
- run: echo "quilt mc versions are ${{ steps.version.outputs.QUILT_MC_VERSIONS }}"
- run: echo "quilt mod version ${{ steps.version.outputs.MOD_VERSION_QUILT }}"
- name: publish fabric
if: steps.assets.outputs.FABRIC_FILE_PATH != ''
uses: Kir-Antipov/[email protected]
with:
modrinth-id: wGoQDPN5
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
modrinth-featured: false
curseforge-id: 667903
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
files: ${{ steps.assets.outputs.FABRIC_FILE_PATH }}
name: "${{ steps.version.outputs.VERSION_NAME_FABRIC }}"
version: "${{ steps.version.outputs.MOD_VERSION_FABRIC }}"
version-type: "${{ steps.version.outputs.RELEASE_TYPE }}"
loaders: "${{ steps.version.outputs.LOADERS_FABRIC }}"
#game-versions: "${{ steps.version.outputs.FABRIC_MC_VERSIONS }}"
- name: publish forge
if: steps.assets.outputs.FORGE_FILE_PATH != ''
uses: Kir-Antipov/[email protected]
with:
modrinth-id: wGoQDPN5
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
modrinth-featured: false
curseforge-id: 667903
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
files: ${{ steps.assets.outputs.FORGE_FILE_PATH }}
name: "${{ steps.version.outputs.VERSION_NAME_FORGE }}"
version: "${{ steps.version.outputs.MOD_VERSION_FORGE }}"
version-type: "${{ steps.version.outputs.RELEASE_TYPE }}"
loaders: "${{ steps.version.outputs.LOADERS_FORGE}}"
#game-versions: "${{ steps.version.outputs.FORGE_MC_VERSIONS }}"
- name: publish neoforge
if: steps.assets.outputs.NEOFORGE_FILE_PATH != ''
uses: Kir-Antipov/[email protected]
with:
modrinth-id: wGoQDPN5
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
modrinth-featured: false
curseforge-id: 667903
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
files: ${{ steps.assets.outputs.NEOFORGE_FILE_PATH }}
name: "${{ steps.version.outputs.VERSION_NAME_NEOFORGE }}"
version: "${{ steps.version.outputs.MOD_VERSION_NEOFORGE }}"
version-type: "${{ steps.version.outputs.RELEASE_TYPE }}"
loaders: "${{ steps.version.outputs.LOADERS_NEOFORGE}}"
#game-versions: "${{ steps.version.outputs.FORGE_MC_VERSIONS }}"
- name: publish quilt
if: steps.assets.outputs.QUILT_FILE_PATH != ''
uses: Kir-Antipov/[email protected]
with:
modrinth-id: wGoQDPN5
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
modrinth-featured: false
curseforge-id: 667903
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
files: ${{ steps.assets.outputs.QUILT_FILE_PATH }}
name: "${{ steps.version.outputs.VERSION_NAME_QUILT }}"
version: "${{ steps.version.outputs.MOD_VERSION_QUILT}}"
version-type: "${{ steps.version.outputs.RELEASE_TYPE }}"
loaders: "${{ steps.version.outputs.LOADERS_QUILT}}"
#game-versions: "${{ steps.version.outputs.QUILT_MC_VERSIONS }}"
# update forge versions json
- name: checkout repo forge-versions
if: steps.assets.outputs.FORGE_FILE_PATH != '' || steps.assets.outputs.NEOFORGE_FILE_PATH != ''
uses: actions/checkout@v4
with:
ref: 'forge-versions'
- name: setup python
if: steps.assets.outputs.FORGE_FILE_PATH != '' || steps.assets.outputs.NEOFORGE_FILE_PATH != ''
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: execute py script to update forge json
if: steps.assets.outputs.FORGE_FILE_PATH != ''
run: |
python -c "
import sys, json
print(sys.argv)
mc_version = sys.argv[1]
mod_version = sys.argv[2]
release_type = sys.argv[3]
jsonContent = {}
with open('forge_updates.json', 'r') as infile:
jsonContent = json.load(infile)
for str in mc_version.split(','):
version = str.strip('[]\" ')
if version != '' and version[-1:] != ')' and version[:1] != '(':
jsonContent['promos'][version + '-latest'] = mod_version
print('added ' + version + '-latest:' + mod_version)
if release_type == 'release':
jsonContent['promos'][version + '-recommended'] = mod_version
print('added ' + version + '-recommended:' + mod_version)
print(json.dumps(jsonContent, indent='\t'))
with open('forge_updates.json', 'w') as outfile:
outfile.write(json.dumps(jsonContent, indent='\t'))
" "${{ steps.version.outputs.FORGE_MC_VERSIONS }}" "${{ steps.version.outputs.MOD_VERSION }}" "${{ steps.version.outputs.RELEASE_TYPE }}"
- name: execute py script to update neoforge json
if: steps.assets.outputs.NEOFORGE_FILE_PATH != ''
run: |
python -c "
import sys, json
print(sys.argv)
mc_version = sys.argv[1]
mod_version = sys.argv[2]
release_type = sys.argv[3]
jsonContent = {}
with open('neoforge_updates.json', 'r') as infile:
jsonContent = json.load(infile)
for str in mc_version.split(','):
version = str.strip('[]\" ')
if version != '' and version[-1:] != ')' and version[:1] != '(':
jsonContent['promos'][version + '-latest'] = mod_version
print('added ' + version + '-latest:' + mod_version)
if release_type == 'release':
jsonContent['promos'][version + '-recommended'] = mod_version
print('added ' + version + '-recommended:' + mod_version)
print(json.dumps(jsonContent, indent='\t'))
with open('neoforge_updates.json', 'w') as outfile:
outfile.write(json.dumps(jsonContent, indent='\t'))
" "${{ steps.version.outputs.NEOFORGE_MC_VERSIONS }}" "${{ steps.version.outputs.MOD_VERSION }}" "${{ steps.version.outputs.RELEASE_TYPE }}"
- name: push new update json forge
if: steps.assets.outputs.FORGE_FILE_PATH != '' && steps.assets.outputs.NEOFORGE_FILE_PATH == ''
uses: EndBug/add-and-commit@v9
with:
message: 'update forge ${{ steps.version.outputs.FORGE_MC_VERSIONS }} to ${{ steps.version.outputs.MOD_VERSION }}'
push: true
- name: push new update json neoforge
if: steps.assets.outputs.FORGE_FILE_PATH == '' && steps.assets.outputs.NEOFORGE_FILE_PATH != ''
uses: EndBug/add-and-commit@v9
with:
message: 'update neoforge ${{ steps.version.outputs.NEOFORGE_MC_VERSIONS }} to ${{ steps.version.outputs.MOD_VERSION }}'
push: true
- name: push new update json forge+neoforge
if: steps.assets.outputs.FORGE_FILE_PATH != '' && steps.assets.outputs.NEOFORGE_FILE_PATH != ''
uses: EndBug/add-and-commit@v9
with:
message: 'update forge ${{ steps.version.outputs.FORGE_MC_VERSIONS }} to ${{ steps.version.outputs.MOD_VERSION }} and update neoforge ${{ steps.version.outputs.NEOFORGE_MC_VERSIONS }} to ${{ steps.version.outputs.MOD_VERSION }}'
push: true