From 6d2db2ef642310d7dc39679489adb79ebca5c18f Mon Sep 17 00:00:00 2001 From: Rangi <35663410+Rangi42@users.noreply.github.com> Date: Thu, 24 Jun 2021 17:49:08 -0400 Subject: [PATCH] `make checkdiff` does CI documentation checks (#900) Fixes #744 --- .github/workflows/checkdiff.yml | 17 ++++++++ Makefile | 11 ++++- contrib/checkdiff.bash | 77 +++++++++++++++++++++++++++++++++ include/asm/rpn.h | 2 +- 4 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/checkdiff.yml create mode 100755 contrib/checkdiff.bash diff --git a/.github/workflows/checkdiff.yml b/.github/workflows/checkdiff.yml new file mode 100644 index 00000000..d8a1d44e --- /dev/null +++ b/.github/workflows/checkdiff.yml @@ -0,0 +1,17 @@ +name: "Code coverage checking" +on: pull_request + +jobs: + checkdiff: + runs-on: ubuntu-latest + steps: + - name: Set up repo + run: | + git clone -b "${{ github.event.pull_request.head.ref }}" "${{ github.event.pull_request.head.repo.clone_url }}" rgbds + cd rgbds + git remote add upstream "${{ github.event.pull_request.base.repo.clone_url }}" + git fetch upstream + - name: Checkdiff + working-directory: rgbds + run: | + make checkdiff "BASE_REF=${{ github.event.pull_request.base.sha }}" Q= | tee log diff --git a/Makefile b/Makefile index 5c53b4b0..5063d10a 100644 --- a/Makefile +++ b/Makefile @@ -49,6 +49,9 @@ YFLAGS ?= -Wall BISON := bison RM := rm -rf +# Used for checking pull requests +BASE_REF := origin/master + # Rules to build the RGBDS binaries all: rgbasm rgblink rgbfix rgbgfx @@ -189,9 +192,8 @@ checkcodebase: # the first common commit between the HEAD and origin/master. # `.y` files aren't checked, unfortunately... -BASE_REF:= origin/master checkpatch: - $Qeval COMMON_COMMIT=$$(git merge-base HEAD ${BASE_REF}); \ + $QCOMMON_COMMIT=`git merge-base HEAD ${BASE_REF}`; \ for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do \ echo "[*] Analyzing commit '$$commit'"; \ git format-patch --stdout "$$commit~..$$commit" \ @@ -199,6 +201,11 @@ checkpatch: | ${CHECKPATCH} - || true; \ done +# Target used to check for suspiciously missing changed files. + +checkdiff: + $Qcontrib/checkdiff.bash `git merge-base HEAD ${BASE_REF}` + # This target is used during development in order to prevent adding new issues # to the source code. All warnings are treated as errors in order to block the # compilation and make the continous integration infrastructure return failure. diff --git a/contrib/checkdiff.bash b/contrib/checkdiff.bash new file mode 100755 index 00000000..7ab26d35 --- /dev/null +++ b/contrib/checkdiff.bash @@ -0,0 +1,77 @@ +#!/bin/bash + +# SPDX-License-Identifier: MIT +# +# Copyright (c) 2021 Rangi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +declare -A FILES +while read -r -d '' file; do + FILES["$file"]="true" +done < <(git diff --name-only -z $1 HEAD) + +edited () { + ${FILES["$1"]:-"false"} +} + +dependency () { + if edited "$1" && ! edited "$2"; then + echo "'$1' was modified, but not '$2'! $3" | xargs + fi +} + +# Pull requests that edit the first file without the second may be correct, +# but are suspicious enough to require review. + +dependency include/linkdefs.h src/rgbds.5 \ + "Was the object file format changed?" + +dependency src/asm/parser.y src/asm/rgbasm.5 \ + "Was the rgbasm grammar changed?" + +dependency include/asm/warning.h src/asm/rgbasm.1 \ + "Were the rgbasm warnings changed?" + +dependency src/asm/object.c include/linkdefs.h \ + "Should the object file revision be bumped?" +dependency src/link/object.c include/linkdefs.h \ + "Should the object file revision be bumped?" + +dependency Makefile CMakeLists.txt \ + "Did the build process change?" +dependency Makefile src/CMakeLists.txt \ + "Did the build process change?" + +dependency src/asm/main.c src/asm/rgbasm.1 \ + "Did the rgbasm CLI change?" +dependency src/asm/main.c contrib/zsh_compl/_rgbasm \ + "Did the rgbasm CLI change?" +dependency src/link/main.c src/link/rgblink.1 \ + "Did the rgblink CLI change?" +dependency src/link/main.c contrib/zsh_compl/_rgblink \ + "Did the rgblink CLI change?" +dependency src/fix/main.c src/fix/rgbfix.1 \ + "Did the rgbfix CLI change?" +dependency src/fix/main.c contrib/zsh_compl/_rgbfix \ + "Did the rgbfix CLI change?" +dependency src/gfx/main.c src/gfx/rgbgfx.1 \ + "Did the rgbgfx CLI change?" +dependency src/gfx/main.c contrib/zsh_compl/_rgbgfx \ + "Did the rgbgfx CLI change?" diff --git a/include/asm/rpn.h b/include/asm/rpn.h index 981769e2..f15ffd99 100644 --- a/include/asm/rpn.h +++ b/include/asm/rpn.h @@ -24,7 +24,7 @@ struct Expression { uint8_t *rpn; // Array of bytes serializing the RPN expression uint32_t rpnCapacity; // Size of the `rpn` buffer uint32_t rpnLength; // Used size of the `rpn` buffer - uint32_t rpnPatchSize; // Size the expression will take in the obj file + uint32_t rpnPatchSize; // Size the expression will take in the object file }; /*