Compare commits
16 commits
a376f1b148
...
94e85a8f36
Author | SHA1 | Date | |
---|---|---|---|
94e85a8f36 | |||
e9e3779018 | |||
7dd1dc6dcf | |||
f54c9d598b | |||
dddad18357 | |||
ba59b1618f | |||
b41478a747 | |||
57a171ae0d | |||
6619f791ea | |||
247f15586e | |||
29c701b3d5 | |||
42166a2c4e | |||
87b39b4486 | |||
2576b0eba1 | |||
bf7da671dc | |||
e55a7f3ba1 |
6 changed files with 34 additions and 2 deletions
|
@ -19,6 +19,7 @@ COMMANDS_PREFIX = "spcd-"
|
|||
|
||||
|
||||
def clone_project_branch() -> None:
|
||||
"""Clone project on triggering branch into the current workspace."""
|
||||
if not projects.environment.get("GITLAB_CI"):
|
||||
step("Clone project branch")
|
||||
log.info(projects)
|
||||
|
@ -41,6 +42,7 @@ def clone_project_branch() -> None:
|
|||
|
||||
|
||||
def install_commands(path: str) -> None:
|
||||
"""Make commands callable in the operating system."""
|
||||
step("Install commands")
|
||||
user = Path("/usr/local/bin")
|
||||
for command in [
|
||||
|
@ -54,11 +56,13 @@ def install_commands(path: str) -> None:
|
|||
|
||||
|
||||
def install_python_packages() -> None:
|
||||
"""Upgrade pip then install extra Python packages."""
|
||||
step("Install Python packages")
|
||||
log.info("pip")
|
||||
run("pip", "install", "--upgrade", "pip")
|
||||
split()
|
||||
packages = [
|
||||
"hatch",
|
||||
"mypy",
|
||||
"pelican",
|
||||
"pytest",
|
||||
|
@ -73,6 +77,7 @@ def install_python_packages() -> None:
|
|||
|
||||
|
||||
def list_environment_variables() -> None:
|
||||
"""List accessible variables and their public contents."""
|
||||
step("List environment variables")
|
||||
for variable, value in sorted(projects.environment.items()):
|
||||
if variable not in ["SPCD", "SPCD_SSH_KEY"]:
|
||||
|
@ -82,6 +87,7 @@ def list_environment_variables() -> None:
|
|||
|
||||
|
||||
def main(main: str) -> None:
|
||||
"""Entry point to initialize environment or run a specific command."""
|
||||
paths = environ["PATH"].split(pathsep)
|
||||
if env.SPCD_PYTHON_VENV_BINARIES not in paths:
|
||||
environ["PATH"] = pathsep.join([env.SPCD_PYTHON_VENV_BINARIES, *paths])
|
||||
|
@ -99,6 +105,7 @@ def main(main: str) -> None:
|
|||
|
||||
|
||||
def set_ssh() -> None:
|
||||
"""Set things up to enable access to targets through SSH."""
|
||||
step("Set SSH")
|
||||
# get variables
|
||||
ssh_hosts = projects.environment.get("SPCD_SSH_HOSTS")
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
"""Continuous Integration."""
|
||||
|
||||
from spcd.project import Project
|
||||
from spcd.projects import Projects
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
"""Commands available for workflows."""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
@ -9,10 +11,12 @@ from spcd.util import browse
|
|||
|
||||
|
||||
def spcd_browse_workspace() -> None:
|
||||
"""Browse the current workspace for the project."""
|
||||
browse(project.root)
|
||||
|
||||
|
||||
def spcd_build_project() -> None:
|
||||
"""Perform the actual building process."""
|
||||
for extension in ["py", "sh"]:
|
||||
path = Path(project.root) / f"build.{extension}"
|
||||
if path.exists():
|
||||
|
@ -23,12 +27,14 @@ def spcd_build_project() -> None:
|
|||
|
||||
|
||||
def spcd_check_project() -> None:
|
||||
"""Check the project for anything wrong."""
|
||||
ps.run("ruff", "check")
|
||||
|
||||
|
||||
def spcd_synchronize(
|
||||
target: str | None = None, source: str | None = None
|
||||
) -> None:
|
||||
"""Synchronize output towards a target."""
|
||||
if not target:
|
||||
user = "cd"
|
||||
host = env.SPCD_PROJECT_PATH
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
"""CI project."""
|
||||
"""Continuous Integration project."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
@ -25,7 +25,10 @@ ROOT = [
|
|||
|
||||
|
||||
class Project:
|
||||
"""Current project."""
|
||||
|
||||
def __init__(self: Project, projects: Projects) -> None:
|
||||
"""Set projects, branch, name, root & url."""
|
||||
self.projects = projects
|
||||
# branch
|
||||
for variable in BRANCH:
|
||||
|
@ -43,6 +46,7 @@ class Project:
|
|||
self.url = add_url_path(projects.url, self.name)
|
||||
|
||||
def __str__(self: Project) -> str:
|
||||
"""List branch, name, root & url."""
|
||||
return f"""\
|
||||
branch = {self.branch}
|
||||
name = {self.name}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
"""CI projects."""
|
||||
"""Continuous Integration projects."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
@ -18,7 +18,10 @@ SERVER_URL = [
|
|||
|
||||
|
||||
class Projects:
|
||||
"""Other projects."""
|
||||
|
||||
def __init__(self: Projects) -> None:
|
||||
"""Set environment, group, name & url."""
|
||||
self.environment = os.environ
|
||||
# group, name
|
||||
for variable in GROUP_AND_NAME:
|
||||
|
@ -32,6 +35,7 @@ class Projects:
|
|||
self.url = add_url_path(value, self.group)
|
||||
|
||||
def __str__(self: Projects) -> str:
|
||||
"""List group, name & url."""
|
||||
return f"""\
|
||||
group = {self.group}
|
||||
name = {self.name}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
"""Basic utilities."""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlparse, urlunparse
|
||||
|
@ -8,12 +10,14 @@ from rwx.log import stream as log
|
|||
|
||||
|
||||
def add_url_path(url: str, extra_path: str) -> str:
|
||||
"""Append an extra segment to an existing URL."""
|
||||
parts = urlparse(url)
|
||||
parts = parts._replace(path=str(Path(parts.path) / extra_path))
|
||||
return urlunparse(parts)
|
||||
|
||||
|
||||
def browse(root: str) -> None:
|
||||
"""Frame the browsing of a root directory in the log output."""
|
||||
paths = []
|
||||
for directory, _, files in os.walk(root):
|
||||
for file in files:
|
||||
|
@ -27,24 +31,29 @@ def browse(root: str) -> None:
|
|||
|
||||
|
||||
def cat(file: str) -> None:
|
||||
"""Frame the content of a file in the log output."""
|
||||
frame(file)
|
||||
log.info(fs.read_file_text(file).rstrip())
|
||||
shut(file)
|
||||
|
||||
|
||||
def frame(text: str) -> None:
|
||||
"""Open a new frame in the log output."""
|
||||
log.info(f"{env.SPCD_OPEN}{text}")
|
||||
|
||||
|
||||
def shut(text: str) -> None:
|
||||
"""Close current frame in the log output."""
|
||||
log.info(f"{env.SPCD_SHUT}{text}")
|
||||
|
||||
|
||||
def split() -> None:
|
||||
"""Separate previous log outputs from the ones following."""
|
||||
log.info(env.SPCD_SPLT)
|
||||
|
||||
|
||||
def step(text: str) -> None:
|
||||
"""Increment the step number of the current build process."""
|
||||
env.SPCD_STEP += 1
|
||||
log.info(env.SPCD_DOWN)
|
||||
log.info(f"{env.SPCD_VERT} {env.SPCD_STEP} {text}")
|
||||
|
|
Loading…
Reference in a new issue