2022-11-26 04:36:25 +00:00
|
|
|
#!/usr/bin/env python3
|
2023-10-08 11:41:43 +00:00
|
|
|
|
|
|
|
###
|
|
|
|
# Uploads progress information to https://github.com/decompals/frogress.
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
# python3 tools/upload_progress.py -b https://progress.decomp.club/ -p [project] -v [version] build/[version]/progress.json
|
|
|
|
#
|
|
|
|
# If changes are made, please submit a PR to
|
|
|
|
# https://github.com/encounter/dtk-template
|
|
|
|
###
|
|
|
|
|
2022-11-26 04:36:25 +00:00
|
|
|
import argparse
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import requests
|
2023-10-08 11:41:43 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2022-11-26 04:36:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_git_commit_timestamp() -> int:
|
2023-10-08 11:41:43 +00:00
|
|
|
return int(
|
|
|
|
subprocess.check_output(["git", "show", "-s", "--format=%ct"])
|
|
|
|
.decode("ascii")
|
|
|
|
.rstrip()
|
|
|
|
)
|
2022-11-26 04:36:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_git_commit_sha() -> str:
|
2023-10-08 11:41:43 +00:00
|
|
|
return subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("ascii").strip()
|
2022-11-26 04:36:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
def generate_url(args: argparse.Namespace) -> str:
|
2023-10-08 11:41:43 +00:00
|
|
|
url_components = [args.base_url.rstrip("/"), "data"]
|
2022-11-26 04:36:25 +00:00
|
|
|
|
|
|
|
for arg in [args.project, args.version]:
|
|
|
|
if arg != "":
|
|
|
|
url_components.append(arg)
|
|
|
|
|
2023-10-08 11:41:43 +00:00
|
|
|
return str.join("/", url_components) + "/"
|
2022-11-26 04:36:25 +00:00
|
|
|
|
|
|
|
|
2023-10-08 11:41:43 +00:00
|
|
|
if __name__ == "__main__":
|
2022-11-26 04:36:25 +00:00
|
|
|
parser = argparse.ArgumentParser(description="Upload progress information.")
|
|
|
|
parser.add_argument("-b", "--base_url", help="API base URL", required=True)
|
|
|
|
parser.add_argument("-a", "--api_key", help="API key (env var PROGRESS_API_KEY)")
|
|
|
|
parser.add_argument("-p", "--project", help="Project slug", required=True)
|
|
|
|
parser.add_argument("-v", "--version", help="Version slug", required=True)
|
|
|
|
parser.add_argument("input", help="Progress JSON input")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
api_key = args.api_key or os.environ.get("PROGRESS_API_KEY")
|
|
|
|
if not api_key:
|
2024-06-24 04:34:51 +00:00
|
|
|
raise KeyError("API key required")
|
2022-11-26 04:36:25 +00:00
|
|
|
url = generate_url(args)
|
|
|
|
|
|
|
|
entries = []
|
|
|
|
with open(args.input, "r") as f:
|
|
|
|
data = json.load(f)
|
2023-10-08 11:41:43 +00:00
|
|
|
entries.append(
|
|
|
|
{
|
|
|
|
"timestamp": get_git_commit_timestamp(),
|
|
|
|
"git_hash": get_git_commit_sha(),
|
|
|
|
"categories": data,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
print("Publishing entry to", url)
|
|
|
|
json.dump(entries[0], sys.stdout, indent=4)
|
|
|
|
print()
|
2024-06-24 04:34:51 +00:00
|
|
|
r = requests.post(
|
|
|
|
url,
|
|
|
|
json={
|
|
|
|
"api_key": api_key,
|
|
|
|
"entries": entries,
|
|
|
|
},
|
|
|
|
)
|
2022-11-26 04:36:25 +00:00
|
|
|
r.raise_for_status()
|
2024-06-24 04:34:51 +00:00
|
|
|
print("Done!")
|