diff --git a/spcd/__init__.py b/spcd/__init__.py index c2bf4b0..ad58e1d 100644 --- a/spcd/__init__.py +++ b/spcd/__init__.py @@ -10,7 +10,7 @@ from rwx import fs from rwx.log import stream as log from rwx.ps import run -from spcd import cmd +from spcd import act, cmd from spcd.ci import project, projects from spcd.shell import env from spcd.util import browse, cat, split, step @@ -131,12 +131,17 @@ def main(main_file: Path) -> None: path, *arguments = sys.argv name = Path(path).name if name == "__main__.py": - list_environment_variables() - clone_project_branch() - set_ssh() - install_actions(main_file) - install_commands(main_file) - install_python_packages() + if arguments: + name, *arguments = arguments + f = getattr(act, name) + f(*arguments) + else: + list_environment_variables() + clone_project_branch() + set_ssh() + install_actions(main_file) + install_commands(main_file) + install_python_packages() else: f = getattr(cmd, name.replace("-", "_")) f(*arguments) diff --git a/spcd/act.py b/spcd/act.py new file mode 100644 index 0000000..87e9fe1 --- /dev/null +++ b/spcd/act.py @@ -0,0 +1,38 @@ +"""Actions available for workflows.""" + +import os +from pathlib import Path + +from rwx import ps + +from spcd.ci import project, projects +from spcd.shell import env + + +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}/", + ) diff --git a/spcd/actions/synchronize/action.yaml b/spcd/actions/synchronize/action.yaml index 15aaf68..46526be 100644 --- a/spcd/actions/synchronize/action.yaml +++ b/spcd/actions/synchronize/action.yaml @@ -5,4 +5,4 @@ inputs: runs: using: composite steps: - - run: echo "synchronize" + - run: python3 -m "spcd" "synchronize"