From fc3b2a1a9aa35bd305dfa154f96ad8f13abe01db Mon Sep 17 00:00:00 2001 From: Andrew Farries Date: Thu, 25 Jan 2024 09:42:18 +0000 Subject: [PATCH] Add deadcode analysis CI check Fail the build if any dead code is detected. --- .github/workflows/build.yml | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 57b156268..c095d26a9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -75,6 +75,31 @@ jobs: exit 1 fi + dead-code-check: + name: dead code check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21' + + - name: Install deadcode tool + run: | + go install golang.org/x/tools/cmd/deadcode@latest + + - name: Run deadcode analysis + run: | + deadcode --test --json ./... > out.json + if ! echo 'null' | diff - out.json > /dev/null; then + echo "Dead code analysis failed!" + echo "Dead code analysis found the following dead code:" + cat out.json + exit 1 + fi + license-check: name: license check runs-on: ubuntu-latest @@ -124,7 +149,7 @@ jobs: release: runs-on: ubuntu-latest - needs: [test, lint, examples, license-check, type-generation] + needs: [test, lint, examples, license-check, type-generation, dead-code-check] if: startsWith(github.ref, 'refs/tags/') env: DOCKER_CLI_EXPERIMENTAL: "enabled"