Skip to main content

Overview

Two complete GitHub Actions workflows for a repo that owns shipd.config.ts. flags-diff previews flag changes on every pull request that touches the file. flags-push applies them when the change merges to main. Each authenticates with its own service account token (shipd_sa_…), so pull request jobs can read flags but never change them, and both handle the CLI’s exit codes explicitly.

What’s in it

  • @shipdit/cli is a dev dependency, so CI runs the same CLI version as your machine.
  • flags-diff.yml runs shipd diff --exit-code, writes the plan to the job summary, and checks that src/generated/flags.ts is committed.
  • flags-push.yml runs shipd push --ci and turns exit codes into errors or warnings.
  • Both jobs target project web-app, environment production.

Set up the tokens

  1. In the dashboard, go to Settings → Service accounts and click Create service account. Name it github-actions.
  2. Open the account and click Create token twice, binding both to project web-app (not to an environment). Scopes match an exact action, so flag:update does not grant flag:read: Add flag:archive to the push token only if you push with --prune. See Sync flags in CI for the reasoning.
  3. Copy each token. They are shown once.
  4. In GitHub, go to Settings → Secrets and variables → Actions and add both as repository secrets.

Files

package.json
pnpm/action-setup reads the pnpm version from packageManager.
shipd.config.ts
.github/workflows/flags-diff.yml
.github/workflows/flags-push.yml

Exit codes

The full list lives in the CLI reference.

Run it

Open a pull request that edits shipd.config.ts. The flags-diff job summary shows the plan. Merge it and flags-push applies the plan to production.

Adapt it

  • To block pull requests on any drift, including changes someone made in the dashboard, make exit code 2 fail: replace its case line with exit 2.
  • To fail the push job while an approval is pending, make exit code 5 fail the same way.
  • For more environments, copy the push job and change SHIPD_ENV. default values apply per environment. Definition fields apply to the whole project.
  • SHIPD_API_URL is required in CI. Only shipd login falls back to https://api.useshipd.com. You can also set apiUrl in .shipd/config.json.
  • Secrets are not passed to workflows triggered from forks, so flags-diff fails there. Skip the job for forks with if: github.event.pull_request.head.repo.full_name == github.repository.
  • Use --prune only after you confirm that no one manages flags in this project outside shipd.config.ts. It archives remote-only flags.

Next