name: OpenSSF Scorecard
on:
  # Run on pushes to main/default branch only
  branch_protection_rule:
  push:
    branches: [ "main" ]
  schedule:
    # Weekly Saturday at 01:30 UTC
    - cron: '30 1 * * 6'

# Least-privilege: read-all at workflow level, override per job
permissions: read-all

jobs:
  analysis:
    name: Scorecard analysis
    runs-on: ubuntu-latest
    permissions:
      # Required to publish results via OIDC
      id-token: write
      # Required to upload SARIF to code-scanning
      security-events: write
      actions: read
      contents: read

    steps:
      - name: "Checkout code"
        uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
        with:
          persist-credentials: false

      - name: "Run OpenSSF Scorecard"
        uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3
        with:
          results_file: results.sarif
          results_format: sarif
          # Publish results to enable badge + REST API access
          publish_results: true

      - name: "Upload SARIF artifact"
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
        with:
          name: SARIF file
          path: results.sarif
          retention-days: 5

      - name: "Upload to code-scanning"
        uses: github/codeql-action/upload-sarif@87557b9c84dde89fdd9b10e88954ac2f4248e463 # v4
        with:
          sarif_file: results.sarif
