Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

CI: fail the broker deploy when it cannot deploy, and deploy nightly too (#6908)

Milind Soni09adc3db6a1b
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index ba58fea04d..283459f6a0 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -532,20 +532,28 @@ jobs:
# commit, so an unreviewed branch can never push to production. Closes
# the deploy gap that left #1914's broker fix (45cc2cf) sitting in
# source without reaching Cloudflare.
+ # The nightly run on main deploys too, so a main run cancelled before this
+ # job leaves the Worker behind main for a day at most.
needs: [control-plane]
- if: github.event_name == 'push' && github.ref == 'refs/heads/main'
+ if: (github.event_name == 'push' || github.event_name == 'schedule') && github.ref == 'refs/heads/main'
name: deploy composio broker (Cloudflare Worker)
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- # A repo without the secret (a fork, or before the token is created)
- # skips the deploy with a warning instead of failing every main push.
+ # A fork without the secret skips the deploy with a warning. On this
+ # repository a missing token fails the job: from October to November 2026
+ # the job passed while skipping every deploy, and the live Worker stayed
+ # weeks behind main without anyone seeing it.
- id: token
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
+ UPSTREAM: ${{ github.repository == 'milind-soni/OpenMausBot' }}
run: |
if [ -n "$CLOUDFLARE_API_TOKEN" ]; then
echo "present=true" >> "$GITHUB_OUTPUT"
+ elif [ "$UPSTREAM" = "true" ]; then
+ echo "::error title=Composio broker not deployed::CLOUDFLARE_API_TOKEN is not set, so the broker Worker was not deployed and the live service is behind main."
+ exit 1
else
echo "::warning title=Composio broker not deployed::CLOUDFLARE_API_TOKEN is not set, so the broker Worker was not deployed."
fi
@@ -566,6 +574,20 @@ jobs:
run: pnpm broker:check
- if: steps.token.outputs.present == 'true'
run: pnpm broker:test
+ # Migrations are applied by hand before the code that needs them (the
+ # README's deploy order). New code on a database without them fails at
+ # run time, so the deploy stops here instead.
+ - name: Every database migration is applied
+ if: steps.token.outputs.present == 'true'
+ env:
+ CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
+ run: |
+ out=$(pnpm exec wrangler d1 migrations list openmausbot-composio --remote --config cloudflare/composio-broker/wrangler.jsonc 2>&1) || { echo "$out"; exit 1; }
+ echo "$out"
+ if ! printf '%s\n' "$out" | grep -q "No migrations to apply"; then
+ echo "::error title=Composio broker not deployed::A migration is not applied to the remote database. Apply it (cloudflare/composio-broker/README.md), then rerun this job."
+ exit 1
+ fi
- name: Deploy the composio broker Worker via Wrangler
if: steps.token.outputs.present == 'true'
uses: cloudflare/wrangler-action@9acf94ace14e7dc412b076f2c5c20b8ce93c79cd # v3.15.0
@@ -574,8 +596,12 @@ jobs:
# Mirrors the local `pnpm broker:deploy` script so CI is the same
# command a developer runs by hand. The token is created in the
# Cloudflare dashboard with Workers Scripts:Edit on the broker
- # account; store it as the CLOUDFLARE_API_TOKEN repo secret.
- command: deploy --config cloudflare/composio-broker/wrangler.jsonc
+ # account, plus D1 Edit: the migration check above runs SQL through
+ # D1's query API (a `CREATE TABLE IF NOT EXISTS d1_migrations` and a
+ # read), which D1 Read does not allow. Store it as the
+ # CLOUDFLARE_API_TOKEN repo secret. The message names the commit,
+ # so `wrangler deployments list` shows what is live.
+ command: deploy --config cloudflare/composio-broker/wrangler.jsonc --message "main ${{ github.sha }} (CI ${{ github.event_name }})"
ui-smoke:
needs: static
diff --git a/cloudflare/composio-broker/README.md b/cloudflare/composio-broker/README.md
index ed1b3a5811..7045c50d43 100644
--- a/cloudflare/composio-broker/README.md
+++ b/cloudflare/composio-broker/README.md
@@ -15,6 +15,13 @@ Deployment for this repository:
3. For an existing Worker, run `pnpm exec wrangler secret put COMPOSIO_API_KEY --config cloudflare/composio-broker/wrangler.jsonc`, then `pnpm broker:deploy`.
4. For the very first deploy, put `COMPOSIO_API_KEY=...` in the ignored `.dev.vars.production` file and run `pnpm exec wrangler deploy --config cloudflare/composio-broker/wrangler.jsonc --secrets-file .dev.vars.production`. Delete the file immediately afterward.
+CI deploys main after every push and every nightly run (the `deploy-composio-broker` job), with the
+`CLOUDFLARE_API_TOKEN` repository secret: Workers Scripts Edit and D1 Edit on the broker's account only (the migration
+check runs `CREATE TABLE IF NOT EXISTS d1_migrations` and a read through D1's query API, which needs Edit). On this
+repository the job fails without the secret, and it stops before deploying while `wrangler d1 migrations list
+--remote` shows a migration not yet applied: apply it (step 2), then rerun the job. Each CI deploy's message names
+its commit, so `wrangler deployments list` shows which commit is live.
+
Forks should create their own D1 database and rate-limit namespaces, replace
the IDs in `wrangler.jsonc`, deploy under their own Worker name, and set
`OMB_COMPOSIO_BROKER_URL` in their packaged build. Running only the local
diff --git a/scripts/ci-workflow.test.ts b/scripts/ci-workflow.test.ts
index b4108e2655..4eb167866a 100644
--- a/scripts/ci-workflow.test.ts
+++ b/scripts/ci-workflow.test.ts
@@ -278,19 +278,29 @@ describe("CI concurrency", () => {
)).toBe(true);
for (const [name, job] of Object.entries(workflow.jobs) as [string, { needs?: string | string[]; if?: string }][]) {
if (["static", "gate"].includes(name)) continue;
- // The one deploy job: after the control-plane checks, on main pushes only. It is
- // not part of the merge gate.
+ // The one deploy job: after the control-plane checks, on main's pushes and its nightly
+ // run only. It is not part of the merge gate.
if (name === "deploy-composio-broker") {
expect(job.needs).toEqual(["control-plane"]);
- expect(job.if).toBe("github.event_name == 'push' && github.ref == 'refs/heads/main'");
+ expect(job.if).toBe("(github.event_name == 'push' || github.event_name == 'schedule') && github.ref == 'refs/heads/main'");
expect(workflow.jobs.gate.needs).not.toContain(name);
- // Without the Cloudflare token the deploy is skipped with a warning, not failed:
- // every step after the token check waits on it.
+ // Without the Cloudflare token a fork skips the deploy with a warning; this repository
+ // fails, so a deploy that never happens shows. Every step after the check waits on it.
const [check, ...rest] = job.steps as { id?: string; if?: string; env?: Record<string, string>; run?: string }[];
expect(check.id).toBe("token");
- expect(check.env).toEqual({ CLOUDFLARE_API_TOKEN: "${{ secrets.CLOUDFLARE_API_TOKEN }}" });
+ expect(check.env).toEqual({
+ CLOUDFLARE_API_TOKEN: "${{ secrets.CLOUDFLARE_API_TOKEN }}",
+ UPSTREAM: "${{ github.repository == 'milind-soni/OpenMausBot' }}",
+ });
expect(check.run).toContain("::warning");
+ expect(check.run).toMatch(/elif \[ "\$UPSTREAM" = "true" \]; then\n\s*echo "::error[^\n]*\n\s*exit 1\n/);
for (const step of rest) expect(step.if).toBe("steps.token.outputs.present == 'true'");
+ // The deploy stops while a database migration is unapplied, and names the commit it deploys.
+ const migrations = rest.findIndex((step) => step.run?.includes("d1 migrations list openmausbot-composio --remote"));
+ const deployStep = rest.find((step) => (step as { uses?: string }).uses?.startsWith("cloudflare/wrangler-action@")) as { with?: Record<string, string> } | undefined;
+ expect(migrations).toBeGreaterThan(-1);
+ expect(migrations).toBeLessThan(rest.indexOf(deployStep as never));
+ expect(deployStep?.with?.command).toContain('--message "main ${{ github.sha }}');
// The broker is typechecked and tested in the same checkout it deploys.
const runs = rest.map((step) => step.run);
const deploy = rest.findIndex((step) => (step as { uses?: string }).uses?.startsWith("cloudflare/wrangler-action@"));