Result: a pull request that shows what an apply would change, an apply on merge, and a scheduled check that tells you when someone edited the workspace in Sim.
Credentials
Saving and dry-running source act as a person. Use a personal API key (Settings → Sim API keys, passed as SIM_API_KEY) or an OAuth login. A workspace API key is refused with 403 for workflows, and for a workspace directory it can apply only the kinds it can write; see Workspace API keys. Set SIM_WORKSPACE unless you pass --workspace, and SIM_ENDPOINT if you use a self-hosted Sim. See Authenticating CI.
What to commit
- A workflow directory: commit
workflow.ts,functions/,.sim/lock.json,.sim/base.json,.sim/written.json,.sim/stored-edges.json,tsconfig.jsonand.gitattributes. CI finds the workflow fromworkflowIdin.sim/base.json, andstatusandgetuse.sim/written.jsonto tell your edits apart from what the CLI last wrote. Gitignoretsconfig.full.json;.sim/sdk/is optional. - A workspace directory: commit everything, including
.sim/. Its generated.gitignoreleaves out only temporary files.
Directory layout lists every file.
One workflow
Run sim workflows source apply --dir <dir> --dry on pull requests. It exits 0 when the workflow is valid, 1 when it has errors, and 5 when the workflow was changed in the workflow builder after you committed the directory, so a failing check blocks the merge. check is not needed: the dry run runs every check a save runs, and check fails on a fresh runner that has no cached block catalog.
A workspace
Keep a workspace directory in a repository, .sim/ included, and let CI plan each pull request and apply each merge. The dry run exits 1 on errors, 5 when the workspace changed since the committed base, and 15 when the apply would hold back changes that use a secret with no value or a credential nothing binds to. check downloads the block catalog once on a fresh runner. On GitHub Actions (GITHUB_ACTIONS=true), every source command also annotates each error and warning at its file and line, so they show inline on the pull request, and an apply (a dry run too), create and status append the plan and errors to the job's step summary. --summary-file <path> (or SIM_SUMMARY_FILE) also writes the same Markdown to a file on any CI, replacing it each run.
check runs first because it is fast and, after a one-time catalog download, needs no server: it compiles every workflow and type-checks the directory after regenerating .sim/sdk/workspace.d.ts, so resources the pull request adds are typed. Each finding is also a GitHub annotation at its line. Apply rewrites files under the directory (each .sim/base.json, ids it allocated, values the server normalized), and the next apply compares with them, so the last step commits them back to the branch; [skip ci] keeps that commit from running the job again. That step runs even when the apply failed (!cancelled()), because an apply can fail having written part of its plan: exit 15 means it held back changes that use a secret with no value or a credential nothing binds to and applied the rest, and exit 8 means it stopped part-way. Either way the directory records what was written, so committing it keeps the next run from being refused as stale (exit 5) for resources this run wrote; the job still fails, so set the secret, connect the credential or fix the failure, and push again. Where the branch is protected, run sim workspaces source get --dir workspace on a new branch instead and open a pull request.
After merging two branches that each applied, a dry run with no changes means the files match the workspace. Exit 5 means a resource changed since this branch's base: get the workspace into a fresh directory and carry the edit over. Exit 10 means another apply is writing the workspace (or another command is using the directory), so retry; the concurrency key keeps two runs of this job from overlapping. Pull requests from forks do not receive repository secrets, so the dry run needs a branch in the same repository.
Comment the plan on the pull request
The step summary appears on the run page, not in the pull request. To post the plan as one comment that later pushes edit instead of adding another, write the plan to a file with --summary-file in the step that runs the dry run and post that file, with pull-requests: write in permissions:
Use this step in place of the plain dry-run step for pull requests. The comment lists the first 50 changes and errors and counts the rest. --edit-last edits the last comment from the same account, which is the Actions bot here, so do not post other comments from this token on the pull request.
Detect drift on a schedule
A change made in Sim, such as a hotfix in the workflow builder, makes the next apply exit 5. A scheduled job finds it first: status exits 12 when the server changed since the directory was read, and 11 when the committed directory holds edits no apply has saved, for example after a merge whose apply failed.
status exits 0 or 11 without asking Sim when the server is unreachable, so the job reads the server field of its JSON output and fails unless it is checked. To bring the change into git instead, run sim workspaces source get --dir workspace on a new branch and open a pull request.
Promote in CI
To promote the same directory to a second workspace, add a step with --to before the step that commits the files back:
The promotion writes workspace/.sim/targets/<workspaceId>.json, what it left in that workspace. Committing it lets the next run tell a change made in that workspace since (kept, or exit 5 when the directory changed the same resource) from one to promote. See Promote to another workspace.
Git provenance
In a git repository, apply and create send the commit checked out (HEAD) and the origin remote URL, with any credentials, query or fragment removed, as provenance.gitSha and provenance.repo, each only when git can read it (a repository with no origin sends only the commit). A saved write records what was sent in its audit log entry (workflow.updated or workflow.created for a workflow, workspace.updated for a workspace apply). A directory outside a repository sends neither.