Skip to main content
All recipes

CircleCI

APIREST APIDeployment check

Run the deployment API check from a CircleCI context containing your token and service slugs. Make deployment require this job to prevent a failed check from being ignored.

1. Save the deployment check

Save this as scripts/check-upstream.mjs. It runs on Node.js 24 without additional packages.

  • CHECKUPSTREAM_API_TOKEN: a read-scoped cup_api_ token stored in CI secrets.
  • CHECKUPSTREAM_SERVICES: comma-separated slugs your organization tracks, such as stripe,openai.
scripts/check-upstream.mjs
const token = process.env.CHECKUPSTREAM_API_TOKEN;
const services = process.env.CHECKUPSTREAM_SERVICES;
if (!token || !services?.trim()) {
  throw new Error("Set CHECKUPSTREAM_API_TOKEN and CHECKUPSTREAM_SERVICES in CI");
}

const url = new URL(
  "/api/v1/deploy-gate",
  process.env.CHECKUPSTREAM_BASE_URL || "https://checkupstream.com",
);
url.searchParams.set("services", services);
const response = await fetch(url, {
  headers: { Authorization: `Bearer ${token}` },
  signal: AbortSignal.timeout(20_000),
});
if (!response.ok) throw new Error(`Deployment check failed: HTTP ${response.status}`);

const gate = await response.json();
console.log(JSON.stringify(gate, null, 2));
if (
  gate?.safe !== true ||
  !Number.isInteger(gate.totalServicesChecked) ||
  gate.totalServicesChecked <= 0
) {
  process.exitCode = 1;
}

2. Add the CircleCI job

Create a checkupstream context with both variables and restrict its use to the appropriate project and branch. Add requires: [check-upstream] to your deployment job.

.circleci/config.yml
version: 2.1

jobs:
  check-upstream:
    docker:
      - image: cimg/node:24.0
    steps:
      - checkout
      - run:
          name: Check selected vendors
          command: node scripts/check-upstream.mjs

workflows:
  deployment-check:
    jobs:
      - check-upstream:
          context: checkupstream
          filters:
            branches:
              only: main

Continue your setup

Review the endpoints and credentials used by your integration.