From 086586e84aec320d08e3902308ea2026fb7bf4d5 Mon Sep 17 00:00:00 2001 From: Jack Westbrook Date: Fri, 29 Nov 2024 11:11:52 +0100 Subject: [PATCH] CI: Add Knip to understand dependency usage (#1360) --- .github/knip.json | 11 +++++++++++ .github/workflows/ci.yml | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 .github/knip.json diff --git a/.github/knip.json b/.github/knip.json new file mode 100644 index 000000000..cf5ca9efc --- /dev/null +++ b/.github/knip.json @@ -0,0 +1,11 @@ +{ + "$schema": "https://unpkg.com/knip@5/schema.json", + "entry": ["src/module.{js,ts,tsx}"], + "project": ["src/**/*", "tests/**/*", ".config/**/*"], + "eslint": { + "config": [".config/.eslintrc", "./.eslintrc"] + }, + "webpack": { + "config": [".config/webpack/webpack.config.ts"] + } +} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ec7a593bd..eef5a98be 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,7 @@ jobs: run: | mkdir ./packed-artifacts npm pack --workspace="@grafana/create-plugin" --workspace="@grafana/sign-plugin" --pack-destination="./packed-artifacts" + cp ./.github/knip.json ./packed-artifacts - name: Upload artifacts for testing uses: actions/upload-artifact@v4 with: @@ -199,6 +200,16 @@ jobs: run: sign-plugin --rootUrls http://www.example.com --signatureType private working-directory: ./${{ matrix.workingDir }} + - name: Frontend Knip Report + if: ${{ github.actor != 'dependabot[bot]' }} + # Knip uses the scaffolded plugin .gitignore file for ignore paths. + # github workflows use paths like home/runner/work/plugin-tools/plugin-tools + # so we need to remove /work otherwise knip returns false positives + run: | + sed -i '/^work\/$/d' .gitignore + npx -y knip --config ../packed-artifacts/knip.json --reporter markdown --no-exit-code + working-directory: ./${{ matrix.workingDir }} + release: runs-on: ubuntu-latest needs: [test, generate-plugins]