From 4c3b896787d07b84c895a89f49f5dec4f42f0b31 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Sat, 13 Jan 2024 20:45:45 +0100 Subject: Internal: Ban imports (#595) Added options to ban specific imports in some packages. #595 --- .github/workflows/ban-imports.yaml | 23 +++++++++++++++++++++++ .github/workflows/illegal-imports.txt | 6 ++++++ 2 files changed, 29 insertions(+) create mode 100644 .github/workflows/ban-imports.yaml create mode 100644 .github/workflows/illegal-imports.txt diff --git a/.github/workflows/ban-imports.yaml b/.github/workflows/ban-imports.yaml new file mode 100644 index 000000000..2d0020c85 --- /dev/null +++ b/.github/workflows/ban-imports.yaml @@ -0,0 +1,23 @@ +name: Check banned imports +on: + - pull_request + - push + - workflow_dispatch +permissions: {} +jobs: + check-imports: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + name: Checkout code + - name: Check imports + run: | + while IFS=' ' read search banned; do + echo Banning $banned from $search + grep -nrE -- "import $banned" src/main/java/"$search"|sed -E 's/^(.*):([0-9]+):(.*)/::error file=\1,line=\2::Illegal \3/g'|tee -a temp + done<<<$(cat .github/workflows/illegal-imports.txt|sed -E 's/#.*//;/^$/d') + found=$(wc -l temp|cut -d ' ' -f 1) + echo Found "$found" invalid imports. Check the files tab for more information. + if [[ "$found" -ne 0 ]]; then + exit 1 + fi diff --git a/.github/workflows/illegal-imports.txt b/.github/workflows/illegal-imports.txt new file mode 100644 index 000000000..97beefd29 --- /dev/null +++ b/.github/workflows/illegal-imports.txt @@ -0,0 +1,6 @@ +# Ban some packages from importing some other packages. +# Lines starting with # are ignored +# Every other line needs to be in the format +# + +at/hannibal2/skyhanni/ scala. -- cgit