github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/tools/check-commits.sh (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2020 syzkaller project authors. All rights reserved.
     3  # Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
     4  
     5  set -e
     6  
     7  # .github/workflows/ci.yml passes GITHUB_PR_HEAD_SHA and GITHUB_PR_COMMITS for pull requests.
     8  # That's the range we want to check for PRs. If these are not set, we check from the current HEAD
     9  # to the master branch (presumably a local run). If master does not exist (presumably CI run on
    10  # a commit into a fork tree), check HEAD commit only.
    11  GITHUB_PR_HEAD_SHA="${GITHUB_PR_HEAD_SHA:-HEAD}"
    12  if [ "${GITHUB_PR_COMMITS}" == "" ]; then
    13  	GITHUB_PR_COMMITS=`git log --oneline master..${GITHUB_PR_HEAD_SHA} | wc -l`
    14  	if [ "${GITHUB_PR_COMMITS}" == "" ] || [ "${GITHUB_PR_COMMITS}" == "0" ]; then
    15  		GITHUB_PR_COMMITS=1
    16  	fi
    17  fi
    18  
    19  COMMITS=0
    20  FAILED=""
    21  HASHES=$(git log --format="%h" -n ${GITHUB_PR_COMMITS} ${GITHUB_PR_HEAD_SHA})
    22  for HASH in ${HASHES}; do
    23  	((COMMITS+=1))
    24  	SUBJECT=$(git show --format="%s" --no-patch ${HASH})
    25  	BODY=$(git show --format="%B" --no-patch ${HASH})
    26  	PATTERN="^(Revert \"|(([a-z0-9/_.-]+|Makefile|AUTHORS|CONTRIBUTORS|README.md)(, )?)+:\ [^A-Z].+[^.]$)"
    27  	if ! [[ ${SUBJECT} =~ $PATTERN ]]; then
    28  		echo "##[error]Wrong commit subject format: '${SUBJECT}'.\
    29   Please use 'main/affected/package: short change description'.\
    30   See docs/contributing.md for details.\
    31   Regex pattern used to check commit subjects is '$PATTERN'."
    32  		FAILED="1"
    33  	fi
    34  	LONGLINE='[^\
    35  ]{121}'
    36  	# dependabot may generate descriptions longer than 120 chars
    37  	DEPENDABOT_SUBJ='^mod:\ bump'
    38  	if [[ ! ${SUBJECT} =~ ${DEPENDABOT_SUBJ} ]] && [[ ${BODY} =~ ${LONGLINE} ]] ; then
    39  		echo "##[error]Please limit commit description line length to 120 characters."
    40  		echo "${BODY}"
    41  		FAILED="1"
    42  	fi
    43  done
    44  echo "$COMMITS commits checked for format style (git log -n ${GITHUB_PR_COMMITS} ${GITHUB_PR_HEAD_SHA})"
    45  if [ "$FAILED" != "" ]; then exit 1; fi