CI: use GitHub API to exempt dependabot from changelog requirement (#378)

* CI: use GitHub API to exempt dependabot from changelog requirement

* Write changelog
This commit is contained in:
cyqsimon
2024-03-01 17:42:39 +08:00
committed by GitHub
parent 862ede716c
commit 1319437388
2 changed files with 17 additions and 10 deletions

View File

@@ -4,28 +4,34 @@ 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
runs-on: ubuntu-latest
# allow dependabot PRs to have no changelog
if: github.actor != 'dependabot[bot]'
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
# 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
- 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:"