[!NOTE] Implemented (issue #135). The user documentation is in watch repositories.
Status: implemented (#135). The user guide is docs/connect/watch-repositories.md.
When code is merged into a watched branch on GitHub, Saci runs the related test plans without a person. Two constraints apply:
A new command, saci watch, runs on the Saci host as a long-running
process. It does not change the backend: it is a client of the REST API,
like saci run.
flowchart LR
gh["GitHub repositories"]
subgraph host["Saci host"]
watch["saci watch"]
clones[("Local clones<br/>and state file")]
backend["saci-backend"]
worker["saci-worker"]
end
watch -- "git ls-remote (poll)" --> gh
watch -- "git fetch, checkout" --> clones
watch -- "POST /api/v1/runs, GET run" --> backend
backend -- launch --> worker
One cycle:
git ls-remote for the
branch of each repository and compares the commit with the last
commit that it saw.quiet_period_secs. Related merges
in several repositories thus give one cycle.The plan states the versions that it tests, for example the image tags or
the commands that build or deploy the system under test. The watcher does
not build, deploy or give versions to the run. It only decides when to
run and gives the newest plans to the backend. A plan that tests the
newest code of a branch says so itself, for example with a main image
tag or a clone of the branch in the worker.
Thus the backend, the worker and the plan format do not change.
The watcher can also start a local backend when none answers (#141). Then one service runs both. See starting the backend.
The watcher uses git ls-remote <url> refs/heads/<branch>, not the GitHub
REST API:
git already uses on the host (SSH agent or
credential helper).The cost is one small request for each repository at each interval. The default interval is 60 seconds.
Rejected alternatives:
The watcher owns its clones in <workdir>/repos/<name>. It creates a
clone when it is missing. To update a clone, it runs git fetch and
git checkout --force --detach <commit>, then git clean -ffdx. Local
changes in a clone are lost. Do not edit the clones by hand.
Clones that the watcher owns give a known state for each cycle. A person’s working copy can have local changes, another branch or build output, and the watcher must not change it.
The clones are for the plans only. Workers mount no host directories (launchers).
The configuration has one list of repositories and one list of triggers. A trigger names the repositories that start it and the plans that it runs. A repository that only supplies plans, for example the test repository, is in the snapshot but does not need to start a trigger.
backend:
url: http://127.0.0.1:18080 # default: --backend or SACI_BACKEND_URL
token: { env: SACI_TOKEN } # optional
workdir: ~/.local/state/saci-watch # clones and the state file
poll_interval_secs: 60
quiet_period_secs: 180
repositories:
- name: wanaku
url: https://github.com/wanaku-ai/wanaku.git
branch: main
- name: wanaku-operator
url: https://github.com/wanaku-ai/wanaku-operator.git
branch: main
- name: wanaku-tests
url: git@github.com:wanaku-ai/wanaku-tests.git
branch: main
triggers:
- name: operator
on: [wanaku, wanaku-operator, wanaku-tests]
plans:
- plan: wanaku-tests/plans/operator-basic-functionality.md
environment: openshift
policy: keep-going
- plan: wanaku-tests/plans/operator-upgrade.md
environment: openshift
on lists the repositories whose changes start the trigger. A change
in a repository that no trigger names is ignored.plan is a path in the clones: the repository name, then the path in
that repository.Test plans of one project often use one shared system under test, for example one OpenShift namespace. Two cycles at the same time can break each other. Thus:
GET /api/v1/runs/{id} until the run
ends. A failed plan does not stop the next plans of the cycle.The watcher keeps its state in <workdir>/state.json: the last snapshot
that it saw, the last snapshot that it tested for each trigger with its
run IDs, and the run that it waits for. It writes the file to a temporary
file and renames it, so a crash cannot leave a partial file.
--run-now starts a cycle at once.Idempotency-Key of each submission is
watch:<trigger>:<snapshot hash>:<plan index>. When the watcher
submits a run again after a lost reply or a crash, the backend returns
the run that it already accepted.saci watch --config watch.yaml [--once] [--run-now]
saci watch status --config watch.yaml
saci watch polls until it is stopped. On SIGINT or SIGTERM it stops
after the current request. It does not cancel a running test run. On
SIGHUP it polls at once, and the changes found start a cycle without
the quiet period (#177).--once polls one time, runs a cycle when a change is found, and exits.
This is for tests and for hosts that use cron or a systemd timer.saci watch status shows the snapshot, the last cycle of each trigger
with its commits, runs and outcomes, and the run that the watcher waits
for.The user guide gives a systemd user unit and a launchd agent to start the watcher with the host.
saci watch is a module of saci-cli. The CLI already has the REST
client, the plan bundle loader and the backend settings. The watcher uses
the git program, as investigations do, and no Git library.
The watcher does not send notifications. The backend’s outcome actions already report run results, for example by email.
git with argument
lists, never through a shell.git clean -ffdx removes files in the clones only. The watcher refuses
a workdir that is a Git working tree or the home directory.git ls-remote polling, the quiet
period, the clones and the snapshot, the state file, submission with
idempotency keys, waiting for runs, --once, --run-now and
saci watch status. Tests use local bare repositories (file://
URLs) and the saci-testkit backend fixtures.docs/connect/watch-repositories.md, the command in
docs/reference/cli.md, an example configuration for a project in several
repositories in examples/, and the systemd and launchd units.Ticket 2 depends on 1.