Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

Release SDK 0.0.2 with automated npm publishing (#6335)

teof13efac2b729
diff --git a/.agents/skills/release-sdk/SKILL.md b/.agents/skills/release-sdk/SKILL.md
new file mode 100644
index 0000000000..1e8641cedb
--- /dev/null
+++ b/.agents/skills/release-sdk/SKILL.md
@@ -0,0 +1,45 @@
+---
+name: release-sdk
+description: Prepare or publish a patch release of @macro-inc/sdk in this repository. Use when asked to bump the SDK patch version or release it to npm.
+---
+
+# Release the SDK
+
+Read [the SDK release guide](../../../packages/sdk/RELEASING.md) and the root
+`AGENTS.md`. Follow the guide for commands, npm setup, validation, tagging, and
+recovery; inspect the current workflow and package metadata before executing it.
+
+## Scope
+
+- “Bump” or “prepare a release” authorizes preparation, validation, and a release
+ PR as appropriate; it does not by itself authorize publishing to npm.
+- “Release/publish a new patch” authorizes the full process, including the release
+ PR, merging once required checks/reviews permit it, and pushing the release tag.
+ Honor existing session authorization without asking for it again. If release
+ authorization is missing, finish the reviewable preparation before asking.
+- Creating or editing this skill or its documentation does not authorize a release.
+
+## Execution
+
+1. Inspect the worktree, current branch, `origin/main`, npm versions, release tags,
+ and any existing release PR/run. Preserve unrelated changes. Determine the
+ next stable patch from current state; resume an already prepared bump instead
+ of bumping twice. If versions disagree or the base is a prerelease, resolve
+ that before selecting a target.
+2. Check the guide's npm prerequisites. Make the version change, run its SDK
+ validation and package inspection, and prepare a PR with the old/new version
+ and results. Do not hide failed checks or bypass repository review rules.
+3. For an authorized publication, merge after required checks/reviews pass and
+ pin the actual merged commit. Verify its version, workflow, and ancestry on
+ freshly fetched `origin/main`; check npm and remote tags again for collisions.
+4. Push only the matching `sdk-vX.Y.Z` tag. Watch the exact tag/commit's Publish SDK
+ run, then verify that version and the npm dist-tag. A version bump, a pushed
+ tag, or a green validation job alone is not proof of publication.
+5. Follow the guide's bounded recovery steps for failures. Never move an existing
+ release tag or retry publishing an already published version. If access,
+ required reviews, or npm setup block progress, report the completed preparation
+ and precise remaining action.
+
+Return the old/new version, PR and release commit, tag, Actions run URL, and npm
+verification. Clearly distinguish prepared, awaiting merge, publishing, failed,
+and published states; include only artifacts that actually exist.
diff --git a/.github/workflows/publish-sdk.yml b/.github/workflows/publish-sdk.yml
new file mode 100644
index 0000000000..9f848333fb
--- /dev/null
+++ b/.github/workflows/publish-sdk.yml
@@ -0,0 +1,58 @@
+# DO NOT EDIT — regenerate with `cargo x workflows` (from the repository root).
+# Source: tooling/xtask/crates/xtask_workflows/src/workflows/publish_sdk.rs
+name: Publish SDK
+'on':
+ push:
+ tags:
+ - sdk-v*
+jobs:
+ publish:
+ name: Publish @macro-inc/sdk
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ id-token: write
+ steps:
+ - name: Checkout
+ uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
+ with:
+ clean: 'false'
+ fetch-depth: '0'
+ persist-credentials: 'false'
+ - name: Setup Bun
+ uses: oven-sh/setup-bun@v2
+ with:
+ bun-version: '1.3.5'
+ - name: Setup Node
+ uses: actions/setup-node@v4
+ with:
+ node-version: '24'
+ registry-url: https://registry.npmjs.org
+ - name: Setup npm
+ run: npm install --global 'npm@^11.5.1'
+ - name: Verify release tag
+ run: |
+ version="${GITHUB_REF_NAME#sdk-v}"
+ package_version="$(node -p "require('./packages/sdk/package.json').version")"
+
+ if [ "$version" != "$package_version" ]; then
+ echo "tag version $version does not match package version $package_version"
+ exit 1
+ fi
+
+ if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then
+ echo "release commit $GITHUB_SHA is not on main"
+ exit 1
+ fi
+ - name: Install dependencies
+ run: bun install --frozen-lockfile
+ working-directory: packages/sdk
+ - name: Validate SDK
+ run: bun run check && bun test && bun run coverage && bun run build
+ working-directory: packages/sdk
+ - name: Publish package
+ run: npm publish --access public
+ working-directory: packages/sdk
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: false
diff --git a/CLAUDE.md b/CLAUDE.md
index 6b6be4cff9..5c0fc01b15 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -36,6 +36,7 @@ This file is the shared entry point: `AGENTS.md` symlinks to `CLAUDE.md`. Edit
| Running the frontend or backend on a local machine | [Running locally](docs/RUNNING_LOCALLY.md) |
| Working inside Cursor Cloud | [Cursor Cloud](docs/CURSOR_CLOUD.md) |
| Driving the app through a browser | [App agent guide](docs/AGENT_GUIDE/README.md) |
+| SDK version bumps and npm publishing | [SDK release guide](packages/sdk/RELEASING.md), [release-sdk skill](.agents/skills/release-sdk/SKILL.md) |
| Deployment | [Infrastructure guide](infra/README.md) |
## Essential guardrails
diff --git a/packages/sdk/README.md b/packages/sdk/README.md
index 6d6f774938..5e2732d16a 100644
--- a/packages/sdk/README.md
+++ b/packages/sdk/README.md
@@ -11,7 +11,7 @@ Macro's SDK: a Typescript library for harnessing the power of Macro
To get started, make a Macro client
```ts
-import { Macro } from '@macro/sdk';
+import { Macro } from '@macro-inc/sdk';
const macro = new Macro({ }); // uses MACRO_API_KEY env var
```
@@ -31,7 +31,7 @@ Every request the SDK sends carries exactly one Macro credential. There are thre
The default for scripts and integrations. Put the key in `MACRO_API_KEY` and construct with no options.
```ts
-import { Macro } from '@macro/sdk';
+import { Macro } from '@macro-inc/sdk';
const macro = new Macro({});
const me = await macro.users.me();
@@ -148,7 +148,7 @@ Use the `msg` tagged template to build rich message bodies for channel messages
or documents.
```ts
-import { msg, here } from '@macro/sdk';
+import { msg, here } from '@macro-inc/sdk';
const channel = macro.channels.byId('chan_1');
const user = macro.users.byId('user_1');
@@ -228,6 +228,12 @@ app.post('/webhook', (c) => macro.events.webhook()(c.req.raw));
This section is just if you are contributing to the SDK.
+## Releases
+
+See [Releasing the SDK](RELEASING.md) for patch version bumps, npm setup,
+and tag-triggered publishing. Agents can use the
+[`release-sdk`](../../.agents/skills/release-sdk/SKILL.md) skill.
+
## Coverage checking
We have a coverage checker. It reads every generated function and ensures that
diff --git a/packages/sdk/RELEASING.md b/packages/sdk/RELEASING.md
new file mode 100644
index 0000000000..da4fdc9352
--- /dev/null
+++ b/packages/sdk/RELEASING.md
@@ -0,0 +1,142 @@
+# Releasing the SDK
+
+SDK releases publish `@macro-inc/sdk` to npm. Incrementing `package.json` alone
+never publishes: merge the version change into `main`, then push an `sdk-vX.Y.Z`
+tag pointing at the intended merged commit. A GitHub Release is optional and is
+not the workflow trigger.
+
+Agents can use [`release-sdk`](../../.agents/skills/release-sdk/SKILL.md) to
+prepare or publish a patch release using this guide.
+
+## One-time npm setup
+
+Before the first automated release, a package maintainer must verify the package
+exists on npm and configure its trusted publisher:
+
+| Setting | Value |
+| --- | --- |
+| Provider | GitHub Actions |
+| Organization | `macro-inc` |
+| Repository | `macro` |
+| Workflow filename | `publish-sdk.yml` |
+| Environment | Leave blank; the job declares no environment |
+| Allowed actions | Allow direct publishing with `npm publish` |
+
+If the package does not exist, arrange its initial publication with a maintainer
+before following the routine patch process. Do not interpret network or
+authentication errors as proof that the package or version is available.
+
+Check that `packages/sdk/package.json` has repository metadata matching
+`https://github.com/macro-inc/macro` (conventionally
+`"repository": { "type": "git", "url": "git+https://github.com/macro-inc/macro.git", "directory": "packages/sdk" }`).
+Add missing metadata in the release PR. npm documents this requirement in its
+[trusted publishing guide](https://docs.npmjs.com/trusted-publishers/).
+The workflow uses OIDC; routine releases do not need an npm token in GitHub secrets.
+
+## Prepare a patch
+
+1. From the repository root, inspect the working tree and fetch current release
+ state. Preserve unrelated edits; use a separate checkout if necessary.
+
+ ```sh
+ git status --short --branch
+ git fetch origin main --tags
+ git show origin/main:packages/sdk/package.json
+ npm view @macro-inc/sdk versions --json --registry=https://registry.npmjs.org
+ git ls-remote --tags origin 'refs/tags/sdk-v*'
+ ```
+
+2. Choose the next patch of the current stable version (`X.Y.Z` → `X.Y.(Z+1)`),
+ checking both `main` and npm. For example, `0.0.1` → `0.0.2`. If a release
+ bump is already prepared, resume it instead of incrementing again. Resolve
+ disagreements between the checkout, `main`, tags, and npm before proceeding;
+ do not downgrade or silently turn a prerelease/minor/major release into a patch.
+
+3. Edit only the `version` field in `packages/sdk/package.json` for the bump.
+ Keep the Bun lockfile consistent if installation changes it; do not introduce
+ an npm lockfile or use a version command that creates an early Git tag.
+
+4. In `packages/sdk`, run the same validation as publishing CI:
+
+ ```sh
+ bun install --frozen-lockfile
+ bun run check && bun test && bun run coverage && bun run build
+ npm pack --dry-run --ignore-scripts
+ ```
+
+ Inspect the package listing: the compiled JavaScript and declaration files
+ referenced by `exports` must be present. `coverage` checks endpoint wrappers,
+ not test coverage. SDK CI also checks generated-code freshness; if stale,
+ follow the package's `just update-generated` workflow and review its diff.
+ Run `just check` from the repository root before committing.
+
+5. Commit the intended release changes, push a branch, and open a PR. Include the
+ old/new version, SDK changes being released, and validation results. Wait for
+ required checks and reviews, then merge within the user's authorized scope.
+ A request to prepare a bump ends at the prepared change or PR; a request to
+ publish includes proceeding through the tag and verification steps.
+
+## Publish the merged commit
+
+Use the actual merge or squash commit from the release PR, not an unmerged branch
+commit or an unchecked moving `main` tip. From the repository root, set these
+values for the release (replace the examples):
+
+```sh
+sdk_version='0.0.2'
+sdk_release_sha='<full merged commit SHA>'
+sdk_tag="sdk-v${sdk_version}"
+git fetch origin main --tags
+git merge-base --is-ancestor "$sdk_release_sha" origin/main
+git show "${sdk_release_sha}:packages/sdk/package.json"
+```
+
+Continue only if the ancestry check succeeds, that commit's package version
+exactly matches `sdk_version`, and it contains `.github/workflows/publish-sdk.yml`.
+Recheck npm and remote tags immediately before tagging. If the version is already
+published, verify the existing release instead. If the tag exists, inspect its
+commit and associated run; never move, delete, or force-push a release tag.
+
+Pushing this tag starts the public npm publication:
+
+```sh
+git tag "$sdk_tag" "$sdk_release_sha"
+git push origin "refs/tags/${sdk_tag}"
+```
+
+The workflow rejects mismatched versions and commits outside `main`, installs
+with Bun, validates, builds, and runs `npm publish --access public`. It has no
+manual dispatch trigger and does not create a GitHub Release or release notes.
+
+## Verify and recover
+
+Find the run for the exact tag and confirm its commit SHA before watching it:
+
+```sh
+gh run list --repo macro-inc/macro --workflow publish-sdk.yml --branch "$sdk_tag" \
+ --json databaseId,headSha,status,conclusion,url
+# Replace RUN_ID with the matching run's databaseId.
+gh run watch RUN_ID --repo macro-inc/macro --exit-status
+npm view "@macro-inc/sdk@${sdk_version}" version dist.tarball --json \
+ --registry=https://registry.npmjs.org
+npm view @macro-inc/sdk dist-tags --json --registry=https://registry.npmjs.org
+```
+
+Confirm the requested version is available and `latest` points to it (unless a
+newer release has since completed). Report the version, commit, tag, PR, Actions
+run URL, and npm verification. If the run has not appeared or npm has not updated,
+allow a short bounded wait and report pending status rather than claiming success.
+
+On failure, read the failed job logs and check npm before retrying: a run may have
+published successfully before a later failure. Retry the same run only after a
+transient or configuration problem is resolved and the version remains
+unpublished. Code fixes go through a new PR and a new version/tag. Never overwrite
+an existing npm version, move a release tag, or bypass CI with a local publish as
+a recovery shortcut. Report missing npm access or setup as a concrete blocker.
+
+## Maintaining the workflow
+
+[Publish SDK](../../.github/workflows/publish-sdk.yml) is generated from
+[`publish_sdk.rs`](../../tooling/xtask/crates/xtask_workflows/src/workflows/publish_sdk.rs).
+Change the Rust source and regenerate with `cargo x workflows` from the repository
+root; do not hand-edit the generated YAML.
diff --git a/packages/sdk/bun.lock b/packages/sdk/bun.lock
index 7f356348ba..44c0a13fb5 100644
--- a/packages/sdk/bun.lock
+++ b/packages/sdk/bun.lock
@@ -3,7 +3,7 @@
"configVersion": 1,
"workspaces": {
"": {
- "name": "@macro/sdk",
+ "name": "@macro-inc/sdk",
"dependencies": {
"ts-pattern": "^5.8.0",
},
diff --git a/packages/sdk/package.json b/packages/sdk/package.json
index 58cd91c4bc..66d435040d 100644
--- a/packages/sdk/package.json
+++ b/packages/sdk/package.json
@@ -1,6 +1,11 @@
{
- "name": "@macro/sdk",
- "version": "0.0.1",
+ "name": "@macro-inc/sdk",
+ "version": "0.0.2",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/macro-inc/macro.git",
+ "directory": "packages/sdk"
+ },
"type": "module",
"description": "Libary for interacting with Macro.com",
"main": "./dist/src/macro.js",
diff --git a/packages/sdk/src/config.ts b/packages/sdk/src/config.ts
index d1437d9ca4..a90d9f543a 100644
--- a/packages/sdk/src/config.ts
+++ b/packages/sdk/src/config.ts
@@ -109,7 +109,7 @@ export interface MacroOpts {
* key (`mak_…`) or a bearer token. */
token?: TokenSource;
/** Which Macro environment to talk to. Falls back to the MACRO_ENV env
- * var, then `'dev'`. */
+ * var, then `'prod'`. */
env?: Env;
/** Override individual service hosts (e.g. point one at localhost). */
hosts?: Partial<Record<ServiceName, string>>;
diff --git a/packages/sdk/src/utils/client.ts b/packages/sdk/src/utils/client.ts
index 7f8f75bbb0..ac3246557e 100644
--- a/packages/sdk/src/utils/client.ts
+++ b/packages/sdk/src/utils/client.ts
@@ -34,15 +34,15 @@ function userCredentialHeader(secret: string): CredentialHeader {
return match(secret)
.with(P.string.startsWith(BOT_TOKEN_PREFIX), () => {
throw new Error(
- "bot token passed as a user credential. Use auth: { type: 'bot', token } or MACRO_BOT_TOKEN.",
+ "bot token passed as a user credential. Use auth: { type: 'bot', token } or MACRO_BOT_TOKEN."
);
})
.with(
P.string.startsWith(USER_API_KEY_PREFIX),
- (key): CredentialHeader => [USER_API_KEY_HEADER, key],
+ (key): CredentialHeader => [USER_API_KEY_HEADER, key]
)
.otherwise(
- (token): CredentialHeader => ['Authorization', `Bearer ${token}`],
+ (token): CredentialHeader => ['Authorization', `Bearer ${token}`]
);
}
@@ -53,14 +53,14 @@ async function resolveToken(source: TokenSource): Promise<string> {
export async function requestAuthHeaders(
auth: MacroAuth,
requestedAs?: string,
- existing?: { hasBotScope?: boolean },
+ existing?: { hasBotScope?: boolean }
): Promise<ReadonlyArray<readonly [string, string]>> {
return match(auth)
.with({ type: 'bot' }, async (botAuth) => {
const tok = await resolveToken(botAuth.token);
if (!tok.startsWith(BOT_TOKEN_PREFIX)) {
throw new Error(
- "user API key passed as a bot token. Use auth: { type: 'user', apiKey } or MACRO_API_KEY.",
+ "user API key passed as a bot token. Use auth: { type: 'user', apiKey } or MACRO_API_KEY."
);
}
const headers: Array<readonly [string, string]> = [
@@ -80,7 +80,7 @@ export async function requestAuthHeaders(
.with({ type: 'user', apiKey: P.string }, ({ apiKey }) => {
if (apiKey.startsWith(BOT_TOKEN_PREFIX)) {
throw new Error(
- "bot token passed as a user credential. Use auth: { type: 'bot', token } or MACRO_BOT_TOKEN.",
+ "bot token passed as a user credential. Use auth: { type: 'bot', token } or MACRO_BOT_TOKEN."
);
}
return [[USER_API_KEY_HEADER, apiKey] as const];
@@ -133,7 +133,7 @@ export class MacroClient {
this.requestedAs = opts.requestedAs;
if (this.requestedAs && this.authConfig.type !== 'bot') {
throw new Error(
- 'requestedAs() requires bot auth — a user token always acts as its own user',
+ 'requestedAs() requires bot auth — a user token always acts as its own user'
);
}
this.wsVerify = opts.wsVerify;
@@ -206,7 +206,7 @@ export class MacroClient {
const headers = await requestAuthHeaders(
this.authConfig,
this.requestedAs,
- { hasBotScope: request.headers.has('x-macro-bot-scope') },
+ { hasBotScope: request.headers.has('x-macro-bot-scope') }
);
for (const [name, value] of headers) {
request.headers.set(name, value);
@@ -221,10 +221,10 @@ function resolveEnv(opts: MacroOpts): Env {
if (opts.env) return opts.env;
const fromEnv =
typeof process !== 'undefined' ? process.env.MACRO_ENV : undefined;
- if (!fromEnv) return 'dev';
+ if (!fromEnv) return 'prod';
if (!(fromEnv in HOSTS)) {
throw new Error(
- `invalid MACRO_ENV "${fromEnv}" — expected local, dev, or prod`,
+ `invalid MACRO_ENV "${fromEnv}" — expected local, dev, or prod`
);
}
return fromEnv as Env;
@@ -239,7 +239,7 @@ function resolveAuth(opts: MacroOpts): MacroAuth {
typeof process !== 'undefined' ? process.env.MACRO_BOT_TOKEN : undefined;
if (envApiKey && envBotToken) {
throw new Error(
- 'both MACRO_API_KEY and MACRO_BOT_TOKEN are set — pass auth to new Macro() to pick one',
+ 'both MACRO_API_KEY and MACRO_BOT_TOKEN are set — pass auth to new Macro() to pick one'
);
}
if (envBotToken) return { type: 'bot', token: envBotToken };
@@ -249,7 +249,7 @@ function resolveAuth(opts: MacroOpts): MacroAuth {
envApiKey ??
(() => {
throw new Error(
- 'no Macro credential. Set MACRO_API_KEY (API key or bearer token) or MACRO_BOT_TOKEN, or pass token/auth to new Macro().',
+ 'no Macro credential. Set MACRO_API_KEY (API key or bearer token) or MACRO_BOT_TOKEN, or pass token/auth to new Macro().'
);
}),
};
diff --git a/packages/sdk/tests/default-environment.test.ts b/packages/sdk/tests/default-environment.test.ts
new file mode 100644
index 0000000000..ef1530ead1
--- /dev/null
+++ b/packages/sdk/tests/default-environment.test.ts
@@ -0,0 +1,21 @@
+import { afterEach, expect, test } from 'bun:test';
+import { Macro } from '../src/macro';
+
+const originalMacroEnv = process.env.MACRO_ENV;
+
+afterEach(() => {
+ if (originalMacroEnv === undefined) {
+ delete process.env.MACRO_ENV;
+ } else {
+ process.env.MACRO_ENV = originalMacroEnv;
+ }
+});
+
+test('uses production services when no environment is configured', () => {
+ delete process.env.MACRO_ENV;
+
+ const macro = new Macro({ token: 'test-token' });
+
+ expect(macro._client.hosts.storage).toBe('https://gateway.macro.com/dss');
+ expect(macro.webAppUrl).toBe('https://macro.com');
+});
diff --git a/services/bots/anthropic-status-bot/README.md b/services/bots/anthropic-status-bot/README.md
index 1a876ad4b0..386b1740b8 100644
--- a/services/bots/anthropic-status-bot/README.md
+++ b/services/bots/anthropic-status-bot/README.md
@@ -14,7 +14,7 @@ lambda used.
Statuspage webhook ──POST──> /webhook/{WEBHOOK_SECRET}
│ parse + format (incident | component)
▼
- @macro/sdk → POST /channels/{CHANNEL_ID}/webhook
+ @macro-inc/sdk → POST /channels/{CHANNEL_ID}/webhook
headers: x-macro-bot-token: BOT_TOKEN, x-macro-bot-scope: user
body: {"content": "🟡 [Anthropic Status] ..."}
```
diff --git a/services/coding-agent-worker/index.ts b/services/coding-agent-worker/index.ts
index 1fe4a2475d..d5f38ddbbc 100644
--- a/services/coding-agent-worker/index.ts
+++ b/services/coding-agent-worker/index.ts
@@ -1,4 +1,4 @@
-import { msg } from '@macro/sdk';
+import { msg } from '@macro-inc/sdk';
import { Hono } from 'hono';
import { logger } from 'hono/logger';
import { macro } from './src/macro';
diff --git a/services/coding-agent-worker/package.json b/services/coding-agent-worker/package.json
index 7caa0da850..6a38169519 100644
--- a/services/coding-agent-worker/package.json
+++ b/services/coding-agent-worker/package.json
@@ -8,7 +8,7 @@
"dependencies": {
"@agentclientprotocol/sdk": "^1.2.1",
"@daytona/sdk": "latest",
- "@macro/sdk": "file:../../packages/sdk",
+ "@macro-inc/sdk": "file:../../packages/sdk",
"envsafe": "^2.0.3",
"hono": "^4.12.30",
"ink": "^7.1.1",
diff --git a/services/coding-agent-worker/scripts/tmp/list-webhooks.ts b/services/coding-agent-worker/scripts/tmp/list-webhooks.ts
index 495a702180..76593e0238 100644
--- a/services/coding-agent-worker/scripts/tmp/list-webhooks.ts
+++ b/services/coding-agent-worker/scripts/tmp/list-webhooks.ts
@@ -1,4 +1,4 @@
-import { Macro } from '@macro/sdk';
+import { Macro } from '@macro-inc/sdk';
import { env } from '../../src/env';
const macro = new Macro({}).requestedAs(env.MACRO_USER_ID);
diff --git a/services/coding-agent-worker/src/macro.ts b/services/coding-agent-worker/src/macro.ts
index 9f61803c26..55822cadfa 100644
--- a/services/coding-agent-worker/src/macro.ts
+++ b/services/coding-agent-worker/src/macro.ts
@@ -1,4 +1,4 @@
-import { Macro } from '@macro/sdk';
+import { Macro } from '@macro-inc/sdk';
import { env } from './env';
import { ensureWebhook } from './webhook';
diff --git a/services/coding-agent-worker/src/webhook.ts b/services/coding-agent-worker/src/webhook.ts
index ea67aa5e8d..24f7bdd2e5 100644
--- a/services/coding-agent-worker/src/webhook.ts
+++ b/services/coding-agent-worker/src/webhook.ts
@@ -1,4 +1,4 @@
-import { Macro } from '@macro/sdk';
+import { Macro } from '@macro-inc/sdk';
import { env } from './env';
const STATE_FILE = new URL('../.webhook.json', import.meta.url);
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows.rs b/tooling/xtask/crates/xtask_workflows/src/workflows.rs
index fc7580894b..fb2ab04738 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows.rs
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows.rs
@@ -36,6 +36,7 @@ mod deploy_web_app;
mod docs_check;
mod ensure_daytona_snapshot;
mod path_validation;
+mod publish_sdk;
mod pulumi_preview_pr;
mod push_local_stack_binaries;
mod reusable_deploy_service;
@@ -251,6 +252,11 @@ const WORKFLOWS: &[WorkflowFile] = &[
file_name: "push_local_stack_binaries.yml",
render_yaml: || render_gh_workflow(push_local_stack_binaries::push_local_stack_binaries)(),
},
+ WorkflowFile {
+ slug: "publish_sdk",
+ file_name: "publish-sdk.yml",
+ render_yaml: || render_gh_workflow(publish_sdk::publish_sdk)(),
+ },
WorkflowFile {
slug: "pulumi_preview_pr",
file_name: "pulumi_preview_pr.yml",
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/publish_sdk.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/publish_sdk.rs
new file mode 100644
index 0000000000..e62d3a5e3e
--- /dev/null
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/publish_sdk.rs
@@ -0,0 +1,90 @@
+//! `Publish SDK` — validates and publishes `@macro-inc/sdk` when an `sdk-v*` tag
+//! is pushed. Generated into `publish-sdk.yml`.
+
+use gh_workflow::{
+ Concurrency, Event, Expression, Job, Level, Permissions, Push, Run, Step, Use, Workflow,
+};
+
+use crate::workflows::steps;
+
+#[cfg(test)]
+mod test;
+
+const SDK_TAG_PATTERN: &str = "sdk-v*";
+
+/// Build the workflow.
+pub fn publish_sdk() -> Workflow {
+ Workflow::new("Publish SDK")
+ .on(Event::default().push(Push::default().add_tag(SDK_TAG_PATTERN)))
+ .concurrency(
+ Concurrency::new(Expression::new("${{ github.workflow }}-${{ github.ref }}"))
+ .cancel_in_progress(false),
+ )
+ .add_job("publish", publish())
+}
+
+fn publish() -> Job {
+ Job::default()
+ .name("Publish @macro-inc/sdk")
+ // npm trusted publishing only supports GitHub-hosted runners.
+ .runs_on("ubuntu-latest")
+ .permissions(
+ Permissions::default()
+ .contents(Level::Read)
+ .id_token(Level::Write),
+ )
+ .add_step(steps::checkout(true, false))
+ .add_step(steps::setup_bun().add_with(("bun-version", "1.3.5")))
+ .add_step(setup_node())
+ .add_step(setup_npm())
+ .add_step(verify_release())
+ .add_step(install_dependencies())
+ .add_step(validate())
+ .add_step(publish_package())
+}
+
+fn setup_node() -> Step<Use> {
+ Step::new("Setup Node")
+ .uses("actions", "setup-node", "v4")
+ .add_with(("node-version", "24"))
+ .add_with(("registry-url", "https://registry.npmjs.org"))
+}
+
+fn setup_npm() -> Step<Run> {
+ Step::new("Setup npm").run("npm install --global 'npm@^11.5.1'")
+}
+
+fn verify_release() -> Step<Run> {
+ Step::new("Verify release tag").run(indoc::indoc! {r#"
+ version="${GITHUB_REF_NAME#sdk-v}"
+ package_version="$(node -p "require('./packages/sdk/package.json').version")"
+
+ if [ "$version" != "$package_version" ]; then
+ echo "tag version $version does not match package version $package_version"
+ exit 1
+ fi
+
+ if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then
+ echo "release commit $GITHUB_SHA is not on main"
+ exit 1
+ fi
+ "#})
+}
+
+fn install_dependencies() -> Step<Run> {
+ Step::new("Install dependencies")
+ .run("bun install --frozen-lockfile")
+ .working_directory(xtask_paths::repo_dir!("packages/sdk"))
+}
+
+fn validate() -> Step<Run> {
+ Step::new("Validate SDK")
+ .run("bun run check && bun test && bun run coverage && bun run build")
+ .working_directory(xtask_paths::repo_dir!("packages/sdk"))
+}
+
+fn publish_package() -> Step<Run> {
+ Step::new("Publish package")
+ .run("npm publish --access public")
+ .working_directory(xtask_paths::repo_dir!("packages/sdk"))
+}
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/publish_sdk/test.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/publish_sdk/test.rs
new file mode 100644
index 0000000000..b007ace18d
--- /dev/null
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/publish_sdk/test.rs
@@ -0,0 +1,19 @@
+use super::*;
+
+fn rendered_yaml() -> String {
+ publish_sdk()
+ .to_string()
+ .expect("SDK publish workflow should serialize")
+}
+
+#[test]
+fn publishes_matching_tags_with_oidc_on_a_github_runner() {
+ let yaml = rendered_yaml();
+
+ assert!(yaml.contains(SDK_TAG_PATTERN));
+ assert!(yaml.contains("runs-on: ubuntu-latest"));
+ assert!(yaml.contains("id-token: write"));
+ assert!(yaml.contains("npm publish --access public"));
+ assert!(yaml.contains("tag version $version does not match package version $package_version"));
+ assert!(yaml.contains("git merge-base --is-ancestor \"$GITHUB_SHA\" origin/main"));
+}