build,circleci: Updates with additional checks from travis scripts.
authorTed Hess <thess@kitschensync.net>
Sat, 17 Nov 2018 20:13:19 +0000 (15:13 -0500)
committerEtienne Champetier <champetier.etienne@gmail.com>
Sun, 25 Nov 2018 03:23:34 +0000 (22:23 -0500)
Checking:
- Pull request does not contain unwanted merges
- signed-off-by tag exists and matches author
- Subject line has package name
- Author name has 'firstname lastname' (no nicknames)

Signed-off-by: Ted Hess <thess@kitschensync.net>
[Use git instead of CircleCI variables]
Signed-off-by: Etienne Champetier <champetier.etienne@gmail.com>
.circleci/config.yml

index 31705e969b3150e9323906677a1457029d28ca1d..10e4f4f1e5a067bbe0a89ccde02956243e75dea6 100644 (file)
@@ -8,6 +8,56 @@ jobs:
       - SDK_FILE: "openwrt-sdk-18.06.1-ar71xx-generic_gcc-7.3.0_musl.Linux-x86_64.tar.xz"
       - BRANCH: "openwrt-18.06"
     steps:
+      - checkout:
+          path: ~/openwrt_packages
+
+      - run:
+          name: Check changes / verify commits
+          working_directory: ~/openwrt_packages
+          command: |
+             cat >> $BASH_ENV <<EOF
+             echo_red()   { printf "\033[1;31m\$*\033[m\n"; }
+             echo_green() { printf "\033[1;32m\$*\033[m\n"; }
+             echo_blue()  { printf "\033[1;34m\$*\033[m\n"; }
+             EOF
+             source $BASH_ENV
+
+             RET=0
+             for commit in $(git rev-list HEAD ^origin/$BRANCH); do
+               echo_blue "=== Checking commit '$commit'"
+               if git show --format='%P' -s $commit | grep -qF ' '; then
+                 echo_red "Pull request should not include merge commits"
+                 RET=1
+               fi
+
+               author="$(git show -s --format=%aN $commit)"
+               if echo $author | grep -q '\S\+\s\+\S\+'; then
+                 echo_green "Author name ($author) seems ok"
+               else
+                 echo_red "Author name ($author) need to be your real name 'firstname lastname'"
+                 RET=1
+               fi
+
+               subject="$(git show -s --format=%s $commit)"
+               if echo "$subject" | grep -q -e '^[0-9A-Za-z,/_-]\+: ' -e '^Revert '; then
+                 echo_green "Commit subject line seems ok ($subject)"
+               else
+                 echo_red "Commit subject line MUST start with '<package name>: ' ($subject)"
+                 RET=1
+               fi
+
+               body="$(git show -s --format=%b $commit)"
+               sob="$(git show -s --format='Signed-off-by: %aN <%aE>' $commit)"
+               if echo "$body" | grep -qF "$sob"; then
+                 echo_green "Signed-off-by match author"
+               else
+                 echo_red "Signed-off-by is missing or doesn't match author (should be '$sob')"
+                 RET=1
+               fi
+             done
+
+             exit $RET
+
       - run:
           name: Download the SDK
           working_directory: ~/sdk
@@ -18,9 +68,6 @@ jobs:
              curl "$SDK_BASE_URL/$SDK_FILE" -sS -o "$SDK_FILE"
              sha256sum -c --ignore-missing sha256sums
 
-      - checkout:
-          path: ~/openwrt_packages
-
       - run:
           name: Prepare build_dir
           working_directory: ~/build_dir
@@ -39,16 +86,24 @@ jobs:
              make defconfig > /dev/null
 
       - run:
-          name: Download & check & compile
+          name: Download source/check/compile
           working_directory: ~/build_dir
           command: |
              PKGS=$(cd ~/openwrt_packages; git diff --diff-filter=d --name-only "origin/$BRANCH..." | grep 'Makefile$' | grep -v '/files/' | awk -F/ '{ print $(NF-1) }')
-             echo "Packages: $PKGS"
+             if [ -z "$PKGS" ] ; then
+                 echo_blue "WARNING: No new or modified packages found!"
+                 exit 0
+             fi
+
+             echo_blue "=== Found new/modified packages: $PKGS"
              for PKG in $PKGS ; do
+                 echo_blue "===+ Download/check: $PKG"
                  make "package/$PKG/download" V=s
                  make "package/$PKG/check" V=s
              done
+
              for PKG in $PKGS ; do
+                 echo_blue "===+ Building: $PKG"
                  make "package/$PKG/compile" -j3 V=s
              done