2020-07-31 10:07:23 +00:00
|
|
|
#!/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
|
|
|
|
|
2020-08-06 06:28:18 +00:00
|
|
|
# .github/workflows/ci.yml passes GITHUB_PR_HEAD_SHA and GITHUB_PR_COMMITS for pull requests.
|
2020-08-05 06:32:06 +00:00
|
|
|
# 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.
|
2020-08-06 06:28:18 +00:00
|
|
|
GITHUB_PR_HEAD_SHA="${GITHUB_PR_HEAD_SHA:-HEAD}"
|
2020-08-05 06:32:06 +00:00
|
|
|
if [ "${GITHUB_PR_COMMITS}" == "" ]; then
|
2020-08-06 06:28:18 +00:00
|
|
|
GITHUB_PR_COMMITS=`git log --oneline master..${GITHUB_PR_HEAD_SHA} | wc -l`
|
2020-08-05 06:32:06 +00:00
|
|
|
if [ "${GITHUB_PR_COMMITS}" == "" ] || [ "${GITHUB_PR_COMMITS}" == "0" ]; then
|
|
|
|
GITHUB_PR_COMMITS=1
|
2020-07-31 10:07:23 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
COMMITS=0
|
|
|
|
FAILED=""
|
2020-08-06 06:28:18 +00:00
|
|
|
HASHES=$(git log --format="%h" -n ${GITHUB_PR_COMMITS} ${GITHUB_PR_HEAD_SHA})
|
2020-07-31 10:07:23 +00:00
|
|
|
for HASH in ${HASHES}; do
|
|
|
|
((COMMITS+=1))
|
|
|
|
SUBJECT=$(git show --format="%s" --no-patch ${HASH})
|
|
|
|
BODY=$(git show --format="%B" --no-patch ${HASH})
|
2020-08-06 07:11:14 +00:00
|
|
|
if ! [[ ${SUBJECT} =~ ^(Revert \"|(([a-z0-9/_.-]+|Makefile|CONTRIBUTORS|README.md)(, )?)+:\ [a-z].+[^.]$) ]]; then
|
2020-07-31 10:07:23 +00:00
|
|
|
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
|
2020-08-06 06:28:18 +00:00
|
|
|
echo "$COMMITS commits checked for format style (git log -n ${GITHUB_PR_COMMITS} ${GITHUB_PR_HEAD_SHA})"
|
2020-07-31 10:07:23 +00:00
|
|
|
if [ "$FAILED" != "" ]; then exit 1; fi
|