act
This commit is contained in:
parent
dd1175d6a3
commit
c00313ce1f
5
.github/workflows/ci.yml
vendored
5
.github/workflows/ci.yml
vendored
@ -88,11 +88,10 @@ jobs:
|
|||||||
retention-days: 7
|
retention-days: 7
|
||||||
|
|
||||||
- name: "Publish package"
|
- name: "Publish package"
|
||||||
|
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
|
||||||
run: |
|
run: |
|
||||||
PUBLISH_USER="${{ secrets.PUBLISH_USER }}" \
|
PUBLISH_USER="${{ secrets.PUBLISH_USER }}" \
|
||||||
PUBLISH_KEY="${{ secrets.PUBLISH_KEY }}" \
|
PUBLISH_KEY="${{ secrets.PUBLISH_KEY }}" \
|
||||||
VERSION="${{ github.sha }}" \
|
VERSION="${{ github.sha }}" \
|
||||||
PACKAGE="${{ secrets.PACKAGE }}" \
|
PACKAGE="${{ vars.PACKAGE }}" \
|
||||||
python tools/build/publish.py
|
python tools/build/publish.py
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,26 +1,24 @@
|
|||||||
from typing import TypedDict
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import requests
|
import requests
|
||||||
import shutil
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from requests.auth import HTTPBasicAuth
|
|
||||||
|
|
||||||
URL = "https://git.betalupi.com"
|
URL = "https://git.betalupi.com"
|
||||||
USER = os.environ['USER']
|
USER = os.environ["USER"]
|
||||||
PACKAGE = os.environ['PACKAGE']
|
PACKAGE = os.environ["PACKAGE"]
|
||||||
VERSION = os.environ['VERSION']
|
VERSION = os.environ["VERSION"]
|
||||||
AUTH = HTTPBasicAuth(USER, os.environ['PUBLISH_KEY'])
|
AUTH = requests.auth.HTTPBasicAuth(USER, os.environ["PUBLISH_KEY"])
|
||||||
|
|
||||||
ROOT: Path = Path(os.getcwd())
|
ROOT: Path = Path(os.getcwd())
|
||||||
SRC_DIR: Path = ROOT / "output"
|
SRC_DIR: Path = ROOT / "output"
|
||||||
|
|
||||||
|
|
||||||
def log(msg):
|
def log(msg):
|
||||||
print(f"[PUBLISH.PY] {msg}")
|
print(f"[PUBLISH.PY] {msg}")
|
||||||
|
|
||||||
|
|
||||||
log(f"Version is {VERSION}")
|
log(f"Version is {VERSION}")
|
||||||
log(f"Package is is {PACKAGE}")
|
log(f"Package is {PACKAGE}")
|
||||||
log(f"Running in {ROOT}")
|
log(f"Running in {ROOT}")
|
||||||
if not ROOT.is_dir():
|
if not ROOT.is_dir():
|
||||||
log("Root is not a directory, cannot continue")
|
log("Root is not a directory, cannot continue")
|
||||||
@ -31,16 +29,18 @@ if not SRC_DIR.exists():
|
|||||||
log("Source dir doesn't exist, cannot continue")
|
log("Source dir doesn't exist, cannot continue")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
def upload(data, target: str):
|
def upload(data, target: str):
|
||||||
requests.put(
|
requests.put(
|
||||||
f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/{target}",
|
f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/{target}",
|
||||||
auth=AUTH,
|
auth=AUTH,
|
||||||
data=data
|
data=data,
|
||||||
)
|
)
|
||||||
return f"{URL}/api/packages/{USER}/generic/ormc-handouts/{VERSION}/{target}"
|
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)
|
index = json.load(f)
|
||||||
|
|
||||||
new_index = []
|
new_index = []
|
||||||
@ -53,27 +53,15 @@ for handout in index:
|
|||||||
h_url = None
|
h_url = None
|
||||||
s_url = None
|
s_url = None
|
||||||
|
|
||||||
h_url = upload(
|
h_url = upload(h_file.open("rb").read(), f"{group} - {title}.pdf")
|
||||||
h_file.open('rb').read(),
|
|
||||||
f"{group} - {title}.pdf"
|
|
||||||
)
|
|
||||||
|
|
||||||
if s_file is not None:
|
if s_file is not None:
|
||||||
s_url = upload(
|
s_url = upload(s_file.open("rb").read(), f"{group} - {title}.sols.pdf")
|
||||||
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}
|
||||||
)
|
)
|
||||||
|
|
||||||
log(f"Published {title}")
|
upload(json.dumps(new_index), "index.json")
|
||||||
|
|
||||||
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