Skip to content

Commit b454252

Browse files
committed
attempt some number
1 parent 637a32a commit b454252

File tree

1 file changed

+39
-19
lines changed

1 file changed

+39
-19
lines changed

.github/workflows/deploy.py

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def should_update_pack(modrinth_json):
6868

6969
def zip_and_post(modrinth_info, root):
7070
version = get_current_version(modrinth_info)
71-
project_id = get_project_id(modrinth_info)
7271
relative_path = os.path.relpath(root, datapack_folder)
7372
datapack_name = f"{relative_path.replace(os.sep, '_')}_v{version}.zip"
7473
full_datapack_path = os.path.join(root, datapack_name)
@@ -83,11 +82,38 @@ def zip_and_post(modrinth_info, root):
8382
zipped_file.write(os.path.join(root, file), arcname=file)
8483
print(f"zipping {file}")
8584

85+
post(modrinth_info, datapack_name, zipped_file_path)
86+
87+
88+
89+
def post(modrinth_info, datapack_name, zipped_file_path):
90+
version = get_current_version(modrinth_info)
91+
project_id = get_project_id(modrinth_info)
92+
ver_name = modrinth_info["name"]
93+
changelog = modrinth_info["changelog"]
94+
dependencies = modrinth_info["dependencies"]
95+
supported_versions = modrinth_info["supported_versions"]
96+
release_type = modrinth_info["version_type"]
97+
8698
files = {
87-
'data': (None, json.dumps(modrinth_info), 'application/json'),
88-
'file': (datapack_name, open(zipped_file_path, 'rb'), 'application/zip')
99+
'primary_file': (datapack_name, open(zipped_file_path, 'rb'), 'application/zip')
100+
}
101+
102+
payload = {
103+
"name": ver_name,
104+
"version_number": version,
105+
"changelog": changelog,
106+
"dependencies": dependencies,
107+
"game_versions": supported_versions,
108+
"version_type": release_type,
109+
"loaders": ['datapack'],
110+
"featured": 'false',
111+
"project_id": project_id
89112
}
90-
response = requests.post(modrinth_post_version_route, headers={"Authorization": modrinth_token}, files=files)
113+
114+
115+
116+
response = requests.post(modrinth_post_version_route, headers={"Authorization": modrinth_token}, files=files, data=payload)
91117
upload_response = response.json()
92118

93119
if 'error' not in upload_response:
@@ -96,26 +122,20 @@ def zip_and_post(modrinth_info, root):
96122
print(f"Failed to upload {datapack_name}. Output:\n{upload_response}")
97123

98124

99-
100125
def main():
101-
print(f"Starting the datapack update process in {datapack_folder}.")
102126
for root, dirs, files in os.walk(datapack_folder):
103-
print(f"Checking directory: {root}")
104127
if 'pack.mcmeta' not in files:
105-
print(f"{root} is not a pack directory, skipping.")
128+
print(f"{root} is not a pack directory, skipping")
106129
continue
107130
if 'modrinth.json' not in files:
108-
print(f"{root} does not have a modrinth.json file, skipping.")
131+
print(f"{root} does not have a modrinth json file, skipping")
132+
continue
133+
datapack_info = get_datapack_info(os.path.join(root, "modrinth.json"))
134+
if not should_update_pack(datapack_info):
109135
continue
110-
try:
111-
datapack_info = get_datapack_info(os.path.join(root, "modrinth.json"))
112-
if not should_update_pack(datapack_info):
113-
print(f"Skipping {root}: no update needed.")
114-
continue
115-
print(f"Preparing to update {root}.")
116-
zip_and_post(datapack_info, root)
117-
except Exception as e:
118-
print(f"Error processing directory {root}: {e}")
136+
zip_and_post(datapack_info, root)
137+
138+
119139

120140
if __name__ == "__main__":
121-
main()
141+
main()

0 commit comments

Comments
 (0)