name: Security analysis with zizmor

on:
  push:
    branches:
      - main
      - releases/*
    paths-ignore:
      - '**.md'
  pull_request:
    paths-ignore:
      - '**.md'
  workflow_dispatch:

permissions: {}

jobs:
  zizmor:
    name: Analyze workflows with zizmor
    runs-on: ubuntu-latest
    permissions:
      contents: read
      security-events: write # to upload SARIF results to code scanning
    steps:
      - name: Checkout repository
        uses: actions/checkout@v7
        with:
          persist-credentials: false

      - name: Set up Python
        uses: actions/setup-python@v7
        with:
          python-version: '3.x'

      - name: Install zizmor
        run: pip install zizmor

      - name: Run zizmor
        run: zizmor --format sarif .github/workflows/ > zizmor.sarif
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Upload SARIF results to code scanning
        if: always() && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
        uses: github/codeql-action/upload-sarif@v4
        with:
          sarif_file: zizmor.sarif
          category: zizmor
