# Every commit of a pull request is signed off under the Developer Certificate of Origin (CONTRIBUTING.md).
name: dco

on:
  pull_request:

permissions:
  contents: read

jobs:
  dco:
    name: dco
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          fetch-depth: 0
      - name: Signed-off-by on every commit
        env:
          BASE: ${{ github.event.pull_request.base.sha }}
          HEAD: ${{ github.event.pull_request.head.sha }}
        run: |
          missing=0
          for c in $(git rev-list --no-merges "$BASE..$HEAD"); do
            author="$(git log -1 --format='%an <%ae>' "$c")"
            if ! git log -1 --format=%B "$c" | grep -qiF "Signed-off-by: $author"; then
              echo "::error::$(git log -1 --format='%h %s' "$c"): no Signed-off-by: $author"
              missing=1
            fi
          done
          exit "$missing"
