Publish from CI
You can keep a game’s rules file in your own repository and publish it from your CI, the way you ship code. Everything the portal’s Publish tab does is in the Builder API, and an API key lets your pipeline call it without anyone signing in.
There’s no Arbitas command-line tool or CI plugin: a pipeline calls the API directly, as below, with curl and jq.
What you need
Section titled “What you need”- A build API key, made by an owner on the portal’s Team page; see
API keys. Store its secret in your CI’s secret store, here as
ARBITAS_API_KEY. A read key can check drafts but not save, publish or promote. - The game’s ID (
gam_…), from Copy ID on the game’s Settings tab. Here it’sARBITAS_GAME. - The rules file in your repository, here
rules/game.rules.yaml.
All requests go to https://build.arbitas.dev.
1. Get a token
Section titled “1. Get a token”Exchange the key for a token. It lasts 15 minutes, which is plenty for one run; exchange the key again if a run takes longer.
TOKEN=$(curl -sf -X POST https://build.arbitas.dev/v1/auth/key-token \ -H "Content-Type: application/json" \ -d "{\"key\": \"$ARBITAS_API_KEY\"}" | jq -r .access_token)AUTH="Authorization: Bearer $TOKEN"2. Check the rules (optional)
Section titled “2. Check the rules (optional)”validateDraft checks rules without saving them, and works with a read key, so it suits a check on every commit:
jq -Rs '{rules: .}' rules/game.rules.yaml | curl -sf -X POST "https://build.arbitas.dev/v1/games/$ARBITAS_GAME/draft/validate" \ -H "$AUTH" -H "Content-Type: application/json" -d @- > validation.jsonjq -e .valid validation.json > /dev/null || { jq .problems validation.json; exit 1; }Each problem has the path in the file it’s about, a message, and the line when it has one.
3. Save the draft
Section titled “3. Save the draft”A game has one draft, saved as numbered revisions. Saving needs the revision you’re replacing, in an If-Match
header, so two saves can’t overwrite each other: read the draft’s current revision from its ETag first.
ETAG=$(curl -sf -D - -o /dev/null "https://build.arbitas.dev/v1/games/$ARBITAS_GAME/draft" -H "$AUTH" | tr -d '\r' | awk 'tolower($1) == "etag:" {print $2}')
jq -Rs '{rules: .}' rules/game.rules.yaml | curl -sf -X PUT "https://build.arbitas.dev/v1/games/$ARBITAS_GAME/draft" \ -H "$AUTH" -H "Content-Type: application/json" -H "If-Match: $ETAG" -d @- > draft.jsonREVISION=$(jq .revision draft.json)The ETag is the revision in quotes, such as "3"; send it back as it came. A draft with problems is still saved,
and its problems come back in validation, but it can’t be published.
| Status | Code | What to do |
|---|---|---|
412 |
preconditionFailed |
Someone saved since you read the ETag. Read it again and decide whether to overwrite |
428 |
preconditionRequired |
Send If-Match |
403 |
forbidden |
The key is a read key |
409 |
gameBeingDeleted |
The game is being deleted |
The rules can be up to 2,000,000 characters.
4. Publish
Section titled “4. Publish”Publishing compiles the draft, plays seeded smoke games on the compiled engine, and makes the next version on the testing channel. Give it the revision you just saved, and optionally release notes (up to 4,000 characters):
OPERATION=$(curl -sf -X POST "https://build.arbitas.dev/v1/games/$ARBITAS_GAME/versions" \ -H "$AUTH" -H "Content-Type: application/json" \ -d "{\"revision\": $REVISION, \"releaseNotes\": \"Built from $GIT_COMMIT\"}" | jq -r .id)It answers 202 Accepted with an operation to follow. It’s refused with 409 when the revision isn’t the latest
(staleRevision), the draft has problems (draftInvalid), or another publish of the game is running
(publishInProgress).
5. Wait for it
Section titled “5. Wait for it”Poll the operation until its status is succeeded or failed; it’s queued or running until then, with a
progress from 0 to 1. Allow it several minutes before your pipeline gives up.
while :; do curl -sf "https://build.arbitas.dev/v1/operations/$OPERATION" -H "$AUTH" > operation.json case $(jq -r .status operation.json) in succeeded) break ;; failed) jq -r .error operation.json; exit 1 ;; esac sleep 5doneVERSION=$(jq -r .result operation.json) # such as /v1/games/gam_…/versions/4A failed publish says why in error: the compile error, or the smoke game that failed. It changes nothing. Tokens last
15 minutes, so a loop that may run longer should exchange the key again.
6. Promote
Section titled “6. Promote”When the version should reach players, promote it. Run this step when you’re ready, for example on a release tag or after a manual approval in your pipeline:
curl -sf -X POST "https://build.arbitas.dev$VERSION/promote" -H "$AUTH"It answers with the version, now on the live channel. Matches already running finish on the version they started
with; new matches use this one. Promoting a version that’s already live is refused with 409 alreadyLive.
getVersion (GET /v1/games/{gameId}/versions/{number}) shows a version’s channel, its rules’ hash, its smoke games,
and whether it was published by a person or a key. listVersions lists them newest first.
Good practice
Section titled “Good practice”- Use separate keys for separate pipelines, so you can revoke one without stopping the others, and give a check-only pipeline a read key.
- Playtest before you promote. Players never get a testing version, but promoting is immediate. Keep a person in the loop for promotion until you trust the pipeline.
- Don’t retry blindly. A
409or412means something changed; read the state again rather than resending.