# Workflow Schema v1

Membl declarative workflows live under `.membl/workflows/*.yml` (or `.yaml`). They pair familiar GitHub Actions workflow constructs with first-class Membl systems primitives: tool-native cache presets, dynamic compute sizing, automated sharding, structured test reports, and serverless gate jobs.

The authoritative JSON Schema is hosted publicly at [`https://membl.io/schemas/membl-workflow.v1.json`](/schemas/membl-workflow.v1.json).

You can configure your IDE or editor for auto-completion and validation by adding a schema header to your workflow:

```yaml
# yaml-language-server: $schema=https://membl.io/schemas/membl-workflow.v1.json
version: 1
name: CI
```

## Top-level structure

Every workflow file requires `version: 1` and a `jobs` map.

| Property      | Type                 | Required | Description                                                                             |
| ------------- | -------------------- | -------- | --------------------------------------------------------------------------------------- |
| `version`     | `1`                  | Yes      | Schema version. Must be `1`.                                                            |
| `name`        | `string`             | No       | Human-readable workflow title (1–200 characters).                                       |
| `on`          | `object`             | No       | Workflow trigger definitions (`push`, `pull_request`, `workflow_dispatch`, `schedule`). |
| `concurrency` | `object`             | No       | Workflow-level concurrency limits and cancellation policies.                            |
| `permissions` | `object` \| `string` | No       | Default security token scopes (`read-all`, `write-all`, or fine-grained map).           |
| `env`         | `object`             | No       | Environment variables available to all jobs.                                            |
| `defaults`    | `object`             | No       | Default settings for `compute`, `cache`, and `run` steps.                               |
| `jobs`        | `object`             | Yes      | Map of job identifiers to job definitions.                                              |

### Triggers (`on`)

The `on` object controls when the workflow executes:

```yaml
on:
  push:
    branches: [main]
    paths: ["apps/**", "packages/**"]
  pull_request:
    branches: [main]
  workflow_dispatch:
  schedule:
    - cron: "0 4 * * *"
```

Branch filters (`push` and `pull_request`) accept:

* `branches`: Array of branch names or patterns.
* `paths`: Array of path glob patterns.
* `types`: Array of event activity types.

### Concurrency (`concurrency`)

Control parallel execution across commits and pull requests:

```yaml
concurrency:
  policy: cancel-superseded-pr
  group: ci-${{ github.ref }}
```

* `policy`: One of `"cancel-superseded-pr"` (automatically cancel earlier runs on the same PR when a newer commit arrives), `"queue"` (queue runs sequentially), or `"none"` (allow concurrent runs).
* `group`: Optional string identifier defining the concurrency boundary.

### Permissions (`permissions`)

Enforce least privilege across your pipeline:

```yaml
# Empty least-privilege default
permissions: {}

# Or specific scopes
permissions:
  contents: read
  checks: write
  pull-requests: read
```

Valid permissions string values are `"read-all"` or `"write-all"`. Fine-grained scope objects map permissions keys (`actions`, `checks`, `contents`, `deployments`, `id-token`, `issues`, `packages`, `pull-requests`, `statuses`) to `"read"`, `"write"`, or `"none"`.

### Defaults (`defaults`)

Set fallback configuration for all jobs in the workflow:

```yaml
defaults:
  compute:
    intent: balanced
    size: auto
  cache:
    preset: [pnpm]
```

* `defaults.compute`: Default `intent`, `size`, and `timeout` applied to jobs without their own `compute` block.
* `defaults.cache`: Default cache preset configuration inherited by jobs.

## Jobs (`jobs.<job_id>`)

Job keys must match `^[A-Za-z_][\w-]*$`. Each job defines either an execution worker job or a serverless gate job.

### Job types (`type`)

* **`type: job`** (default): An execution job that runs a series of `steps` on a provisioned runner. Requires `steps`.
* **`type: gate`**: A lightweight status aggregation point that requires `needs` and executes without provisioning runner compute. Gate jobs cannot specify `steps`, `runs-on`, `compute`, `cache`, `artifacts`, `shard`, or `strategy`.

```yaml
jobs:
  lint:
    name: Lint
    steps:
      - uses: checkout
      - run: pnpm lint

  test:
    name: Test
    steps:
      - uses: checkout
      - run: pnpm test

  ci:
    name: CI / ci
    type: gate
    needs: [lint, test]
```

### Compute configuration (`compute`)

Configure runner placement, sizing, and timeout parameters:

```yaml
compute:
  intent: balanced
  size: auto
  timeout: 20
```

* `intent`: One of `"balanced"`, `"fastest"`, or `"cheapest"`.
* `size`: `"auto"` (dynamically sized according to build memory pressure) or an explicit vCPU count (`2` or `4`).
* `timeout`: Maximum job runtime in minutes (integer >= 1).

### Tool cache presets (`cache`)

Membl provides high-performance tool cache presets that attach pre-warmed, read-only block overlays directly to runners.

Array syntax is preferred for standard toolchains:

```yaml
cache: [pnpm, next]
```

Supported presets:

* JavaScript/TypeScript: `pnpm`, `npm`, `yarn`, `bun`, `next`
* Rust: `cargo` (alias: `rust`), `sccache`
* Go: `go` (expands to module and `go-build` caches)
* Python: `pip` (alias: `python`), `uv`
* Browser: `playwright`

Object form is also supported for explicit preset lists and custom paths:

```yaml
cache:
  preset: [cargo, sccache]
  scope: repo
  paths:
    - target/
```

* `preset` (or `tools`): Preset name or array of preset names.
* `scope`: Cache volume isolation. Defaults to `"repo"`.
* `paths`: Optional custom directory paths to cache.

### Sharding (`shard`)

Split large test jobs across parallel runner instances:

```yaml
shard:
  count: 4
  strategy: index
```

* `count`: Number of parallel shards (integer between 1 and 64).
* `strategy`: `"index"` (index-based shard distribution; exposes `MEMBL_SHARD` and `MEMBL_SHARDS` to the job).

### Structured reports (`reports`)

Collect test and coverage reports for pull request visualization and the project Tests view:

```yaml
reports:
  junit:
    - "test-results/**/*.xml"
  coverage:
    - "coverage/lcov.info"
```

* `junit`: Glob string or array of globs targeting JUnit XML test results.
* `coverage`: Glob string or array of globs targeting coverage reports.

### Artifacts (`artifacts`)

Pass build outputs between jobs in the same workflow run:

```yaml
artifacts:
  produce:
    - dist/**
    - coverage/
  consume:
    - dist/**
```

* `produce`: Array of glob paths uploaded by the job on completion.
* `consume`: Array of glob paths restored from upstream `needs` jobs before steps execute.

### Service containers (`services`)

Run companion service containers alongside job steps (for example PostgreSQL or Redis):

```yaml
services:
  postgres:
    image: postgres:17-alpine
    env:
      POSTGRES_PASSWORD: test
    ports:
      - "5432:5432"
```

* `image`: Container image reference (required).
* `env`: Optional environment variables for the service container.
* `ports`: Optional host-to-container port mappings.

### Other job properties

* `name`: Display title in PR status checks.
* `needs`: Upstream job identifier or array of identifiers (`needs: [lint, test]`).
* `runs-on`: Custom runner label string or array of labels.
* `timeout-minutes`: Maximum execution duration in minutes.
* `continue-on-error`: Boolean or expression.
* `environment`: String name or `{ name: string, url?: string }` deployment target.
* `strategy`: Matrix execution definition (`matrix`, `fail-fast`, `max-parallel`).
* `outputs`: Map of output keys exported by steps for downstream jobs.

Note: Native `.membl/workflows/*.yml` execution does not support arbitrary job-level `if:` expressions or third-party marketplace `uses:` actions. Keep workflows that rely on custom third-party GitHub Actions in `.github/workflows/*.yml` targeting `runs-on: membl-x64` (or `membl-arm`).

## Steps (`steps`)

Steps define the sequence of tasks executed inside a job. Native workflows support `uses: checkout` (or `actions/checkout@<sha>`) and shell `run` steps.

```yaml
steps:
  - name: Checkout source code
    uses: checkout
    with:
      fetch-depth: 1
      persist-credentials: false

  - name: Run test suite
    id: test-step
    run: pnpm test
    shell: bash
    env:
      NODE_ENV: test
    timeout-minutes: 10
```

### Builtin `uses: checkout`

Membl includes an optimized native `checkout` action (and also accepts pinned `actions/checkout@<40-char-sha>`):

```yaml
- uses: checkout
  with:
    ref: ${{ github.ref }}
    fetch-depth: 1
    persist-credentials: false
    lfs: false
    submodules: false
```

* `ref`: Branch, tag, or commit SHA to check out.
* `path`: Target directory path relative to workspace root.
* `persist-credentials`: Boolean controlling whether Git credentials remain on runner disk (defaults to `false`).
* `fetch-depth`: Number of commits to fetch (e.g. `1` for shallow checkout, `0` for full history).
* `lfs`: Boolean enabling Git Large File Storage download.
* `submodules`: Boolean enabling recursive submodule checkout.

### Shell commands (`run`)

Execute shell commands inside the job sandbox:

* `run`: Shell command script to execute.
* `shell`: Shell interpreter (`bash`, `sh`, `python`).
* `working-directory`: Directory in which to execute the command.
* `env`: Step-scoped environment variables.
* `continue-on-error`: Boolean or expression allowing subsequent steps to run on failure.
* `timeout-minutes`: Maximum duration in minutes for the step.

