aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'tasks/publish')
-rwxr-xr-xtasks/publish76+76 −0
1 files changed, 76 insertions, 0 deletions
diff --git a/tasks/publish b/tasks/publish
new file mode 100755
--- /dev/null
+++ b/tasks/publish
@@ -0,0 +1,76 @@
+#!/usr/bin/env -S uv run --script --python 3.14.7
+# SPDX-FileCopyrightText: 2026 Nikolay Govorov
+# SPDX-License-Identifier: 0BSD
+# fmt: off
+#MISE description="Publish signed package repositories to shared S3 storage"
+#MISE tools={"uv"="0.12.5"}
+# fmt: on
+# /// script
+# requires-python = ">=3.14"
+# dependencies = ["boto3==1.43.75"]
+# ///
+
+from __future__ import annotations
+
+import argparse
+import re
+import subprocess
+import sys
+import tempfile
+from pathlib import Path
+
+sys.dont_write_bytecode = True
+
+from _lib import TaskError
+from _repository import Repository
+
+TASK = "publish"
+FORMATS = {"deb", "rpm", "apk"}
+SAFE_SLUG = re.compile(r"^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$")
+
+
+def parser() -> argparse.ArgumentParser:
+ result = argparse.ArgumentParser(
+ prog="mise run publish --",
+ usage=("%(prog)s --service NAME --channel CHANNEL --input DIR deb|rpm|apk..."),
+ )
+ result.add_argument("--service", required=True)
+ result.add_argument("--channel", required=True)
+ result.add_argument("--input", required=True, type=Path)
+ result.add_argument("formats", nargs="+", choices=sorted(FORMATS))
+ return result
+
+
+def main() -> None:
+ command = parser()
+ arguments = command.parse_args()
+ for label, value in (
+ ("service name", arguments.service),
+ ("channel", arguments.channel),
+ ):
+ if not SAFE_SLUG.fullmatch(value) or "--" in value:
+ raise TaskError(f"{TASK}: invalid {label}: {value}")
+ if not arguments.input.is_dir():
+ raise TaskError(f"{TASK}: {arguments.input} not found")
+ with tempfile.TemporaryDirectory(prefix="publish-") as directory:
+ Repository(
+ arguments.service,
+ arguments.channel,
+ arguments.input.resolve(),
+ arguments.formats,
+ Path(directory),
+ ).publish()
+
+
+if __name__ == "__main__":
+ try:
+ main()
+ except TaskError as error:
+ print(error, file=sys.stderr)
+ raise SystemExit(1) from None
+ except subprocess.CalledProcessError as error:
+ print(
+ f"{TASK}: command failed with exit code {error.returncode}",
+ file=sys.stderr,
+ )
+ raise SystemExit(error.returncode) from None