Added workflow?
This commit is contained in:
63
tools/scripts/publish.py
Normal file
63
tools/scripts/publish.py
Normal file
@ -0,0 +1,63 @@
|
||||
# Publish the output of `build.py`
|
||||
# as a Gitea package.
|
||||
|
||||
from pathlib import Path
|
||||
import requests
|
||||
import os
|
||||
import re
|
||||
|
||||
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())
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def del_package():
|
||||
log(f"Deleting package {PACKAGE}/{VERSION}")
|
||||
res = requests.delete(
|
||||
f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}",
|
||||
auth=AUTH,
|
||||
)
|
||||
if res.status_code != 204 and res.status_code != 404:
|
||||
log(f"Deletion failed with code {res.status_code}")
|
||||
|
||||
|
||||
# Delete if already exists
|
||||
# (important for the `latest` package)
|
||||
del_package()
|
||||
|
||||
|
||||
def upload(data, target: str):
|
||||
target = re.sub("[^A-Za-z0-9_. -]+", "", target)
|
||||
|
||||
res = requests.put(
|
||||
f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/{target}",
|
||||
auth=AUTH,
|
||||
data=data,
|
||||
)
|
||||
|
||||
if res.status_code != 201:
|
||||
log(f"Upload failed with code {res.status_code}")
|
||||
del_package() # Do not keep partial package if upload fails
|
||||
exit(1)
|
||||
|
||||
return f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/{target}"
|
||||
|
||||
|
||||
log("Uploading disk.img")
|
||||
upload(Path("./build/disk.img").open("rb").read(), "disk.img")
|
18
tools/scripts/ruff.toml
Normal file
18
tools/scripts/ruff.toml
Normal file
@ -0,0 +1,18 @@
|
||||
exclude = ["venv"]
|
||||
line-length = 88
|
||||
indent-width = 4
|
||||
target-version = "py39"
|
||||
include = ["scripts/**/*.py"]
|
||||
|
||||
[lint]
|
||||
select = ["E4", "E7", "E9", "F"]
|
||||
ignore = []
|
||||
fixable = ["ALL"]
|
||||
unfixable = []
|
||||
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
|
||||
|
||||
[format]
|
||||
quote-style = "double"
|
||||
indent-style = "tab"
|
||||
skip-magic-trailing-comma = false
|
||||
line-ending = "lf"
|
Reference in New Issue
Block a user