use cicd/runners::CicdDispatchEngine
use cicd/naive::simpleStep
use cicd/naive::simpleStepWithInput
use process/command::|command
use process/command::|raw_commands
use std/text/compose::|format
use std/data/string_map::|map
use std/data/string_map::|entry
use std/engine/util::startup
/**
`main` treatment, used as entrypoint as defined in `Compo.toml`.
- `api_token`: service key provided to access Mélodium work distribution API;
- `work_location`: location where dispatched runners take place (default throught API, can be set to `"compose"` for local run);
- `repository_clone_url`: URL to process Git clone;
- `repository_clone_ref`: Git reference (sha or tag) to clone.
All the other parameters are present to handle integration with CI services.
*/
treatment main(const api_token: string, const work_location: string = "api", repository_clone_url: string, repository_clone_ref: string, ci_service_token: string = "", ci_service_project: string = "", ci_service_ref: string = "", ci_service_sha: string = "", ci_service_pipeline: string = "", on_github: bool = false, on_gitlab: bool = false)
// Model used to dispatch work among Mélodium engines.
model cicd: CicdDispatchEngine(api_token=api_token, location=work_location)
{
startup()
build: simpleStep[dispatcher=cicd](
name="build",
image="ubuntu:noble",
commands=|raw_commands([
"apt-get update",
"apt-get install -y git",
"git config --global url.https://.insteadOf git://",
|format("git clone --branch {repository_clone_ref} --depth 1 {repository_clone_url} project",
|map([
|entry("repository_clone_ref", repository_clone_ref),
|entry("repository_clone_url", repository_clone_url)
])
),
"sh -c \"cd project/ ; ls -l --almost-all | tee files-list.txt\"",
"mv project/files-list.txt /mnt/data/"
]),
out_file="files-list.txt"
)
test: simpleStepWithInput[dispatcher=cicd](
name="test",
image="alpine",
in_file="list.txt",
commands=[
|command("test", ["-s", "/mnt/data/list.txt"]),
|command("cat", ["/mnt/data/list.txt"])
]
)
startup.trigger -> build.trigger,data -> test.data
startup.trigger -----------------------> test.trigger
}