Safeguard Docs
CI/CD Integration

GitHub Actions

Scan every push and pull request in GitHub Actions with Safeguard, and fail the workflow on vulnerabilities

GitHub Actions

1. Add the secret

Create a secret key in Safeguard under Settings โ†’ Developer with the scopes scans:trigger and scans:read. In GitHub, add it under Settings โ†’ Secrets and variables โ†’ Actions โ†’ New repository secret with the name SAFEGUARD_API_KEY. An organisation secret works too.

2. Add the workflow

Save this as .github/workflows/safeguard.yml (download):

name: Safeguard
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - name: Safeguard scan
        env:
          SAFEGUARD_API_KEY: ${{ secrets.SAFEGUARD_API_KEY }}
          SAFEGUARD_INSTALL_DIR: ${{ runner.temp }}/safeguard-bin
        run: |
          set -eu
          curl -fsSL https://cli.safeguard.sh/install | bash
          "$SAFEGUARD_INSTALL_DIR/safeguard" ci scan --wait --fail-on critical

No checkout step is needed: Safeguard clones the repository. Push, and the run shows the scan's result and a link to it in Safeguard.

Choose the branches

  • on.push.branches lists the branches whose pushes are scanned.
  • on.pull_request.branches lists the target branches of pull requests that are scanned. Delete the pull_request block to scan pushes only.

Wildcards work, for example [main, 'release/**']. On a pull request the head branch is scanned and the version is named after its head commit.

Options

ChangeHow
Report onlyDrop --fail-on critical
Another threshold--fail-on high (or medium, low)
Fail on a policy gateAdd --fail-on-gate all
Scan on the runnerAdd - uses: actions/checkout@v4 before the step and --local to the command
A specific projectAdd --project-id <id>
Pin the CLI versionAdd SAFEGUARD_VERSION: "<version>" to env

Troubleshooting

  • Pull requests from forks fail. GitHub gives fork pull requests no secrets. Scan pushes only, or use pull_request_target with care: it runs with your secrets, so never run the fork's code in that job.
  • Other errors: see Troubleshooting.

On this page