Fix publish?
This commit is contained in:
parent
0930b8a964
commit
66670d6751
5
.github/workflows/ci.yml
vendored
5
.github/workflows/ci.yml
vendored
@ -3,6 +3,7 @@ name: CI
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
pull_request:
|
pull_request:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
typos:
|
typos:
|
||||||
@ -67,7 +68,7 @@ jobs:
|
|||||||
|
|
||||||
# Builds all handouts, LaTeX and Typst
|
# Builds all handouts, LaTeX and Typst
|
||||||
- name: "Build handouts"
|
- name: "Build handouts"
|
||||||
run: TYPST_PATH="$(pwd)/typst" python tools/build/main.py
|
run: TYPST_PATH="$(pwd)/typst" python tools/scripts/build.py
|
||||||
|
|
||||||
# Upload logs, even if build fails.
|
# Upload logs, even if build fails.
|
||||||
# LaTeX stdout/stderr isn't always helpful.
|
# LaTeX stdout/stderr isn't always helpful.
|
||||||
@ -94,4 +95,4 @@ jobs:
|
|||||||
PUBLISH_KEY="${{ secrets.PUBLISH_KEY }}" \
|
PUBLISH_KEY="${{ secrets.PUBLISH_KEY }}" \
|
||||||
VERSION="${{ github.sha }}" \
|
VERSION="${{ github.sha }}" \
|
||||||
PACKAGE="${{ vars.PACKAGE }}" \
|
PACKAGE="${{ vars.PACKAGE }}" \
|
||||||
python tools/build/publish.py
|
python tools/scripts/publish.py
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
from pathlib import Path
|
|
||||||
import requests
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
|
|
||||||
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"Source dir is {SRC_DIR}")
|
|
||||||
if not SRC_DIR.exists():
|
|
||||||
log("Source dir doesn't exist, cannot continue")
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
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_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_url = None
|
|
||||||
s_url = None
|
|
||||||
|
|
||||||
h_url = upload(h_file.open("rb").read(), f"{group} - {title}.pdf")
|
|
||||||
|
|
||||||
if s_file is not None:
|
|
||||||
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}
|
|
||||||
)
|
|
||||||
|
|
||||||
upload(json.dumps(new_index), "index.json")
|
|
@ -179,11 +179,9 @@ def build_typst(source_dir: Path, out_subdir: Path) -> IndexEntry | None:
|
|||||||
return {
|
return {
|
||||||
"title": meta["title"],
|
"title": meta["title"],
|
||||||
"group": str(out_subdir),
|
"group": str(out_subdir),
|
||||||
"handout_file": str(out/handout_file),
|
"handout_file": str(out / handout_file),
|
||||||
"solutions_file": (
|
"solutions_file": (
|
||||||
str(out/solutions_file)
|
str(out / solutions_file) if meta["publish_solutions"] else None
|
||||||
if meta["publish_solutions"]
|
|
||||||
else None
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,11 +256,9 @@ def build_xetex(source_dir: Path, out_subdir: Path) -> IndexEntry | None:
|
|||||||
return {
|
return {
|
||||||
"title": meta["title"],
|
"title": meta["title"],
|
||||||
"group": str(out_subdir),
|
"group": str(out_subdir),
|
||||||
"handout_file": str(out/handout_file),
|
"handout_file": str(out / handout_file),
|
||||||
"solutions_file": (
|
"solutions_file": (
|
||||||
str(out/solutions_file)
|
str(out / solutions_file) if meta["publish_solutions"] else None
|
||||||
if meta["publish_solutions"]
|
|
||||||
else None
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
67
tools/scripts/publish.py
Normal file
67
tools/scripts/publish.py
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
URL = "https://git.betalupi.com"
|
||||||
|
USER = os.environ["PUBLISH_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"Source dir is {SRC_DIR}")
|
||||||
|
if not SRC_DIR.exists():
|
||||||
|
log("Source dir doesn't exist, cannot continue")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
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_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_url = None
|
||||||
|
s_url = None
|
||||||
|
|
||||||
|
h_url = upload(h_file.open("rb").read(), f"{group} - {title}.pdf")
|
||||||
|
|
||||||
|
if s_file is not None:
|
||||||
|
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}
|
||||||
|
)
|
||||||
|
|
||||||
|
upload(json.dumps(new_index), "index.json")
|
Loading…
x
Reference in New Issue
Block a user