summaryrefslogtreecommitdiffstats
path: root/.github/workflows/require-changelog-for-PRs.yml
blob: 1443e883cf3fe57791339e3d8fc352d101840a34 (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
41
42
43
name: Changelog

on:
  pull_request:

jobs:
  check-changelog:
    name: Check for changelog entry
    runs-on: ubuntu-latest
    # dependabot PRs are automerged if CI passes; we shouldn't block these
    if: github.actor != 'dependabot[bot]'
    env:
      PR_NUMBER: ${{ github.event.number }}
      PR_BASE: ${{ github.base_ref }}
    steps:
      - uses: actions/checkout@v4
      - name: Fetch PR base
        run: git fetch --no-tags --prune --depth=1 origin

      # 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/sharkdp/bat/pulls/${PR_NUMBER} | jq -r '"submitter=" + .user.login' | tee -a $GITHUB_OUTPUT

      - name: Search for added line in changelog
        env:
          PR_SUBMITTER: ${{ steps.get-submitter.outputs.submitter }}
        run: |
          ADDED=$(git diff -U0 "origin/${PR_BASE}" HEAD -- CHANGELOG.md | grep -P '^\+[^\+].+$')
          echo "Added lines in CHANGELOG.md:"
          echo "$ADDED"

          escape_regex_meta_chars() {
            # https://stackoverflow.com/a/16951928/4473405
            sed 's/[][\.|$(){}?+*^]/\\&/g' <<< "$*"
          }

          double_escape_slash_for_bash() {
            sed 's/\\/\\\\/g' <<< "$*"
          }

          echo "Grepping for PR info:"
          grep "#${PR_NUMBER}\\b.*[(]@$(quote ${PR_SUBMITTER})[)]" <<< "$ADDED"