From b313bf5ca90fb8f1007cfe85d5602d3d554d61c8 Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Sat, 30 Mar 2024 13:57:12 +0800 Subject: [PATCH] =?UTF-8?q?build/ci:=20add=20`check-forbidden-classes.sh`?= =?UTF-8?q?=20=F0=9F=9A=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 11 +++++++++-- scripts/check-forbidden-classes.sh | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100755 scripts/check-forbidden-classes.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 77604dc..ca6d211 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,15 +23,22 @@ jobs: distribution: zulu java-version: ${{ matrix.java }} cache: maven - - run: ./mvnw -V --no-transfer-progress clean package + - name: Run dev mode test + run: ./mvnw -V --no-transfer-progress clean package if: matrix.java != 17 - - run: ./mvnw -V --no-transfer-progress clean package spotbugs:check git-commit-id:validateRevision -DperformRelease + - name: Run release mode test(JDK ${{ matrix.java }}) + run: | + ./mvnw -V --no-transfer-progress clean package spotbugs:check git-commit-id:validateRevision -DperformRelease + scripts/check-forbidden-classes.sh if: matrix.java == 17 # https://github.com/marketplace/actions/codecov - uses: codecov/codecov-action@v4 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} # https://remarkablemark.org/blog/2017/10/12/check-git-dirty/ + - name: Check forbidden classes + run: scripts/check-forbidden-classes.sh + if: runner.os == 'Linux' - name: Check git dirty run: | git status --short diff --git a/scripts/check-forbidden-classes.sh b/scripts/check-forbidden-classes.sh new file mode 100755 index 0000000..686309d --- /dev/null +++ b/scripts/check-forbidden-classes.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -eEuo pipefail + +# cd to project root dir +cd "${0%/*}"/.. + +readonly forbidden_classes=( + javax.annotation.Nullable + javax.annotation.Nonnull + org.jetbrains.annotations.Nullable + org.jetbrains.annotations.NotNull +) + +grep_pattern=$(printf '%s\n' "${forbidden_classes[@]}") + +grep_options=("$grep_pattern" -F -n -C2 -r src/) +[[ "${GITHUB_ACTIONS:-}" = true || -t 1 ]] && grep_options=("${grep_options[@]}" --color=always) + +! grep "${grep_options[@]}"