name: SLSA Provenance
on:
  release:
    types: [published]

permissions:
  contents: read

jobs:
  provenance:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      id-token: write
      attestations: write
    steps:
      - uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
        with:
          egress-policy: audit
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          ref: ${{ github.event.release.tag_name }}
          persist-credentials: false
      - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
        with:
          node-version: 22
      - run: npm ci --ignore-scripts
      - run: npm run build
      - id: attest
        uses: actions/attest-build-provenance@0f67c3f4856b2e3261c31976d6725780e5e4c373 # v4.1.1
        with:
          subject-path: 'dist/purify.js,dist/purify.min.js,dist/purify.cjs.js,dist/purify.es.mjs'
      - name: Upload provenance to release
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          BUNDLE_PATH: ${{ steps.attest.outputs.bundle-path }}
          TAG: ${{ github.event.release.tag_name }}
        run: |
          cp "$BUNDLE_PATH" "${TAG}.intoto.jsonl"
          gh release upload "$TAG" "${TAG}.intoto.jsonl" --clobber
