> ## Documentation Index
> Fetch the complete documentation index at: https://docs.finalsay-hitl.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CI and GitHub Actions

> Gate a deploy or release job on a human answer.

The [CLI](https://docs.finalsay-hitl.com/integrations/cli.md) turns a person's answer into an exit code, so any CI system can gate a step on it: the job
continues on approval and fails otherwise.

## GitHub Actions

Store the API key as a secret and the agent ID as a variable, then add a step before the risky one:

```yaml .github/workflows/deploy.yml theme={"theme":{"light":"github-light","dark":"vesper"}}
- name: Ask before deploying
  env:
    FINALSAY_API_KEY: ${{ secrets.FINALSAY_API_KEY }}
    FINALSAY_AGENT_ID: ${{ vars.FINALSAY_AGENT_ID }}
    COMMIT_MSG: ${{ github.event.head_commit.message }}
  run: |
    npx finalsay ask "Deploy ${GITHUB_SHA::7} to production?" \
      -c "$COMMIT_MSG" \
      --request-id "deploy-${GITHUB_SHA}-${GITHUB_RUN_ATTEMPT}" \
      --wait --max-wait 900

- name: Deploy
  run: ./deploy.sh
```

* Pass untrusted text (like the commit message) through an **environment variable**, never straight into the script,
  so it can't inject shell commands.
* `--request-id` makes a re-run of the same attempt reuse the approval instead of asking again.
* `--max-wait` should be shorter than the job's timeout. If it's reached, the CLI exits `6` and the approval stays open;
  someone can still answer, and a re-run picks it up.

## Branching on the answer

Any exit code other than `0` fails the step. To do different things per answer, read the exit code or the JSON:

```sh theme={"theme":{"light":"github-light","dark":"vesper"}}
set +e
finalsay ask "Release 4.2?" -c "$NOTES" \
  -o "Release=release" -o "Release to beta=beta" -o "Hold=hold" \
  --wait --json > answer.json
code=$?
set -e

case "$code" in
  0) ./release.sh stable ;;
  3)
    if [ "$(jq -r .selected_option_value answer.json)" = "beta" ]; then ./release.sh beta
    else echo "On hold"; exit 1
    fi ;;
  4) echo "Reviewer said: $(jq -r .custom_instruction answer.json)"; exit 1 ;;
  *) echo "Not approved (exit $code)"; exit 1 ;;
esac
```

## Other CI systems

GitLab CI, CircleCI, Buildkite and Jenkins work the same way: install Node.js 20+, set `FINALSAY_API_KEY` and
`FINALSAY_AGENT_ID` from your secret store, and run `npx finalsay ask … --wait`. See [exit codes](https://docs.finalsay-hitl.com/integrations/cli.md#exit-codes).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.