summaryrefslogtreecommitdiffstats
path: root/ci
diff options
context:
space:
mode:
authorFly me to the moon <git@bigly.dog>2021-09-10 15:47:15 -0700
committerFly me to the moon <git@bigly.dog>2021-09-10 15:47:15 -0700
commit6016c1233c93c437cb9b66c3613f495720263dc4 (patch)
treecec1465d464e1b807c678a61679e49cb08f2cad1 /ci
parentcead66ba0f591dafb7aee2ac460c8ecd75bfd952 (diff)
try into
Diffstat (limited to 'ci')
-rwxr-xr-xci/ci.py12
-rwxr-xr-xci/docker.py79
2 files changed, 55 insertions, 36 deletions
diff --git a/ci/ci.py b/ci/ci.py
index 1b657ec..1c74400 100755
--- a/ci/ci.py
+++ b/ci/ci.py
@@ -3,15 +3,11 @@
from argparse import ArgumentParser, Namespace
from datetime import datetime
from json import dumps
-from os import chdir
-from os.path import abspath, dirname
+from pathlib import Path
from toml import load
-
-def _cwd() -> None:
- root = dirname(dirname(abspath(__file__)))
- chdir(root)
+_TOP_LEVEL = Path(__file__).resolve().parent.parent
def _read(name: str) -> str:
@@ -24,7 +20,8 @@ def _set_output(name: str, value: str) -> None:
def _set_release_env() -> None:
- cargo = load("Cargo.toml")
+ cargo = load(_TOP_LEVEL / "Cargo.toml")
+
version = cargo["package"]["version"]
time = datetime.now()
tag_name = f"ci_{version}_{time.strftime('%Y-%m-%d_%H-%M')}"
@@ -47,7 +44,6 @@ def _parse_args() -> Namespace:
def main() -> None:
- _cwd()
args = _parse_args()
if args.release:
_set_release_env()
diff --git a/ci/docker.py b/ci/docker.py
index fc6068a..db2fc5d 100755
--- a/ci/docker.py
+++ b/ci/docker.py
@@ -2,26 +2,13 @@
from argparse import ArgumentParser, Namespace
from datetime import datetime
-from os import chdir
-from os.path import dirname, join
-from subprocess import run
-from typing import Any
+from pathlib import Path
+from subprocess import check_call
from yaml import safe_load
-__dir__ = dirname(__file__)
-__prefix__ = "msjpq/sad"
-
-
-def _call(prog: str, *args: str) -> None:
- ret = run([prog, *args])
- if ret.returncode != 0:
- exit(ret.returncode)
-
-
-def _slurp_yaml(path: str) -> Any:
- with open(path) as fd:
- return safe_load(fd)
+_TOP_LEVEL = Path(__file__).resolve().parent.parent
+_PREFIX = "msjpq/sad"
def _parse_args() -> Namespace:
@@ -31,30 +18,66 @@ def _parse_args() -> Namespace:
def _docker_build(name: str) -> None:
- image = f"{__prefix__}:{name}"
- path = join("ci", name, "Dockerfile")
- _call("docker", "build", "-t", image, "-f", path, ".")
+ image = f"{_PREFIX}:{name}"
+ path = _TOP_LEVEL / "ci" / name / "Dockerfile"
+ check_call(
+ (
+ "docker",
+ "build",
+ "-t",
+ image,
+ "-f",
+ path,
+ "--",
+ ".",
+ ),
+ cwd=_TOP_LEVEL,
+ )
def _docker_cp(name: str) -> None:
time = datetime.now().strftime("%H-%M-%S")
- image = f"{__prefix__}:{name}"
- path = join("ci", name, "artifacts.yml")
- spec = _slurp_yaml(path)
+ image = f"{_PREFIX}:{name}"
+ path = _TOP_LEVEL / "ci" / name / "artifacts.yml"
+ with path.open() as fd:
+ spec = safe_load(fd)
+
container = f"{name}-{time}"
- _call("docker", "create", "--name", container, image)
+ check_call(
+ (
+ "docker",
+ "create",
+ "--name",
+ container,
+ image,
+ )
+ )
for target in spec["targets"]:
src = f"{container}:{target['src']}"
- dest = join("artifacts", target["dest"])
- _call("docker", "cp", src, dest)
- _call("docker", "rm", container)
+ dest = _TOP_LEVEL / "artifacts" / target["dest"]
+ check_call(
+ (
+ "docker",
+ "cp",
+ src,
+ dest,
+ )
+ )
+
+ check_call(
+ (
+ "docker",
+ "rm",
+ container,
+ )
+ )
def main() -> None:
- chdir(dirname(__dir__))
args = _parse_args()
name = args.dest
+
_docker_build(name)
_docker_cp(name)