docs/marks.md in oak/oak
Marks
A mark is a named pointer to a commit on main, one for each thing you deploy or release, such as server-prod. A machine follows the mark: when main changes the mark's folders it runs your check, moves the mark when the check passes, and deploys the move. So the mark points at the last commit that passed and went out. What was done with the mark at each commit is the mark's log there.
Oak runs none of your code. The checks and deploys run on your machines, and the mark is how they hand a commit to each other.
Who can do what
- Everyone who can read the repository can list marks, read their history and wait on their moves, read-only API keys included.
- A mark's followers are organization agents listed on it (
--follower NAME); only the repository's writers and admins see who they are. Only followers get the repository's id with each move, and they can write the mark's logs on its moves and checks with a read-only key (never replacing a log someone else wrote). Being a follower doesn't let an agent move the mark; being on its owner group does. - A mark's owner group moves it forward (agents on the group count). A mark with no owner group can be moved by anyone who can write the repository. An API key needs the
writescope, or thereleasescope, to move one. A key with onlyreadandreleasemoves marks and writes nothing else, which suits the machine that follows one. - Whoever may move a mark forward may also pause and resume it (see Pausing).
- Moving a mark back is a rollback. That takes an organization owner or admin, or the owner group too when the mark was created with
--allow-group-rollback. - Owners and admins create, change and delete marks, in the repository's Settings → Marks or over the API, its description included. A change can name the
expected_policy_versionit was made against, and is refused when the mark changed since.
A thing that needs a person to sign off before it goes out gets an owner group of the people who sign off, and a follower with only --run: it deploys what they move the mark to.
Create, move, roll back
oak mark create web --path services/web --path libs/ui --owner-group web --follower web-deploy
oak mark move web main # main's head
oak mark move web 3f2a8b1c --note "ship the new cache"
oak mark rollback web 1d9e0c77 # an earlier commit
oak mark list
oak mark show web
oak mark moves web
A mark starts at main's head unless you pass --commit. Creating a mark deploys nothing: followers skip its first move. Commits are main, a full hash, or a unique prefix of at least seven characters. Every oak mark command takes --repo OWNER/NAME (default: the checkout's repository), --server URL and --json.
The rules a move has to pass:
- Forward only.
movegoes to the mark's commit or a later one onmain's first-parent history. A commit that isn't onmain(a branch commit) is refused. Moving to the commit the mark is already at is allowed, which is how you run a deploy again. - Rollback.
rollbackgoes to a commit before the mark's.
--root NAME makes a mark point into a root instead of main; the same rules apply along the root's history.
Folders
A mark names the folders (or files) of main it is about with --path (repeatable; oak mark paths MARK PATH... changes them later, repo admins). Whenever main's head holds something different under those paths than the mark's commit, its followers hear about it: a change. Oak decides what changed from the tree hashes of the paths, so two commits with the same files under them count as the same however far apart they are, and changes elsewhere in the repository never wake a follower. Name every folder the build reads: a change to a folder the mark doesn't list won't rebuild it. A mark without paths covers the whole repository. oak mark list --changed lists the marks whose folders hold something new at main's head.
Following a mark
oak mark follow web --repo acme/monorepo --check scripts/test.sh --run scripts/deploy.sh
oak mark follow does two jobs, one per script:
--checkruns on every change. The follower checksmain's head out into a work dir (./oak-mark-<mark>by default; a clone made the first time) and runs the check there withOAK_EVENT=change. When it exits 0, the follower moves the mark to that commit. When it fails, the mark's log at that commit says "failed (change)" with the end of the output, and the mark stays where it was. Each change runs once: a fix that lands after a break is the next change, and it goes out on its own.--rundeploys every move: the one the check just made, and anyone's move or rollback by hand. It checks the move's commit out and runs the script there. When the deploy of a move the follower made itself fails, the follower rolls the mark back to the commit it came from (which pauses it, and the rollback is deployed next), or pauses the mark if its credential may not roll back.
Give both for a thing that deploys, only --check for one that only needs the newest commit that passed (a scheduled job that reads the mark's commit), and only --run for one a person moves by hand. Moving the mark takes a credential that may move it, so a follower with --check usually runs as an organization agent on the mark's owner group, with a key that has the release scope. That key lives on the machine that follows, so the people and agents who merge never need the right to move the mark themselves.
What the follower does is the mark's log at each commit: "checking (change)", then "passed" or "failed (change)"; and for a deploy "deploying (move #12 by zach)", then "live (move #12)" or "failed (move #12)", each followed by the end of the script's output. While a script runs, the follower replaces that log every few seconds (see Steps and progress). Arguments for the --run script go after --.
It handles one event at a time. If several land while a script runs, only the newest runs next. What it handled is kept in a state file (--state-file, default <dir>.follow.json), so a restart carries on from there; a move or change that was running when the follower stopped is reported failed and not run again (move the mark again to retry a move). --once handles at most one event and exits, which suits a cron job or a test. --no-checkout runs the scripts without checking anything out. Run it as one of the mark's followers so the scripts get OAK_REPO_ID and its logs may be written with a read-only key.
The check runs with:
| Variable | What |
|---|---|
OAK_COMMIT | main's head |
OAK_EVENT | change |
OAK_MARK, OAK_MARK_PATHS | The mark, and its paths one per line |
OAK_INPUTS | A hash of what is under the paths |
OAK_REPO, OAK_REMOTE, OAK_LINE | The repository, the server, and main |
OAK_REPO_ID | The repository's numeric id (followers only) |
The deploy runs with:
| Variable | What |
|---|---|
OAK_COMMIT | The commit the mark moved to |
OAK_EVENT | move |
OAK_MARK, OAK_MOVE_ID, OAK_MOVE_KIND | The mark, the move's id, and create, forward or rollback |
OAK_REPO, OAK_REMOTE | The repository and server |
OAK_LINE | main, or ~NAME for a mark on a root |
OAK_REPO_ID | The repository's numeric id (followers only) |
Secrets stay on the machine that follows: put them in its environment, not in Oak.
Steps and progress
A script names its steps by printing a line ::step <name> (on stdout or stderr) as each one starts:
echo "::step build"; cargo build --release
echo "::step test"; cargo test
echo "::step upload"; ./upload.sh
While a check or deploy runs, the follower replaces the mark's log at the commit every five seconds or so, and at once when a step starts. Its headline says where the run is, with an estimate from the last run of the same kind that passed (the follower keeps those times in its state file):
checking 3f2a8b1c: test, 6m of ~13m
checkout 4s
build 2m 10s
test 3m 52s so far, ~7m 0s
<the last 200 lines of output>
The checkout counts as a step of its own. A script that prints no steps still gets the elapsed time and the end of its output. When the run ends the log says "passed", "failed" or "live" as above.
Watching a run
oak mark watch web # a line per step; exit 0 when it passes or goes live, 1 when it fails
oak mark watch web --log # and the script's output as it arrives
oak mark watch web --json # events as JSON lines on stderr, one document on stdout at the end
oak mark watch follows the mark's run in progress or, when none is running, waits for the next one. --timeout SECONDS gives up (exit 1). oak mark show includes the run in progress.
While a change at main's head under the mark's paths has no check running, the mark's page and oak mark watch say why: "waiting: follower offline since 14:05 UTC" when no follower has asked for work in the last 90 seconds, or "queued behind 3f2a8b1c" when the follower is busy with another commit (or waiting for a free job under --jobs). The server hears from each follower every time it waits for work and every time it writes progress, and only the repository's writers and admins see what it is doing.
Many marks on one machine
One follower can follow every mark whose name matches a pattern (* stands for any run of characters), in one request to the server however many marks match:
oak mark follow --match 'web-*' --repo acme/monorepo --check scripts/test.sh --run scripts/deploy.sh --jobs 8
Each mark gets its own work dir under --dir (./oak-marks/<MARK> by default) and its own logs, up to --jobs scripts run at once, and one failing doesn't hold up the others. A mark it starts following isn't checked or deployed until it moves or changes again.
Pausing and rolling back
To hold a mark, pause it: its followers stop getting change events until it's resumed, and moving or rolling it back by hand still works. A rollback of a mark with paths pauses it too, so the next change doesn't deploy straight over it.
oak mark pause web --note "bad cache config"
oak mark rollback web 1d9e0c77
oak mark resume web
Mark logs
What was done with a mark at a commit is the mark's log there: its follower writes them as it checks and deploys, and anyone who can write the repository can write one with oak mark log, such as a note on why a deploy was held back.
oak mark log web # the mark's logs, newest first
oak mark log web 3f2a8b1c # its log at one commit, in full
oak mark log web --body "held: waiting on the migration"
oak mark moves web # its moves, with the headline of each log
On the web
Marks show on the History tab. Each commit's line starts with its marks, in a column the same width on every line so the messages line up, each in its owner group's colour. Above the commits, Find a mark searches marks by name (a mark's exact name opens its page), the owner groups narrow the page to one group's marks (writers for marks with no group), Moved lately names the marks that moved most recently and where they are, and All marks lists every mark with where it is, the message of the commit it points at and when it moved.
A mark's page says who owns it and where it is. While its check or deploy runs, a Now line under that says what is running, on which commit, the step, the time so far and the estimate; it opens in place to the steps and the end of the output, and keeps up without a reload. While a change waits for the follower, the line says why. Then the page lists the commits it has been at, newest first, with who moved it there and when, and under each the mark's log there, opening in place to its whole text. If you may move the mark, Move takes a commit (main, a hash or a unique prefix): a later commit moves it forward, an earlier one rolls it back, under the same rules as oak mark move and oak mark rollback. A commit's page lists every mark's log there, in full.
API
| Request | What |
|---|---|
GET /api/:owner/:name/marks | Every mark, with how far behind main it is |
POST /api/:owner/:name/marks | Create one (name, commit, owner_group, followers, allow_group_rollback, paths) |
GET, PATCH, DELETE /api/:owner/:name/marks/:mark | Show, change, delete |
POST /api/:owner/:name/marks/:mark/move, …/rollback | {"commit", "note"} |
GET /api/:owner/:name/marks/:mark/moves | The moves, newest first, with the mark's log at each |
GET /api/:owner/:name/marks/:mark/logs?limit=N&before=ID | The mark's logs, newest first; commit=C for its log at one commit |
POST /api/:owner/:name/marks/:mark/logs | Write the mark's log: {"commit", "body", "url", "move_id"} |
GET /api/:owner/:name/marks/:mark/now?after=VERSION&timeout=S&log=true | The mark's run in progress (or its last): run (kind, state, commit, headline, step, steps, elapsed_seconds, estimate_seconds, with log=true the end of the output), follower (writers and admins: online, seen_at, doing), waiting (reason, text) and version. With after, it waits up to 55 seconds for something newer |
GET /api/:owner/:name/marks/:mark/follow?after=ID&timeout=S | Waits up to 55 seconds for a move newer than after; returns the newest move, and for the mark's followers the variables above. With changes=true (and since=COMMIT, the last change handled) it also answers with a change when main's head changed the mark's paths. doing (idle, running or queued, with doing_commit) says what the follower is doing |
POST /api/:owner/:name/marks/follow | The same for many marks: {"match" or "marks", "cursors": {mark: {"after", "since"}}, "skip", "changes", "timeout", "doing": {mark: {"state", "commit"}}}; returns events (one per mark with something new) and starting cursors for marks it had none for |
POST /api/:owner/:name/marks/:mark/pause, …/resume | Stop or restart change events ({"note"} on pause) |
GET /api/:owner/:name/commits/:commit/logs | Every mark's log at a commit |
Every move also sends the mark.moved webhook event, with mark, move_id, move_kind and from_commit, and every check a follower finishes sends mark.checked, with mark, result (passed or failed) and headline. The MCP server can list marks and read their moves.