diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-08-05 08:32:06 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-08-05 09:18:56 +0200 |
| commit | b712935571355df44e126c5b27c98ccd53d1d18b (patch) | |
| tree | 8d5e23736a01dd3c852c5578a82c52f123f027f8 /tools/check-commits.sh | |
| parent | 09121a7396578abef95aec720b7cee24debf9b0d (diff) | |
tools/check-commits.sh: fix commit range detection
We currently check from github.event.pull_request.base.sha
to github.event.pull_request.head.sha, but they may be in
different branches if the PR commits are branched not from
the latest master HEAD (at the time of PR creation).
Then GH will create a merge commit, and the range we try
to check is not valid.
Check github.event.pull_request.commits commits backwards
from github.event.pull_request.head.sha commit.
Diffstat (limited to 'tools/check-commits.sh')
| -rwxr-xr-x | tools/check-commits.sh | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/tools/check-commits.sh b/tools/check-commits.sh index e2734d3dd..aa06eed5a 100755 --- a/tools/check-commits.sh +++ b/tools/check-commits.sh @@ -4,22 +4,21 @@ set -e -# GITHUB_PR_BASE_SHA is exported in .github/workflows/ci.yml for pull requests. -# If it is not set, check against refs/heads/master (presumably a local run), -# otherwise skip the checks (presumably CI run on a fork commit). -if [ "${GITHUB_PR_BASE_SHA}" == "" ]; then - GITHUB_PR_BASE_SHA="refs/heads/master" - HAVE_MASTER=0 - git show-ref ${GITHUB_PR_BASE_SHA} 1>/dev/null 2>&1 || HAVE_MASTER=$? - if [[ HAVE_MASTER -ne 0 ]]; then - echo "skipping commit checks: GITHUB_PR_BASE_SHA is not set and ${GITHUB_PR_BASE_SHA} does not exist" - exit 0 +# .github/workflows/ci.yml passes GITHUB_PR_BASE_SHA and GITHUB_PR_COMMITS for pull requests. +# That's the range we want to check for PRs. If these are not set, we check from the current HEAD +# to the master branch (presumably a local run). If master does not exist (presumably CI run on +# a commit into a fork tree), check HEAD commit only. +GITHUB_PR_BASE_SHA="${GITHUB_PR_BASE_SHA:-HEAD}" +if [ "${GITHUB_PR_COMMITS}" == "" ]; then + GITHUB_PR_COMMITS=`git log --oneline master..${GITHUB_PR_BASE_SHA} | wc -l` + if [ "${GITHUB_PR_COMMITS}" == "" ] || [ "${GITHUB_PR_COMMITS}" == "0" ]; then + GITHUB_PR_COMMITS=1 fi fi COMMITS=0 FAILED="" -HASHES=$(git log --format="%h" ${GITHUB_PR_BASE_SHA}..HEAD) +HASHES=$(git log --format="%h" -n ${GITHUB_PR_COMMITS} ${GITHUB_PR_BASE_SHA}) for HASH in ${HASHES}; do ((COMMITS+=1)) SUBJECT=$(git show --format="%s" --no-patch ${HASH}) |
