2025-07-17 13:46:36 -04:00

42 lines
1.4 KiB
Python

import os
import sys
from allspice import AllSpice
def main():
token = os.getenv("ALLSPICE_TOKEN")
repo_full = os.getenv("ALLSPICE_REPOSITORY") # e.g., owner/repo
release_tag = os.getenv("RELEASE_TAG")
files_to_upload = os.getenv("FILES_TO_UPLOAD") # comma separated list of files
if not token or not repo_full or not release_tag or not files_to_upload:
print("Missing required environment variables.")
sys.exit(1)
owner, repo = repo_full.split("/")
client = AllSpice(token_text=token)
repository = client.get_repository(owner, repo)
try:
release = repository.get_release_by_tag(release_tag)
except Exception as e:
print(f"Failed to get release by tag '{release_tag}': {e}")
sys.exit(1)
for file_path in files_to_upload.split(","):
file_path = file_path.strip()
if not os.path.isfile(file_path):
print(f"File not found, skipping: {file_path}")
continue
print(f"Uploading {file_path} ...")
try:
filename = os.path.basename(file_path)
with open(file_path, "rb") as f:
release.create_asset(f, name=filename)
print(f"Uploaded: {file_path}")
except Exception as e:
print(f"Failed to upload {file_path}: {e}")
print("Upload process completed.")
if __name__ == "__main__":
main()