This repository has been archived on 2024-08-25. You can view files and clone it, but cannot push or open issues or pull requests.
gitea-branding/upload.py
Jake Howard e075abd796
Some checks failed
build
Add CI
2023-03-26 19:58:51 +01:00

44 lines
1.2 KiB
Python
Executable file

#!/usr/bin/env python3
import requests
from pathlib import Path
from resize import OUTPUT_DIR
import os
import zipfile
from io import BytesIO
ARTIFACT_NAME = "branding.zip"
OWNER = "sys"
PACKAGE_NAME = "gitea-branding"
def main():
gitea_url = os.environ["GITEA_URL"]
gitea_token = os.environ["GITEA_TOKEN"]
session = requests.Session()
session.headers["Authorization"] = f"token {gitea_token}"
print("Building archive...")
archive = BytesIO()
with zipfile.ZipFile(archive, "w") as zip_file:
for output_file in OUTPUT_DIR.rglob("*.*"):
zip_file.writestr(output_file.name, output_file.read_bytes())
archive.seek(0)
print("Deleting existing...")
delete_response = session.delete(f"{gitea_url}/api/packages/{OWNER}/generic/{PACKAGE_NAME}/latest/{ARTIFACT_NAME}")
# 404 means we've not uploaded it yet.
if delete_response.status_code != 404:
delete_response.raise_for_status()
print("Uploading...")
response = session.put(f"{gitea_url}/api/packages/{OWNER}/generic/{PACKAGE_NAME}/latest/{ARTIFACT_NAME}", files={ARTIFACT_NAME: archive})
response.raise_for_status()
if __name__ == "__main__":
main()