Skip to content

Use the CLI in CI

The CLI is built to run unattended. In CI you authenticate with a token, deploy without a browser, and rely on exit codes instead of parsing output.

1. Create a token

In the dashboard, go to Settings → Tokens and create a token for the project or team you want CI to act as. Copy the value; it is shown once.

2. Store it as a secret

Add the token to your CI provider’s secrets (for GitHub, Settings → Secrets and variables → Actions) as YOFIX_TOKEN. Every command reads this variable automatically, and a variable is safer than --token because it never lands in a process list or log.

3. Deploy in the pipeline

.github/workflows/preview.yml
name: Preview deploy
on: [push]
jobs:
preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # full history so the branch label is correct
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm install -g @yofix/cli
- name: Deploy preview
env:
YOFIX_TOKEN: ${{ secrets.YOFIX_TOKEN }}
run: yofix deploy --no-wait --json > deploy.json
- name: Show the preview URL
run: jq -r '.data.previewUrl' deploy.json

Deploy to production from your default branch by gating on the ref and adding --prod:

- name: Deploy production
if: github.ref == 'refs/heads/main'
env:
YOFIX_TOKEN: ${{ secrets.YOFIX_TOKEN }}
run: yofix deploy --prod

Waiting versus not waiting

  • Use --no-wait when a later job (or the YoFix PR comment) reports the result, and you just want to enqueue the build.
  • Drop --no-wait when the pipeline should fail if the build fails. A waiting deploy exits non-zero on a failed build, so the job turns red automatically.
Terminal window
yofix deploy --prod --timeout 900 # block up to 15 minutes, fail if the build fails

Branching on the outcome

Exit codes are stable, so you can react to specific failures:

Terminal window
# CI shells run with `set -e`, so capture the status instead of letting a
# non-zero `yofix deploy` abort the step before the `case` runs.
status=0
yofix deploy --prod || status=$?
case $status in
0) echo "Deployed" ;;
10) echo "Build failed"; exit 1 ;; # YF_DEPLOY_BUILD_FAILED
7) echo "Quota reached"; exit 1 ;; # YF_QUOTA_EXCEEDED
*) echo "Unexpected failure"; exit 1 ;;
esac

Or parse the JSON envelope when you need detail:

Terminal window
yofix ls --json | jq -r '.data[] | "\(.status)\t\(.previewUrl)"'

See the full table in Global options and output.

Next