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 | |
| 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.
| -rw-r--r-- | .github/workflows/ci.yml | 3 | ||||
| -rwxr-xr-x | tools/check-commits.sh | 21 | ||||
| -rwxr-xr-x | tools/syz-env | 2 |
3 files changed, 14 insertions, 12 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b4119e33..aab76bb79 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,6 @@ jobs: with: path: gopath/src/github.com/google/syzkaller # This is needed for tools/check-commits.sh - ref: ${{ github.event.pull_request.head.sha }} fetch-depth: 100 # Caches everything in .cache dir, in partiuclar we want to cache go-build and golangci-lint stuff. # For reference see: @@ -29,7 +28,9 @@ jobs: # Run make presubmit_smoke. - name: run env: + GITHUB_PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} GITHUB_PR_BASE_SHA: ${{ github.event.pull_request.base.sha }} + GITHUB_PR_COMMITS: ${{ github.event.pull_request.commits }} run: gopath/src/github.com/google/syzkaller/.github/workflows/run.sh syz-env make presubmit_smoke # Upload coverage report to codecov.io. For reference see: # https://github.com/codecov/codecov-action/blob/master/README.md 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}) diff --git a/tools/syz-env b/tools/syz-env index a6ffd0877..07cc32186 100755 --- a/tools/syz-env +++ b/tools/syz-env @@ -64,7 +64,9 @@ docker run \ --env FUZZIT_API_KEY \ --env GITHUB_REF \ --env GITHUB_SHA \ + --env GITHUB_PR_HEAD_SHA \ --env GITHUB_PR_BASE_SHA \ + --env GITHUB_PR_COMMITS \ --env CI \ ${DOCKERARGS[@]} \ gcr.io/syzkaller/${IMAGE} -c "$COMMAND" |
