Compare commits
38 commits
Author | SHA1 | Date | |
---|---|---|---|
f1f3503c95 | |||
7f5b6ebbf9 | |||
beadc87c94 | |||
8f6b4772a2 | |||
07398c07ab | |||
8e48406c81 | |||
9b735fe556 | |||
5112abf37e | |||
ef00f4aa97 | |||
a0c36dba7c | |||
ff7c6b17d8 | |||
776421884b | |||
e6d631994e | |||
7dc9f06e47 | |||
aff3a8180a | |||
eb8fd0b651 | |||
493f50bdd0 | |||
6046ebe441 | |||
aeeb047b36 | |||
c7c0d7c7d7 | |||
c77674afa4 | |||
886fcf3673 | |||
924e44a9d9 | |||
c481b2168c | |||
a4c2272b2f | |||
44423ef2ee | |||
588bf5c6c4 | |||
f9c8cbc59e | |||
192692ec8a | |||
12f235af81 | |||
3001e6ec30 | |||
dbb27ac0ef | |||
2ddbc2d090 | |||
3f41f0c6b1 | |||
9cb23cfff1 | |||
3e494bc354 | |||
52835704bf | |||
bc1d047359 |
4 changed files with 124 additions and 31 deletions
37
readme.md
37
readme.md
|
@ -54,9 +54,10 @@ Picture it…
|
||||||
* [X] installing Git to clone
|
* [X] installing Git to clone
|
||||||
* [X] this project
|
* [X] this project
|
||||||
* [X] its parent framework
|
* [X] its parent framework
|
||||||
* [X] installing both Python
|
* [X] installing Python
|
||||||
* [X] system environment
|
* [X] system environment
|
||||||
* [X] virtual environment
|
* [X] virtual environment
|
||||||
|
* [ ] managed version
|
||||||
* [X] generating a Python module to switch context
|
* [X] generating a Python module to switch context
|
||||||
|
|
||||||
#### Python
|
#### Python
|
||||||
|
@ -95,30 +96,16 @@ Handle project workflows in a unified way:
|
||||||
* [ ] SourceHut
|
* [ ] SourceHut
|
||||||
|
|
||||||
* whatever the Operating System container
|
* whatever the Operating System container
|
||||||
* [X] Alma
|
| System | Latest | Previous |
|
||||||
* [X] 9
|
|:---------|:---------------------------|:---------------------------|
|
||||||
* [X] 8
|
| Alma | * [X] 9 | * [X] 8 |
|
||||||
* [X] Alpine
|
| Alpine | * [X] 3.20 | * [X] 3.19 |
|
||||||
* [X] 3.20
|
| Arch | * [X] 20240818 (.0.255804) | * [X] 20240101 (.0.204074) |
|
||||||
* [X] 3.19
|
| Debian | * [X] Bookworm (12) | * [ ] Bullseye (11) |
|
||||||
* [X] Arch
|
| Fedora | * [X] 40 | * [X] 39 |
|
||||||
* [X] 20240818 (.0.255804)
|
| OpenSUSE | * [ ] 15.6 | * [ ] 15.5 |
|
||||||
* [X] 20240101 (.0.204074)
|
| Rocky | * [X] 9 | * [X] 8 |
|
||||||
* [X] Debian
|
| Ubuntu | * [X] Noble (24.04) | * [ ] Jammy (22.04) |
|
||||||
* [X] Bookworm (12)
|
|
||||||
* [ ] Bullseye (11)
|
|
||||||
* [X] Fedora
|
|
||||||
* [X] 40
|
|
||||||
* [X] 39
|
|
||||||
* [ ] OpenSUSE
|
|
||||||
* [ ] 15.6
|
|
||||||
* [ ] 15.5
|
|
||||||
* [X] Rocky
|
|
||||||
* [X] 9
|
|
||||||
* [X] 8
|
|
||||||
* [X] Ubuntu
|
|
||||||
* [X] Noble (24.04)
|
|
||||||
* [ ] Jammy (22.04)
|
|
||||||
|
|
||||||
### Environment variables
|
### Environment variables
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ from rwx import fs
|
||||||
from rwx.log import stream as log
|
from rwx.log import stream as log
|
||||||
from rwx.ps import run
|
from rwx.ps import run
|
||||||
|
|
||||||
from spcd import cmd
|
from spcd import act, cmd
|
||||||
from spcd.ci import project, projects
|
from spcd.ci import project, projects
|
||||||
from spcd.shell import env
|
from spcd.shell import env
|
||||||
from spcd.util import browse, cat, split, step
|
from spcd.util import browse, cat, split, step
|
||||||
|
@ -44,6 +44,45 @@ def clone_project_branch() -> None:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def install_actions() -> None:
|
||||||
|
"""Make actions usable in workflows."""
|
||||||
|
step("Install actions")
|
||||||
|
name = "action.yaml"
|
||||||
|
root = project.root / "act"
|
||||||
|
vpy = Path(env.SPCD_PYTHON_VENV_BINARIES) / "python"
|
||||||
|
for action in ["action", "synchronize"]:
|
||||||
|
log.info(action)
|
||||||
|
directory = root / action
|
||||||
|
fs.make_directory(directory)
|
||||||
|
match action:
|
||||||
|
case "action":
|
||||||
|
inputs = """\
|
||||||
|
arg_1:
|
||||||
|
required: true
|
||||||
|
arg_2:
|
||||||
|
required: true
|
||||||
|
arg_3:
|
||||||
|
required: true
|
||||||
|
arg_4:
|
||||||
|
default: '"placeholder"'
|
||||||
|
"""
|
||||||
|
case "synchronize":
|
||||||
|
inputs = """\
|
||||||
|
source:
|
||||||
|
default: out
|
||||||
|
required: false
|
||||||
|
"""
|
||||||
|
yaml = f"""\
|
||||||
|
runs:
|
||||||
|
using: composite
|
||||||
|
steps:
|
||||||
|
- run: {vpy} -m spcd {action}
|
||||||
|
inputs:
|
||||||
|
{inputs}"""
|
||||||
|
fs.write(directory / name, yaml)
|
||||||
|
cat(directory / name)
|
||||||
|
|
||||||
|
|
||||||
def install_commands(path: Path) -> None:
|
def install_commands(path: Path) -> None:
|
||||||
"""Make commands callable in the operating system.
|
"""Make commands callable in the operating system.
|
||||||
|
|
||||||
|
@ -110,9 +149,15 @@ def main(main_file: Path) -> None:
|
||||||
path, *arguments = sys.argv
|
path, *arguments = sys.argv
|
||||||
name = Path(path).name
|
name = Path(path).name
|
||||||
if name == "__main__.py":
|
if name == "__main__.py":
|
||||||
|
if arguments:
|
||||||
|
name, *arguments = arguments
|
||||||
|
f = getattr(act, name)
|
||||||
|
f(*arguments)
|
||||||
|
else:
|
||||||
list_environment_variables()
|
list_environment_variables()
|
||||||
clone_project_branch()
|
clone_project_branch()
|
||||||
set_ssh()
|
set_ssh()
|
||||||
|
install_actions()
|
||||||
install_commands(main_file)
|
install_commands(main_file)
|
||||||
install_python_packages()
|
install_python_packages()
|
||||||
else:
|
else:
|
||||||
|
|
60
spcd/act.py
Normal file
60
spcd/act.py
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
"""Actions available for workflows."""
|
||||||
|
|
||||||
|
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}/",
|
||||||
|
)
|
|
@ -27,6 +27,7 @@ def spcd_build_project() -> None:
|
||||||
def spcd_check_project() -> None:
|
def spcd_check_project() -> None:
|
||||||
"""Check the project for anything wrong."""
|
"""Check the project for anything wrong."""
|
||||||
ps.run("ruff", "check")
|
ps.run("ruff", "check")
|
||||||
|
ps.run("ruff", "format", "--diff")
|
||||||
|
|
||||||
|
|
||||||
def spcd_synchronize(
|
def spcd_synchronize(
|
||||||
|
|
Loading…
Reference in a new issue