From 2684a21ab06654a279760b489118b36e4221cc93 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 3 May 2026 03:16:13 +0000 Subject: [PATCH 1/2] Add remote-state matrix CI docs example Agent-Logs-Url: https://github.com/sourceplane/stack-tectonic/sessions/de4f3bb4-b032-477a-8e0b-a4d2aa94f3d5 Co-authored-by: ruehowl <22807272+ruehowl@users.noreply.github.com> --- README.md | 1 + docs/remote-state-matrix-ci.md | 172 ++++++++++++++++++++++++++++++ docs/using-this-stack-from-oci.md | 4 + 3 files changed, 177 insertions(+) create mode 100644 docs/remote-state-matrix-ci.md diff --git a/README.md b/README.md index dfb63f8..e6d32be 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ Every composition now lives under `compositions//` so docs, examples, test - [Authoring guide](docs/authoring.md) - [Verification model](docs/verification.md) - [Production deploys](docs/production-deploys.md) +- [Remote-state matrix CI](docs/remote-state-matrix-ci.md) - [Roadmap](docs/roadmap.md) - [Using this stack from OCI](docs/using-this-stack-from-oci.md) diff --git a/docs/remote-state-matrix-ci.md b/docs/remote-state-matrix-ci.md new file mode 100644 index 0000000..b5e3fc0 --- /dev/null +++ b/docs/remote-state-matrix-ci.md @@ -0,0 +1,172 @@ +# Remote-state matrix CI + +This example shows how a consumer repository can compile one `orun` plan and fan it out across a GitHub Actions matrix while using remote state for coordination. + +It is adapted from the upstream `sourceplane/orun` remote-state examples: + +- `examples/github-actions/remote-state-matrix.yml` +- `examples/remote-state-matrix/README.md` + +## Required repository configuration + +Set these GitHub Actions repository variables before enabling the workflow: + +| Setting | Location | Value | +| --- | --- | --- | +| `ORUN_BACKEND_URL` | Settings → Variables → Actions | URL of your `orun-backend` instance | + +The workflow also needs: + +- `contents: read` +- `id-token: write` + +`id-token: write` is required because the remote-state backend authenticates GitHub Actions runners with OIDC. + +## Consumer repo assumptions + +This workflow assumes the consumer repository: + +1. Pins `orun` in `kiox.yaml` +2. Pins this catalog in `intent.yaml` +3. Keeps `component.yaml` files in the repo roots discovered by the intent + +If you want remote state declared in the intent, use the same `execution.state` shape shown in the upstream `sourceplane/orun` examples. + +## Example workflow + +```yaml +name: remote-state-matrix + +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + +permissions: + contents: read + id-token: write + +jobs: + plan: + name: Compile plan + runs-on: ubuntu-latest + outputs: + plan_id: ${{ steps.plan.outputs.plan_id }} + run_id: ${{ steps.plan.outputs.run_id }} + jobs: ${{ steps.matrix.outputs.jobs }} + first_job: ${{ steps.matrix.outputs.first_job }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: sourceplane/kiox-action@v2.1.2 + + - name: Compile plan + id: plan + run: | + kiox -- orun validate --intent intent.yaml + kiox -- orun plan --intent intent.yaml --name remote-state-stack --all + plan_id="$(kiox -- orun get plans -o json | jq -r '.[] | select(.Name == "remote-state-stack") | .Checksum')" + run_id="gha-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}-${plan_id}" + echo "plan_id=${plan_id}" >> "${GITHUB_OUTPUT}" + echo "run_id=${run_id}" >> "${GITHUB_OUTPUT}" + + - name: Build job matrix + id: matrix + run: | + jobs="$(kiox -- orun get jobs --plan '${{ steps.plan.outputs.plan_id }}' --all -o json \ + | jq -c '[.[] | {job: .id, env: .environment, component: .component}]')" + first_job="$(printf '%s' "${jobs}" | jq -r '.[0].job')" + echo "jobs=${jobs}" >> "${GITHUB_OUTPUT}" + echo "first_job=${first_job}" >> "${GITHUB_OUTPUT}" + + - name: Upload compiled plan + uses: actions/upload-artifact@v4 + with: + name: orun-plan + path: .orun/plans/ + if-no-files-found: error + + run-one-job-per-runner: + name: "Run: ${{ matrix.job }}" + needs: plan + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: ${{ fromJson(needs.plan.outputs.jobs) }} + env: + ORUN_BACKEND_URL: ${{ vars.ORUN_BACKEND_URL }} + ORUN_REMOTE_STATE: "true" + ORUN_EXEC_ID: ${{ needs.plan.outputs.run_id }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: sourceplane/kiox-action@v2.1.2 + + - name: Download compiled plan + uses: actions/download-artifact@v4 + with: + name: orun-plan + path: .orun/plans/ + + - name: Run selected job through remote state + run: | + kiox -- orun run '${{ needs.plan.outputs.plan_id }}' \ + --job '${{ matrix.job }}' \ + --remote-state \ + --backend-url "${ORUN_BACKEND_URL}" \ + --gha \ + --verbose + + verify: + name: Verify remote status and logs + needs: [plan, run-one-job-per-runner] + if: always() + runs-on: ubuntu-latest + env: + ORUN_BACKEND_URL: ${{ vars.ORUN_BACKEND_URL }} + ORUN_REMOTE_STATE: "true" + ORUN_EXEC_ID: ${{ needs.plan.outputs.run_id }} + steps: + - uses: actions/checkout@v4 + + - uses: sourceplane/kiox-action@v2.1.2 + + - name: Download compiled plan + uses: actions/download-artifact@v4 + with: + name: orun-plan + path: .orun/plans/ + + - name: Verify remote status + run: | + kiox -- orun status \ + --remote-state \ + --backend-url "${ORUN_BACKEND_URL}" \ + --exec-id "${ORUN_EXEC_ID}" \ + --json + + - name: Verify remote logs + run: | + kiox -- orun logs \ + --remote-state \ + --backend-url "${ORUN_BACKEND_URL}" \ + --exec-id "${ORUN_EXEC_ID}" \ + --job '${{ needs.plan.outputs.first_job }}' +``` + +## What this pattern gives you + +- One plan compiled once per workflow run +- A deterministic execution ID shared by every matrix runner +- Remote job claiming so two runners do not execute the same job +- Dependency-aware fan-out, where downstream jobs wait until upstream jobs complete +- Post-run inspection through `orun status --remote-state` and `orun logs --remote-state` + +For small production repos, this can also replace a single serial `orun run` step in the deployment workflow described in [production-deploys.md](production-deploys.md). diff --git a/docs/using-this-stack-from-oci.md b/docs/using-this-stack-from-oci.md index 2b9c128..5b7b24b 100644 --- a/docs/using-this-stack-from-oci.md +++ b/docs/using-this-stack-from-oci.md @@ -110,6 +110,10 @@ The component stays repo-local. Only the execution contract for `cloudflare-page 3. Run `orun validate` and `orun plan`. 4. Promote the catalog upgrade through environments like any other platform change. +## GitHub Actions matrix example + +For a copyable consumer workflow that compiles a single plan and runs it through a remote-state matrix in GitHub Actions, see [remote-state-matrix-ci.md](remote-state-matrix-ci.md). + ## Why this repo now uses a catalog structure The old flat layout worked for a small prototype, but it would become noisy as the stack grows. The current layout separates: From 9af0880116edc450ad1df0afe352a4120905219d Mon Sep 17 00:00:00 2001 From: Rahul Varghese Date: Sun, 3 May 2026 14:42:30 +0530 Subject: [PATCH 2/2] Harden remote-state matrix docs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- README.md | 6 +- docs/remote-state-matrix-ci.md | 126 +++++++++++++++++++++++------- docs/using-this-stack-from-oci.md | 12 ++- kiox.lock | 8 +- kiox.yaml | 2 +- 5 files changed, 113 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index e6d32be..dbc0381 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,10 @@ compositions: sources: - name: stack-tectonic kind: oci - ref: oci://ghcr.io/sourceplane/stack-tectonic:0.11.0 + ref: oci://ghcr.io/sourceplane/stack-tectonic:0.12.0 ``` -Keep the `orun` runtime pinned separately in `kiox.yaml`, then plan or run against that intent. The full consumer workflow is in [docs/using-this-stack-from-oci.md](docs/using-this-stack-from-oci.md). +Keep the `orun` runtime pinned separately in `kiox.yaml`, then plan or run against that intent. The full consumer workflow is in [docs/using-this-stack-from-oci.md](docs/using-this-stack-from-oci.md), and the opt-in remote-state matrix pattern is documented in [docs/remote-state-matrix-ci.md](docs/remote-state-matrix-ci.md). ## Catalog layout @@ -84,6 +84,6 @@ Every composition now lives under `compositions//` so docs, examples, test 1. Update `stack.yaml`. 2. Run `./scripts/verify.sh`. 3. Merge to `main`. -4. Push a matching tag like `v0.11.0`. +4. Push a matching tag like `v0.12.0`. The release workflow publishes the OCI package, creates the GitHub release, and uploads the generated registry index. diff --git a/docs/remote-state-matrix-ci.md b/docs/remote-state-matrix-ci.md index b5e3fc0..c102bfe 100644 --- a/docs/remote-state-matrix-ci.md +++ b/docs/remote-state-matrix-ci.md @@ -1,11 +1,14 @@ # Remote-state matrix CI -This example shows how a consumer repository can compile one `orun` plan and fan it out across a GitHub Actions matrix while using remote state for coordination. +This guide shows an **opt-in advanced** GitHub Actions pattern for consumer repositories that need backend-coordinated matrix execution. It compiles one `orun` plan, uploads `.orun/plans/`, fans jobs out across a matrix, and verifies the shared remote state afterward. -It is adapted from the upstream `sourceplane/orun` remote-state examples: +It is adapted from the upstream `sourceplane/orun` remote-state references: - `examples/github-actions/remote-state-matrix.yml` - `examples/remote-state-matrix/README.md` +- `.github/workflows/remote-state-conformance.yml` + +Do **not** make this your default pull-request lane just because the workflow exists. Keep it in a dedicated workflow and enable it only when the repository already has a real `orun-backend`, OIDC configured, and a reason to distribute execution across runners. ## Required repository configuration @@ -13,36 +16,56 @@ Set these GitHub Actions repository variables before enabling the workflow: | Setting | Location | Value | | --- | --- | --- | -| `ORUN_BACKEND_URL` | Settings → Variables → Actions | URL of your `orun-backend` instance | +| `ORUN_BACKEND_URL` | Settings -> Variables -> Actions | URL of your `orun-backend` instance | +| `REMOTE_STATE_MATRIX_CI` | Settings -> Variables -> Actions | Optional `true` switch if you later decide to auto-run this workflow on push or PR | -The workflow also needs: +The workflow permissions must include: -- `contents: read` -- `id-token: write` +```yaml +permissions: + contents: read + id-token: write +``` -`id-token: write` is required because the remote-state backend authenticates GitHub Actions runners with OIDC. +`id-token: write` is mandatory because current Orun remote-state flows authenticate GitHub Actions runners with OIDC. Do not hard-code backend URLs, tokens, Cloudflare credentials, or production-only settings in the workflow file. ## Consumer repo assumptions -This workflow assumes the consumer repository: +This pattern assumes the consumer repository pins the runtime and stack separately: + +### `kiox.yaml` + +```yaml +apiVersion: kiox.io/v1 +kind: Workspace +metadata: + name: my-platform +providers: + orun: + source: ghcr.io/sourceplane/orun:v1.12.0 +``` + +### `intent.yaml` + +```yaml +compositions: + sources: + - name: stack-tectonic + kind: oci + ref: oci://ghcr.io/sourceplane/stack-tectonic:0.12.0 +``` -1. Pins `orun` in `kiox.yaml` -2. Pins this catalog in `intent.yaml` -3. Keeps `component.yaml` files in the repo roots discovered by the intent +This guide keeps remote state opt-in at the workflow layer by passing `--remote-state` and `--backend-url` explicitly. That keeps normal local `orun validate`, `orun plan`, and `orun run` behavior local unless you intentionally opt into backend-backed execution. -If you want remote state declared in the intent, use the same `execution.state` shape shown in the upstream `sourceplane/orun` examples. +## Copyable workflow -## Example workflow +Start with a dedicated manual workflow. If you later want push or pull-request automation, add those triggers behind a repo-level gate such as `vars.REMOTE_STATE_MATRIX_CI == 'true'`. ```yaml name: remote-state-matrix on: workflow_dispatch: - pull_request: - push: - branches: - - main permissions: contents: read @@ -100,7 +123,6 @@ jobs: include: ${{ fromJson(needs.plan.outputs.jobs) }} env: ORUN_BACKEND_URL: ${{ vars.ORUN_BACKEND_URL }} - ORUN_REMOTE_STATE: "true" ORUN_EXEC_ID: ${{ needs.plan.outputs.run_id }} steps: - uses: actions/checkout@v4 @@ -121,6 +143,7 @@ jobs: --job '${{ matrix.job }}' \ --remote-state \ --backend-url "${ORUN_BACKEND_URL}" \ + --exec-id "${ORUN_EXEC_ID}" \ --gha \ --verbose @@ -131,7 +154,6 @@ jobs: runs-on: ubuntu-latest env: ORUN_BACKEND_URL: ${{ vars.ORUN_BACKEND_URL }} - ORUN_REMOTE_STATE: "true" ORUN_EXEC_ID: ${{ needs.plan.outputs.run_id }} steps: - uses: actions/checkout@v4 @@ -144,29 +166,73 @@ jobs: name: orun-plan path: .orun/plans/ - - name: Verify remote status + - name: Capture remote status + id: status run: | - kiox -- orun status \ + status_json="$(kiox -- orun status \ --remote-state \ --backend-url "${ORUN_BACKEND_URL}" \ --exec-id "${ORUN_EXEC_ID}" \ - --json - - - name: Verify remote logs + --json)" + echo "${status_json}" | jq . + { + echo 'status_json<> "${GITHUB_OUTPUT}" + + - name: Capture remote logs run: | kiox -- orun logs \ --remote-state \ --backend-url "${ORUN_BACKEND_URL}" \ --exec-id "${ORUN_EXEC_ID}" \ --job '${{ needs.plan.outputs.first_job }}' + + - name: Fail if remote state reports failed or incomplete jobs + env: + STATUS_JSON: ${{ steps.status.outputs.status_json }} + run: | + failed="$(printf '%s' "${STATUS_JSON}" | jq '(.state.jobs // {}) | to_entries | map(select(.value.status == "failed")) | length')" + incomplete="$(printf '%s' "${STATUS_JSON}" | jq '(.state.jobs // {}) | to_entries | map(select(.value.status != "completed")) | length')" + total="$(printf '%s' "${STATUS_JSON}" | jq '(.state.jobs // {}) | to_entries | length')" + completed="$(printf '%s' "${STATUS_JSON}" | jq '(.state.jobs // {}) | to_entries | map(select(.value.status == "completed")) | length')" + + if [ "${failed}" -gt 0 ]; then + echo "::error::${failed} remote-state job(s) failed" + exit 1 + fi + + if [ "${incomplete}" -gt 0 ]; then + echo "::error::${incomplete} remote-state job(s) did not reach completed status" + exit 1 + fi + + echo "Remote state verification: ${completed}/${total} jobs completed successfully." ``` +## Optional guarded automatic trigger + +If this workflow becomes a useful recurring lane, add `push` and `pull_request` triggers and gate the `plan` job instead of running it for every PR by default: + +```yaml +if: github.event_name == 'workflow_dispatch' || vars.REMOTE_STATE_MATRIX_CI == 'true' +``` + +That keeps remote-state matrix CI intentionally enabled instead of silently becoming a default branch or PR requirement. + ## What this pattern gives you -- One plan compiled once per workflow run -- A deterministic execution ID shared by every matrix runner -- Remote job claiming so two runners do not execute the same job -- Dependency-aware fan-out, where downstream jobs wait until upstream jobs complete -- Post-run inspection through `orun status --remote-state` and `orun logs --remote-state` +- one plan compiled once per workflow run +- `.orun/plans/` shared to matrix runners instead of recompiling +- a deterministic `ORUN_EXEC_ID` shared by every runner +- remote job claiming so two runners do not execute the same job +- dependency-aware fan-out where downstream jobs wait until upstream jobs complete +- explicit post-run `orun status --remote-state` and `orun logs --remote-state` inspection +- a hard workflow failure when remote state reports failed or incomplete jobs + +## What this guide intentionally omits + +The upstream Orun examples also cover duplicate-claim and environment-fanout conformance cases. Those are intentionally omitted here because Stack Tectonic consumer guidance should stay focused on the smallest copyable workflow that proves one-plan matrix coordination. -For small production repos, this can also replace a single serial `orun run` step in the deployment workflow described in [production-deploys.md](production-deploys.md). +If you are validating backend semantics rather than adopting the pattern in an application repo, start from the upstream Orun examples instead of this simplified consumer guide. diff --git a/docs/using-this-stack-from-oci.md b/docs/using-this-stack-from-oci.md index 5b7b24b..e9fbdd9 100644 --- a/docs/using-this-stack-from-oci.md +++ b/docs/using-this-stack-from-oci.md @@ -47,7 +47,7 @@ compositions: sources: - name: stack-tectonic kind: oci - ref: oci://ghcr.io/sourceplane/stack-tectonic:0.11.0 + ref: oci://ghcr.io/sourceplane/stack-tectonic:0.12.0 discovery: roots: @@ -63,11 +63,17 @@ environments: The important line is the OCI source: ```yaml -ref: oci://ghcr.io/sourceplane/stack-tectonic:0.11.0 +ref: oci://ghcr.io/sourceplane/stack-tectonic:0.12.0 ``` Pin a released version instead of `latest` so plans stay reproducible. +## Keep remote state opt-in + +Most consumer repositories should keep their default local `orun` workflow simple: validate, plan, and run without remote coordination unless they explicitly need matrix-safe distributed runners. + +When you do need backend-backed execution, keep it in a dedicated GitHub Actions workflow instead of baking remote state into every default repo run. The copyable advanced example is in [remote-state-matrix-ci.md](remote-state-matrix-ci.md). + ## Local component ownership The consuming repository should keep `component.yaml` files next to the code or infrastructure they own. @@ -112,7 +118,7 @@ The component stays repo-local. Only the execution contract for `cloudflare-page ## GitHub Actions matrix example -For a copyable consumer workflow that compiles a single plan and runs it through a remote-state matrix in GitHub Actions, see [remote-state-matrix-ci.md](remote-state-matrix-ci.md). +For an opt-in consumer workflow that compiles a single plan and runs it through a remote-state matrix in GitHub Actions, see [remote-state-matrix-ci.md](remote-state-matrix-ci.md). ## Why this repo now uses a catalog structure diff --git a/kiox.lock b/kiox.lock index 86d7626..af27eaa 100644 --- a/kiox.lock +++ b/kiox.lock @@ -5,7 +5,7 @@ metadata: providers: - alias: orun provider: sourceplane/orun - source: ghcr.io/sourceplane/orun:v0.9.6 - version: v0.9.6 - resolved: ghcr.io/sourceplane/orun@sha256:c259e8c8f2ebacbe68a7eccbbb52fe29e5caa7a502243ef4cc6146664896e1a6 - store: c99e023eb0799af3ad9bb3abbb796af41b9c3895b713585276567b3d29486189 + source: ghcr.io/sourceplane/orun:v1.12.0 + version: v1.12.0 + resolved: ghcr.io/sourceplane/orun@sha256:d27e781c68e531542a1968f524bdcf0471b9777f05e098f151bb02d06ba79f33 + store: 994e4dd192cd8303e300f15146bf67d44c44df7a3befde5f07656a5695d2e961 diff --git a/kiox.yaml b/kiox.yaml index 1493c1a..55321ac 100644 --- a/kiox.yaml +++ b/kiox.yaml @@ -4,4 +4,4 @@ metadata: name: stack-tectonic providers: orun: - source: ghcr.io/sourceplane/orun:v0.9.6 + source: ghcr.io/sourceplane/orun:v1.12.0