Skip to Content
CLI ReferenceCI/CD Integration

CI/CD Integration

The Foir CLI is designed to work in automated environments. This guide covers headless authentication, applying and exporting config (foir push / foir pull) in CI, and example workflows for common platforms.

Headless Authentication

In CI/CD environments, use the FOIR_API_KEY environment variable instead of interactive OAuth login. When this variable is set, the CLI authenticates directly without requiring browser interaction.

export FOIR_API_KEY=foir_adm_abc123... foir records list page --json

You can create an API key for CI use through the CLI or the console:

# An admin key for the pipeline, holding what its jobs need foir api-keys create --name "CI pipeline" --kind admin --grants records:read,records:write

Store the returned key as a secret in your CI platform (e.g., GitHub Actions secrets, GitLab CI variables). An admin key expires after 90 days unless you set --expires-in, and foir api-keys renew <key-id> keeps it with the same secret, so the stored secret needs no change.

If you need to authenticate as a user from a headless machine (SSH session, container, or CI shell) rather than with an API key, run foir login --device. This uses the device flow: the CLI prints a short code and a URL you approve from a browser on any device — no local browser or callback server is required. It is auto-selected when no local browser is detected.

Environment Variables

These environment variables configure the CLI in CI environments:

VariableDescriptionRequired
FOIR_API_KEYAPI key for authenticationYes
FOIR_API_URLOverride the API endpoint the CLI connects to (default: https://rpc.foir.io). --api-url wins over itNo
FOIR_STORAGE_URLOverride the storage endpoint URL. From CLI 0.70.0 it defaults to the resolved API URL; on 0.69.0 and earlier set it to your API URL explicitlyNo
FOIR_PROJECTThe named project to act in, where foir.config.ts declares several. Required there: there is no defaultWhere named projects are declared

Applying and Exporting Config in CI

The CLI manages your project’s config-as-code in two directions:

  • foir push applies a local foir.config.ts to the platform — registering or updating models, operations, hooks, schedules, and other declared resources. This is the command you run in CI to keep the platform in sync with source control.
  • foir pull exports the platform’s current state of a config back into a local foir.config.ts. Use it to capture changes a manager made in the dashboard so they land in source control. It writes config only — there is no code/type generation step.

Both authenticate via FOIR_API_KEY in CI. See the push and pull references for the full flag list.

# Apply config-as-code to the platform FOIR_API_KEY=$FOIR_API_KEY foir push # Apply and publish updated resources in one step FOIR_API_KEY=$FOIR_API_KEY foir push --publish

GitHub Actions Examples

Apply Config on Merge

Run foir push as part of your pipeline so merges to main reconcile the platform with your foir.config.ts:

# .github/workflows/push-config.yml name: Push Config on: push: branches: [main] paths: ['foir.config.ts'] jobs: push: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: '20' cache: 'npm' - run: npm ci - name: Push config to platform env: FOIR_API_KEY: ${{ secrets.FOIR_API_KEY }} run: npx @foir/cli push --publish

Seed Content from Repository

Push content files to the platform whenever they change:

# .github/workflows/seed-content.yml name: Seed Content on: push: branches: [main] paths: ['content/**'] jobs: seed: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: '20' - name: Install Foir CLI run: npm install -g @foir/cli - name: Seed records env: FOIR_API_KEY: ${{ secrets.FOIR_API_KEY }} run: | for f in content/*.json; do echo "Creating record from $f" foir records create page --file "$f" --json done

Sync Dashboard Edits Back to Source

Use a cron-triggered workflow to export platform changes (made by managers in the dashboard) back into foir.config.ts and open a PR / commit them:

# .github/workflows/sync-config.yml name: Sync Config on: schedule: - cron: '0 6 * * 1-5' # Weekdays at 6 AM UTC workflow_dispatch: jobs: sync: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: '20' cache: 'npm' - run: npm ci - name: Export config from Foir env: FOIR_API_KEY: ${{ secrets.FOIR_API_KEY }} run: npx @foir/cli pull --force - name: Check for changes id: changes run: | if [ -n "$(git status --porcelain foir.config.ts)" ]; then echo "has_changes=true" >> $GITHUB_OUTPUT fi - name: Commit and push if: steps.changes.outputs.has_changes == 'true' run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git add foir.config.ts git commit -m "chore: sync foir.config.ts from platform" git push

Staging and Production as Named Projects

When one config declares a staging and a production project, the pipeline promotes a commit the way it promotes code: push it to staging and release it there, exercise it, then push the same commit to production and release it when you are ready. Nothing is copied between the projects; each push applies the checked-out config to the project it names.

A push writes drafts. Production keeps serving what it served until a release carries them (see Schema Publishing), so the production job below pushes, and a second job, held for approval, releases.

# .github/workflows/promote.yml on: push: branches: [main] jobs: staging: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: npm ci - run: npx foir push --project staging --publish --allow-delete env: FOIR_API_KEY: ${{ secrets.FOIR_STAGING_API_KEY }} production: needs: staging runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: npm ci # Drafts only: production serves what it served until the release below. - run: npx foir push --project production env: FOIR_API_KEY: ${{ secrets.FOIR_PRODUCTION_API_KEY }} release: needs: production runs-on: ubuntu-latest # A GitHub environment with required reviewers holds this job for approval. environment: production steps: - uses: actions/checkout@v4 - run: npm ci - run: npx foir release status --project production env: FOIR_API_KEY: ${{ secrets.FOIR_PRODUCTION_API_KEY }} - run: npx foir release publish --project production env: FOIR_API_KEY: ${{ secrets.FOIR_PRODUCTION_API_KEY }}

If the release turns out wrong, foir release rollback <id> --project production puts back exactly what it replaced. An urgent change (closing sign-up, turning a provider off) is a push and a release in one step: foir push --project production --publish.

What makes this safe to automate:

  • A bare push refuses. With named projects declared, foir push without --project or FOIR_PROJECT exits non-zero and lists the names. A job that forgot to say where it pushes fails rather than guessing.
  • A swapped key fails. An API key belongs to one project, and the platform refuses a request whose key belongs to another project than the one --project names, with both named. A production job holding the staging key stops at its first command.
  • The projects stay identical. Every push resolves the config for every declared project and refuses if any two differ outside their destinations (endpoints, redirect URIs, origins, sender addresses), naming the field. A config cannot give staging a different model or quota by accident.
  • Keys stay in their own files. Each project declares its envFile, and a push writes that project’s minted keys and signing secrets there and nowhere else.
  • Drift fails the push. A model, operation, hook, schedule or context dimension added in a project’s console, and declared by no config, fails that project’s next push and is named. Declare it, or push with --prune to delete it (with --allow-delete in CI).
  • You can ask what each project holds. Each push records the hash of the manifest it applied, taken without destinations. foir projects status reads every project’s hash and drift and prints them side by side, and says which projects hold the checked-out config:
foir projects status --json | jq -r '.summary' # staging is ahead of production: it holds this config, and production holds another.

projects status reads every declared project in one run, so it needs a signed-in session (foir login); an API key belongs to one project and is refused there.

Tips

  • Use --json for scripting. When parsing CLI output in scripts, always use the --json flag to get structured output instead of the human-readable table format.
  • Use --quiet for pipelines. When you only need IDs (e.g., to pipe into another command), --quiet outputs one ID per line with no other formatting.
  • Pin the CLI version. Don’t install it globally at a number written into a script, which rots the moment anyone forgets to update it. Add @foir/cli as a devDependency and run it through your lockfile, so the version CI uses is the one your repository already agreed on and Dependabot can move it like anything else.
  • Use npx to avoid global installs. If the CLI is a dev dependency, npx @foir/cli runs it without a global install step.
Last updated on