diff --git a/.github/workflows/lint_c.yml b/.github/workflows/lint_c.yml index b094a1dd..d9be8f80 100644 --- a/.github/workflows/lint_c.yml +++ b/.github/workflows/lint_c.yml @@ -43,7 +43,19 @@ jobs: uses: ./.github/actions/docker - name: 'Check syntax' + id: syntax_check uses: ./.github/actions/docker - continue-on-error: false with: - run: /syntax_check.sh + run: SET_GH_OUTPUT=1 /syntax_check.sh + + - name: Report syntax errors + if: failure() && steps.syntax_check.outputs.errors && github.event.pull_request + uses: peter-evans/create-or-update-comment@v1 + with: + issue-number: ${{ github.event.pull_request.number }} + body: | + Please fix following syntax errors: + ``` + ${{ steps.syntax_check.outputs.errors }} + ``` + You might want to run `docker compose exec dev /syntax_check.sh` for an auto-fix. \ No newline at end of file diff --git a/docker/syntax_check.sh b/docker/syntax_check.sh index be74df29..0bd3466a 100755 --- a/docker/syntax_check.sh +++ b/docker/syntax_check.sh @@ -3,7 +3,6 @@ # set -e CLANG_FORMAT_BIN="/usr/bin/clang-format-12" -PATH="$HOME/.cargo/bin:${PATH}" PROJECT_DIR=$(pwd) @@ -19,14 +18,20 @@ C_FILES=$(find . \ ulimit -s 65536 $CLANG_FORMAT_BIN --version -$CLANG_FORMAT_BIN --verbose -style=file -n --Werror --ferror-limit=0 $C_FILES -c_syntax_rc=$? +errors=$($CLANG_FORMAT_BIN --verbose -style=file -n --Werror --ferror-limit=0 $C_FILES |& tee /dev/stderr | sed '/^Formatting/d') -if [[ $c_syntax_rc -eq 0 ]]; then +if [[ -z "$errors" ]]; then echo "Code looks fine for me!" exit 0 fi +if [[ -n "${SET_GH_OUTPUT}" ]]; then + errors="${errors//'%'/'%25'}" + errors="${errors//$'\n'/'%0A'}" + errors="${errors//$'\r'/'%0D'}" + echo "::set-output name=errors::$errors" +fi + read -p "Do you want fix syntax? (y/n): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1 cd $PROJECT_DIR