.github/workflows: check commit description format

Check PR commit subjects for the standard format we use "pkg/name: description of the change".
Check PR commit bodies for at most 120 characters.
This commit is contained in:
Dmitry Vyukov 2020-07-31 12:07:23 +02:00
parent 53dd7c4e25
commit d895b3be2c
5 changed files with 64 additions and 2 deletions

View File

@ -15,6 +15,9 @@ jobs:
uses: actions/checkout@v2
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:
# https://help.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows#using-the-cache-action
@ -25,6 +28,8 @@ jobs:
key: cache
# Run make presubmit_smoke.
- name: run
env:
GITHUB_PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
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

View File

@ -102,7 +102,7 @@ endif
bin/syz-extract bin/syz-fmt \
extract generate generate_go generate_sys \
format format_go format_cpp format_sys \
tidy test test_race check_copyright check_language check_links check_diff \
tidy test test_race check_copyright check_language check_links check_diff check_commits \
presubmit presubmit_parallel clean
all: host target
@ -265,7 +265,7 @@ presubmit:
presubmit_smoke:
$(MAKE) generate
$(MAKE) -j100 check_diff check_copyright check_language check_links presubmit_build
$(MAKE) -j100 check_commits check_diff check_copyright check_language check_links presubmit_build
$(MAKE) test
presubmit_build:
@ -342,6 +342,9 @@ check_copyright:
check_language:
./tools/check-language.sh
check_commits:
./tools/check-commits.sh
check_links:
python ./tools/check_links.py $$(pwd) $$(ls ./*.md; find ./docs/ -name '*.md')

View File

@ -33,6 +33,15 @@ the problem you are solving and how it is solved.
`dir/path` is a relative path to the main dir this commit changes
(look at examples in the [commit history](https://github.com/google/syzkaller/commits/master)).
If several packages/dirs are significantly affected, then the following format is allowed:
```
dir1/path1, dir2/path2: one-line description
```
Though, dirs should not be included if they have only minor changes.
For pervasive changes the following format is allowed:
```
all: one-line description
```
Please pay attention to punctuation. In particular:
@ -40,6 +49,8 @@ Please pay attention to punctuation. In particular:
- There is *no dot* at the end of `one-line description`.
- `Extended multi-line description` is full English sentences with Capital letters and dots.
Commit message line length is limited to 120 characters.
Also:
- If you commit fixes an issue, please include `Fixes #NNN` line into commit message

42
tools/check-commits.sh Executable file
View File

@ -0,0 +1,42 @@
#!/usr/bin/env bash
# Copyright 2020 syzkaller project authors. All rights reserved.
# Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
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
fi
fi
COMMITS=0
FAILED=""
HASHES=$(git log --format="%h" ${GITHUB_PR_BASE_SHA}..HEAD)
for HASH in ${HASHES}; do
((COMMITS+=1))
SUBJECT=$(git show --format="%s" --no-patch ${HASH})
BODY=$(git show --format="%B" --no-patch ${HASH})
if ! [[ ${SUBJECT} =~ ^(([a-z0-9/_.-]+|Makefile|CONTRIBUTORS|README.md)(, )?)+:\ [a-z].+[^.]$ ]]; then
echo "##[error]Wrong commit subject format: '${SUBJECT}'.\
Please use 'main/affected/package: short change description'.\
See docs/contributing.md for details."
FAILED="1"
fi
LONGLINE='[^\
]{121}'
if [[ ${BODY} =~ ${LONGLINE} ]]; then
echo "##[error]Please limit commit description line length to 120 characters."
echo "${BODY}"
FAILED="1"
fi
done
if [ "$FAILED" != "" ]; then exit 1; fi
echo "$COMMITS commits checked for format style"

View File

@ -64,6 +64,7 @@ docker run \
--env FUZZIT_API_KEY \
--env GITHUB_REF \
--env GITHUB_SHA \
--env GITHUB_PR_BASE_SHA \
--env CI \
${DOCKERARGS[@]} \
gcr.io/syzkaller/${IMAGE} -c "$COMMAND"