forked from TouchController/TouchController
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
224 lines (203 loc) · 7.16 KB
/
release.sh
File metadata and controls
224 lines (203 loc) · 7.16 KB
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
#!/bin/bash
set -e
if [ -z "$MODRINTH_TOKEN" ]
then
echo "No MODRINTH_TOKEN set"
exit 1
fi
if [ -z "$MODRINTH_PROJECT_ID" ]
then
echo "No MODRINTH_PROJECT_ID set"
exit 1
fi
if [ -z "$MCMOD_COOKIE" ]
then
echo "No MCMOD_COOKIE set"
exit 1
fi
if [ -z "$MCMOD_CLASSID" ]
then
echo "No MCMOD_CLASSID set"
exit 1
fi
./gradlew clean build
mod_name="$(grep modName gradle.properties | cut -d= -f2)"
mod_version="$(grep modVersion gradle.properties | cut -d= -f2)"
mod_state="$(grep modState gradle.properties | cut -d= -f2)"
mcmod_tag=""
case "$mod_state" in
"beta")
mcmod_tag="beta"
;;
"alpha")
mcmod_tag="alpha"
;;
"release")
mcmod_tag=""
;;
*)
echo "Bad mod state: $mod_state"
exit 1
;;
esac
function extract_changelog() {
awk -v target_version="$1" '
$0 ~ /^## / {
if (found) exit
if ($2 == target_version) found = 1
next
}
found { print }
' "$2" | grep -v '^$'
}
changelog_en="$(extract_changelog "$mod_version" "NEWS-en.md")"
changelog_zh="$(extract_changelog "$mod_version" "NEWS-zh.md")"
changelog="$changelog_zh"$'\n\n---\n\n'"$changelog_en"
modrinth_versions="$(curl -sf "https://api.modrinth.com/v2/project/$MODRINTH_PROJECT_ID/version" -H "Authorization: $MODRINTH_TOKEN" | jq -r '.[].version_number')"
modmenu_versions="$(curl -sf "https://api.modrinth.com/v2/project/mOgUt4GM/version" -H "Authorization: $MODRINTH_TOKEN" | jq -cr '.[] | {version_number, id}')"
fabric_api_versions="$(curl -sf "https://api.modrinth.com/v2/project/P7dR8mSH/version" -H "Authorization: $MODRINTH_TOKEN" | jq -cr '.[] | {version_number, id}')"
function extract_version_id() {
versions="$1"
version_number="$2"
grep -F "\"$version_number\"" <<< "$versions" | jq -r .id
}
mod_files=()
fabric_files=()
forge_files=()
neoforge_files=()
for module_dir in mod/*/{fabric,forge,neoforge}-*
do
property_file="$module_dir/gradle.properties"
function extract_property() {
grep "$1" "$property_file" | cut -d= -f2
}
module_name="$(basename "$module_dir")"
module_game_version="$(extract_property gameVersion)"
module_loader="$(cut -d- -f1 <<< "$module_name")"
version_id="$mod_version+$module_name"
mod_file="$module_dir/build/libs/$mod_name-$mod_version+$module_name.jar"
mod_files+=("$mod_file")
case "$module_loader" in
"fabric")
fabric_files+=("$mod_file")
;;
"forge")
forge_files+=("$mod_file")
;;
"neoforge")
neoforge_files+=("$mod_file")
;;
*)
echo "Bad loader: $module_loader"
return 1
;;
esac
function upload_modrinth() {
if echo "$modrinth_versions" | grep -F "$version_id" > /dev/null
then
echo "Version $version_id is already on Modrinth, skip."
return 0
fi
echo "Uploading $version_id to Modrinth"
modrinth_dependencies="[]"
if [ "$module_loader" == "fabric" ]
then
modmenu_version="$(extract_property modmenuVersion)"
fabric_api_version="$(extract_property fabricApiVersion)"
modmenu_id="$(extract_version_id "$modmenu_versions" "$modmenu_version")"
fabric_api_id="$(extract_version_id "$fabric_api_versions" "$fabric_api_version")"
modrinth_dependencies="$(jq -n \
--arg modmenu_version "$modmenu_id" \
--arg fabric_api_version "$fabric_api_id" \
'[
{
"project_id": "mOgUt4GM",
"version_id": $modmenu_version,
"dependency_type": "optional"
},
{
"project_id": "P7dR8mSH",
"version_id": $fabric_api_version,
"dependency_type": "required"
}
]'
)"
fi
modrinth_data="$(jq -n \
--arg name "$mod_version" \
--arg version_number "$version_id" \
--arg changelog "$changelog" \
--arg dependencies "$modrinth_dependencies" \
--arg game_version "$module_game_version" \
--arg version_type "$mod_state" \
--arg loader "$module_loader" \
--arg project_id "$MODRINTH_PROJECT_ID" \
'{
"name": $name,
"version_number": $version_number,
"changelog": $changelog,
"featured": true,
"dependencies": '"$modrinth_dependencies"',
"game_versions": [$game_version],
"version_type": $version_type,
"loaders": [$loader],
"project_id": $project_id,
"file_parts": ["primary_file"],
"primary_file": "primary_file"
}'
)"
curl --fail-with-body "https://api.modrinth.com/v2/version" \
-H "Authorization: $MODRINTH_TOKEN" \
-F data="$modrinth_data" \
-F primary_file="@$mod_file"
echo
}
function upload_mcmod() {
api_list=""
case "$module_loader" in
"fabric")
api_list="2"
;;
"forge")
api_list="1"
;;
"neoforge")
api_list="13"
;;
*)
echo "Bad loader: $module_loader"
return 1
;;
esac
echo "Uploading $version_id to mcmod"
upload_result="$( \
curl -sf "https://modfile-dl.mcmod.cn/action/upload/" \
--cookie "$MCMOD_COOKIE" \
-F classID="$MCMOD_CLASSID" \
-F mcverList="$module_game_version" \
-F platformList="1" \
-F apiList="$api_list" \
-F tagList="$mcmod_tag" \
-F 0="@$mod_file" \
)"
if [ "$(jq .state <<< "$upload_result")" -ne 0 ]
then
echo "mcmod upload failed: $upload_result"
exit 1
fi
}
upload_modrinth
upload_mcmod
# TODO: Upload CurseForge
done
rm -f "bundle/TouchController-${mod_version}.zip" "bundle/TouchController-${mod_version}-"*".zip"
zip -j "bundle/TouchController-${mod_version}.zip" "${mod_files[@]}"
zip -j "bundle/TouchController-${mod_version}-fabric.zip" "${fabric_files[@]}"
zip -j "bundle/TouchController-${mod_version}-forge.zip" "${forge_files[@]}"
zip -j "bundle/TouchController-${mod_version}-neoforge.zip" "${neoforge_files[@]}"
mkdir -p "release/${mod_version}"
for file in "${mod_files[@]}"
do
name="$(basename "${file}")"
cp "$file" "release/${mod_version}/${name}"
done