From f213dd8a313db4a2d61effd6d8c8e6c06429770c Mon Sep 17 00:00:00 2001 From: Andrew Farries Date: Thu, 25 Jan 2024 09:35:35 +0000 Subject: [PATCH] Add deadcode analysis CI check Fail the build if any dead code is detected. --- .github/workflows/build.yml | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 57b156268..592f8aeb7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -75,6 +75,30 @@ 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 ./... > deadcode-out + if [ ! -s deadcode-out ]; then + echo "Dead code analysis failed!" + echo "Dead code analysis found the following dead code:" + cat deadcode-out + fi + license-check: name: license check runs-on: ubuntu-latest @@ -124,7 +148,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"