How-to guides/GitHub Actions integration

GitHub Actions integration

Edit on GitHub ↗

Run Privateer in CI, inject secrets, and upload SARIF to the Security tab.

Basic pipeline

name: Privateer Validation

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

jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install Privateer
        run: |
          /bin/bash -c "$(curl -sSL https://raw.githubusercontent.com/privateerproj/pvtr/main/install.sh)"

      - name: Install plugin
        run: pvtr install openssf/github-repo

      - name: Run validation
        env:
          PVTR_VARS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: pvtr run -c config.yml

      - name: Upload results
        uses: actions/upload-artifact@v4
        if: always()       # upload even on validation failure
        with:
          name: privateer-results
          path: evaluation_results/

The if: always() on the upload step is important: without it, a validation failure (non-zero exit) prevents result files from being archived.

Injecting secrets

Commit config.yml without secrets and pass each one as a PVTR_VARS_<KEY> environment variable on the run step, as the pipeline above does for token:

- name: Run Privateer
  env:
    PVTR_VARS_TOKEN: ${{ secrets.MY_TOKEN }}
  run: pvtr run -c config.yml

This needs pvtr 0.24.3 or later and a plugin built on privateer-sdk v1.35.0 or later; for the GitHub repo scanner that is a release after v0.33.2. The configuration reference has the naming rules and precedence.

Skipping on documentation-only changes

- name: Detect code changes
  id: filter
  run: |
    FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -v '\.md$' || true)
    if [ -z "$FILES" ]; then
      echo "code=false" >> "$GITHUB_OUTPUT"
    else
      echo "code=true" >> "$GITHUB_OUTPUT"
    fi

- name: Run Privateer
  if: steps.filter.outputs.code == 'true'
  run: pvtr run -c config.yml

SARIF upload for the GitHub Security tab

- name: Run Privateer (SARIF output)
  run: pvtr run -c config.yml
  # config.yml must set: output: sarif

- name: Upload SARIF
  uses: github/codeql-action/upload-sarif@v3
  if: always()
  with:
    sarif_file: evaluation_results/