spcd/spcd/act.py
Marc Beninca dfd4219191
Some checks failed
/ alpine (push) Failing after 22s
/ debian (push) Failing after 1m17s
/ ubuntu (push) Failing after 1m38s
/ arch (push) Failing after 37s
/ opensuse (push) Failing after 1m50s
/ fedora (push) Failing after 3m28s
/ alma (push) Failing after 4m10s
/ rocky (push) Failing after 6m12s
lint
2025-02-22 23:47:16 +01:00

62 lines
1.5 KiB
Python

"""Actions available for workflows."""
from __future__ import annotations
import os
from ast import literal_eval
from pathlib import Path
from rwx import ps
from rwx.log import stream as log
from spcd.ci import project, projects
from spcd.shell import env
PREFIX = "INPUT_"
def action() -> None:
"""Display action inputs."""
for variable, value in parse_inputs().items():
log.info("%s = %s", variable, value)
def parse_inputs() -> dict[str, object]:
"""Parse inputs as a dictionary.
:return: name & value pairs
:rtype: dict[str, object]
"""
inputs = {}
for variable, value in sorted(projects.environment.items()):
if variable.startswith(PREFIX):
name = variable.removeprefix(PREFIX).lower()
inputs[name] = literal_eval(value)
return inputs
def synchronize(source: str | None = None, target: str | None = None) -> None:
"""Synchronize output towards a target.
:param source: where to deploy from
:type source: str | None
:param target: where to deploy to
:type target: str | None
"""
if not target:
user = "cd"
host = env.SPCD_PROJECT_PATH
root = (
Path(os.sep) / user / projects.group / project.name / project.branch
)
target = f"{user}@{host}:{root}"
if not source:
source = "out"
ps.run(
"rsync",
"--archive",
"--delete-before",
"--verbose",
f"{source}/",
f"{target}/",
)