PeaLang / Code Library / Blueprint
Production Blueprint ยท v3.1.36

Release promotion gate

Domain: Release Engineering / CI/CDCI/CDPeaLangJSON-RPC
Verified example. The code below was checked against the local PeaLang v3.1.36 parser, interpreter or async VM. It uses only syntax and built-ins present in that source tree.

Problem statement

A deployment pipeline promotes builds automatically. It must block promotion when a smoke check fails or a forbidden label is present, and it must emit a machine-readable reason that a dashboard or chat bot can explain without reading logs.

Complete code

const BLOCKED = ["breaking-change", "failed-smoke", "missing-approval"]

function gate(change) {
  if change == null {
    return error("ValueError", "missing change record", "E_CHANGE")
  }
  let checks = change["checks"] ?? []
  let failed = [c["name"] for c in checks if c["ok"] == false]
  let labels = change["labels"] ?? []
  let blockers = [x for x in BLOCKED if x in labels]
  if len(failed) > 0 or len(blockers) > 0 {
    return error("ValueError", "release gate blocked", "E_GATE", null,
                 {"failed": failed, "blockers": blockers})
  }
  return {"promote": true, "checks": len(checks)}
}

let good = gate({"labels": [], "checks": [{"name": "smoke", "ok": true}]})
print good["promote"]
let blocked = gate({"labels": ["breaking-change"], "checks": []})
print blocked["code"]
print std.json.stringify(blocked["context"])
Save as release-promotion-gate.pea

Run & verify

pea fmt --check release-promotion-gate.pea
pea check release-promotion-gate.pea
pea run release-promotion-gate.pea
Always run the formatter and static checker before execution: pea fmt --check release-promotion-gate.pea && pea check release-promotion-gate.pea, then pea run release-promotion-gate.pea (or the host command shown above for async modules).

Why & How

  1. Negative-path first. The rule rejects a missing change record with E_CHANGE before touching any fields, so malformed CI input cannot crash the gate with an index error.
  2. Null coalescing for defaults. ?? [] supplies empty defaults for missing checks and labels. That makes older CI payloads compatible without weakening the gate.
  3. Two independent blockers. Failed checks and forbidden labels are collected separately. Returning both lists in context means one CI run reveals every problem instead of forcing a fix-and-rerun cycle.
  4. Structured failure. E_GATE with a context map is consumable by Python, Java or Go callers over JSON-RPC. The error kind and code remain stable even if the UI changes.
  5. Pure policy. No command execution, network call or credential is used. The CI system supplies facts; PeaLang decides. That separation lets the same rule run locally and in the pipeline.
  6. Verification. The sample prints true for a clean change and E_GATE with blockers: ["breaking-change"] for the blocked change.