Merge pull request #15731 from miri64/dist/enh/pr_check-annotate

dist/tools/pr_check: cleanup and annotate errors in Github Action
This commit is contained in:
Kevin "Tristate Tom" Weiss 2021-01-13 15:24:13 +01:00 committed by GitHub
commit aa19614a6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 61 deletions

View File

@ -32,8 +32,5 @@ jobs:
run:
git fetch origin '${{ github.base_ref }}:${{ github.base_ref }}'
- name: Run checks
env: # enforce deactivation of label check in pr_check
TRAVIS_PULL_REQUEST:
CI_PULL_NR:
run: |
./dist/tools/${{ matrix.check }}/check.sh "${{ github.base_ref }}"

View File

@ -1,18 +1,17 @@
# About
This script checks if a Pull Request needs squashing or if it is waiting for
another Pull Request.
This script checks if a Pull Request needs squashing.
# Usage
```bash
./check.sh [<master branch>]
./check.sh [<branch>]
```
The optional `<master branch>` parameter refers to the branch the pull request's
branch branched from. The script will output all commits marked as squashable
from `HEAD` to the merge-base with `<master branch>`. The default for
`<master branch>` is `master`.
The `<branch>` parameter refers to the branch the pull request's branch branched
from. The script will output all commits marked as squashable from `HEAD` to the
merge-base with `<branch>`. The default for `<branch>` is `master`.
A commit is marked as squashable if it contains the keywords SQUASH or FIX
(case insensitive) within the first five characters of it's subject title.
A commit is marked as squashable if it contains the keywords SQUASH, FIX or
REMOVE ME (case insensitive) within the first five characters of it's subject
title.

View File

@ -7,14 +7,17 @@
# directory for more details.
#
. "$(dirname "$0")/../ci/github_annotate.sh"
: "${RIOTBASE:=$(cd $(dirname $0)/../../../; pwd)}"
cd $RIOTBASE
: "${RIOTTOOLS:=${RIOTBASE}/dist/tools}"
. "${RIOTTOOLS}"/pr_check/check_labels.sh
EXIT_CODE=0
github_annotate_setup
if tput colors &> /dev/null && [ $(tput colors) -ge 8 ]; then
CERROR="\e[1;31m"
CRESET="\e[0m"
@ -40,21 +43,24 @@ SQUASH_COMMITS="$(git log $(git merge-base HEAD "${RIOT_MASTER}")...HEAD --prett
keyword_filter)"
if [ -n "${SQUASH_COMMITS}" ]; then
echo -e "${CERROR}Pull request needs squashing:${CRESET}" 1>&2
echo -e "${SQUASH_COMMITS}"
if github_annotate_is_on; then
echo "${SQUASH_COMMITS}" | while read commit; do
ANNOTATION="Commit needs to be squashed: \"${commit}\""
ANNOTATION="${ANNOTATION}\n\nPLEASE ONLY SQUASH WHEN ASKED BY A "
ANNOTATION="${ANNOTATION}MAINTAINER!"
ANNOTATION="${ANNOTATION}\nSee: "
ANNOTATION="${ANNOTATION}https://github.com/RIOT-OS/RIOT/blob/master/CONTRIBUTING.md#squash-commits-after-review"
github_annotate_error_no_file "${ANNOTATION}"
done
else
echo -e "${CERROR}Pull request needs squashing:${CRESET}" 1>&2
echo -e "${SQUASH_COMMITS}"
fi
EXIT_CODE=1
fi
if [ -n "$TRAVIS_PULL_REQUEST" -o -n "$CI_PULL_NR" ]; then
if check_gh_label "CI: needs squashing"; then
echo -e "${CERROR}Pull request needs squashing according to its labels set on GitHub${CRESET}"
EXIT_CODE=1
fi
github_annotate_teardown
if check_gh_label "State: waiting for other PR"; then
echo -e "${CERROR}Pull request is waiting for another pull request according to its labels set on GitHub${CRESET}"
EXIT_CODE=1
fi
fi
github_annotate_report_last_run
exit ${EXIT_CODE}

View File

@ -1,36 +0,0 @@
#!/usr/bin/env bash
#
# Copyright (C) 2014 Martine Lenders <mlenders@inf.fu-berlin.de>
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
#
# The following script part has been moved here from:
# ./dist/tools/pr_check/check.sh
GITHUB_API_HOST="https://api.github.com"
GITHUB_REPO="RIOT-OS/RIOT"
if which wget &> /dev/null; then
GET="wget -O -"
elif which curl &> /dev/null; then
GET="curl"
else
echo "Script needs wget or curl" >&2
exit 2
fi
if [ -n "$TRAVIS_PULL_REQUEST" ]; then
LABELS_JSON=$(${GET} "${GITHUB_API_HOST}/repos/${GITHUB_REPO}/issues/${TRAVIS_PULL_REQUEST}/labels" 2> /dev/null)
elif [ -n "$CI_PULL_LABELS" ]; then
LABELS_JSON="$CI_PULL_LABELS"
fi
check_gh_label() {
LABEL="${1}"
echo "${LABELS_JSON}" | grep -q "${LABEL}"
return $?
}