summaryrefslogtreecommitdiffstats
path: root/.github/workflows/require-changelog-for-PRs.yml
blob: 0f126cf96388821f70ea05290997be850d2bb4e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
name: Changelog

on:
  pull_request:

jobs:
  get-submitter:
    name: Get the username of the PR submitter
    runs-on: ubuntu-latest
    outputs:
      submitter: ${{ steps.get-submitter.outputs.submitter }}
    steps:
      # cannot use `github.actor`: the triggering commit may be authored by a maintainer
      - name: Get PR submitter
        id: get-submitter
        run: curl -sSfL https://api.github.com/repos/imsnif/bandwhich/pulls/${PR_NUMBER} | jq -r '"submitter=" + .user.login' | tee -a $GITHUB_OUTPUT  

  check-changelog:
    name: Check for changelog entry
    needs: get-submitter
    env:
      PR_NUMBER: ${{ github.event.number }}
      PR_SUBMITTER: ${{ needs.get-submitter.outputs.submitter }}
      PR_BASE: ${{ github.base_ref }}
    runs-on: ubuntu-latest
    # allow dependabot PRs to have no changelog
    if: ${{ needs.get-submitter.outputs.submitter != 'dependabot[bot]' }}
    steps:
      - uses: actions/checkout@v4

      - name: Fetch PR base
        run: git fetch --no-tags --prune --depth=1 origin

      - name: Search for added line in changelog
        run: |
          ADDED=$(git diff -U0 "origin/${PR_BASE}" HEAD -- CHANGELOG.md | grep -P '^\+[^\+].+$')
          echo "Added lines in CHANGELOG.md:"
          echo "$ADDED"
          echo "Grepping for PR info:"
          grep -P "(#|pull/)${PR_NUMBER}\\b.*@${PR_SUBMITTER}\\b" <<< "$ADDED"