Files
ss14-wl/Tools/publish_github_artifact.py
2024-10-09 21:12:59 +05:00

56 lines
1.5 KiB
Python
Executable File

#!/usr/bin/env python3
import requests
import os
import subprocess
GITHUB_TOKEN = os.environ["GITHUB_TOKEN"]
PUBLISH_TOKEN = os.environ["PUBLISH_TOKEN"]
ARTIFACT_ID = os.environ["ARTIFACT_ID"]
GITHUB_REPOSITORY = os.environ["GITHUB_REPOSITORY"]
VERSION = os.environ['GITHUB_SHA']
FORK_ID = os.environ['FORK_ID']
#
# CONFIGURATION PARAMETERS
# Forks should change these to publish to their own infrastructure.
#
ROBUST_CDN_URL = "https://cdn.station14.ru/"
def main():
print("Fetching artifact URL from API...")
artifact_url = get_artifact_url()
print(f"Artifact URL is {artifact_url}, publishing to Robust.Cdn")
data = {
"version": VERSION,
"engineVersion": get_engine_version(),
"archive": artifact_url
}
headers = {
"Authorization": f"Bearer {PUBLISH_TOKEN}",
"Content-Type": "application/json"
}
resp = requests.post(f"{ROBUST_CDN_URL}fork/{FORK_ID}/publish", json=data, headers=headers)
resp.raise_for_status()
print("Publish succeeded!")
def get_artifact_url() -> str:
headers = {
"Authorization": f"Bearer {GITHUB_TOKEN}",
"X-GitHub-Api-Version": "2022-11-28",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
}
resp = requests.get(ARTIFACT_ID, allow_redirects=False, headers=headers)
resp.raise_for_status()
return resp.headers["Location"]
def get_engine_version() -> str:
return "236.0.0"
if __name__ == '__main__':
main()