Publish?
All checks were successful
CI / Typst formatting (push) Successful in 13s
CI / Typos (push) Successful in 16s
CI / Build (push) Successful in 13m14s

This commit is contained in:
mark 2025-01-21 22:58:00 -08:00 committed by Mark
parent eb1ee2c2cb
commit 0930b8a964
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
2 changed files with 32 additions and 49 deletions

View File

@ -88,11 +88,10 @@ jobs:
retention-days: 7
- name: "Publish package"
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
run: |
PUBLISH_USER="${{ secrets.PUBLISH_USER }}" \
PUBLISH_KEY="${{ secrets.PUBLISH_KEY }}" \
VERSION="${{ github.sha }}" \
PACKAGE="${{ secrets.PACKAGE }}" \
PACKAGE="${{ vars.PACKAGE }}" \
python tools/build/publish.py

View File

@ -1,83 +1,67 @@
from typing import TypedDict
from pathlib import Path
import requests
import shutil
import json
import os
from requests.auth import HTTPBasicAuth
URL="https://git.betalupi.com"
USER = os.environ['USER']
PACKAGE = os.environ['PACKAGE']
VERSION = os.environ['VERSION']
AUTH = HTTPBasicAuth(USER, os.environ['PUBLISH_KEY'])
URL = "https://git.betalupi.com"
USER = os.environ["USER"]
PACKAGE = os.environ["PACKAGE"]
VERSION = os.environ["VERSION"]
AUTH = requests.auth.HTTPBasicAuth(USER, os.environ["PUBLISH_KEY"])
ROOT: Path = Path(os.getcwd())
SRC_DIR: Path = ROOT / "output"
def log(msg):
print(f"[PUBLISH.PY] {msg}")
log(f"Version is {VERSION}")
log(f"Package is {PACKAGE}")
log(f"Running in {ROOT}")
if not ROOT.is_dir():
log("Root is not a directory, cannot continue")
exit(1)
log(f"Output dir is {SRC_DIR}")
log(f"Source dir is {SRC_DIR}")
if not SRC_DIR.exists():
log("Output dir doesn't exist, cannot continue")
log("Source dir doesn't exist, cannot continue")
exit(1)
IndexEntry = TypedDict(
"IndexEntry",
{"title": str, "group": str, "handout_file": str, "solutions_file": str | None},
)
def upload(data, target: str):
requests.put(
f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/{target}",
auth=AUTH,
data=data,
)
return f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/{target}"
index = SRC_DIR / "index.json"
with index.open("r") as f:
index_file = SRC_DIR / "index.json"
with index_file.open("r") as f:
index = json.load(f)
new_index = []
for handout in index:
title = handout["title"]
group = handout["group"]
h_file = SRC_DIR/handout["handout_file"]
s_file = SRC_DIR/handout["handout_file"]
h_file = SRC_DIR / handout["handout_file"]
s_file = SRC_DIR / handout["handout_file"]
h_url = None
s_url = None
target = f"{group} - {title}.pdf"
requests.put(
f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/{target}",
auth=AUTH,
data=h_file.open('rb').read()
)
h_url = f"{URL}/api/packages/{USER}/generic/ormc-handouts/{VERSION}/{target}"
h_url = upload(h_file.open("rb").read(), f"{group} - {title}.pdf")
if s_file is not None:
target = f"{group} - {title}.sols.pdf"
requests.put(
f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/{target}",
auth=AUTH,
data=s_file.open('rb').read()
s_url = upload(s_file.open("rb").read(), f"{group} - {title}.sols.pdf")
log(f"Published {title} to {h_url}")
new_index.append(
{"title": title, "group": group, "handout": h_url, "solutions": s_url}
)
s_url = f"{URL}/api/packages/{USER}/generic/ormc-handouts/{VERSION}/{target}"
log(f"Published {title}")
new_index.append({
"title": title,
"group": group,
"handout": h_url,
"solutions": s_url
})
requests.put(
f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/index.json",
auth=AUTH,
data=json.dumps(new_index)
)
upload(json.dumps(new_index), "index.json")