Skip to content

Commit

Permalink
Merge 7993367 into 440f237
Browse files Browse the repository at this point in the history
  • Loading branch information
gregito authored Jul 24, 2024
2 parents 440f237 + 7993367 commit 3a4945a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,14 @@ jobs:
ignore-pattern: |
/cdp-sdk-go/
/main.go$
deadcode:
name: 'Terraform Provider Quality Gate :: Dead code analysis'
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: 'go.mod'
- name: Run deadcode
run: go install golang.org/x/tools/cmd/deadcode@latest && sh ./deadcode-check.sh
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ terraform-provider-cdp

# Ignore the dist directory
dist/

# Ignore deadcode check output that is produced by the deadcode-check.sh script
deadcode-output.txt
22 changes: 22 additions & 0 deletions deadcode-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

deadcode . > deadcode-output.txt

# Since deadcode report files that are not called from tha main package,
# we need to remove these outputs that are only (but certainly) used in tests.
# For this, we'd need to follow the pattern to name these files like
# test_.*_util(s).go
# Surely, if either of these files contain a really dead code,
# it will be omitted from the report thus this approach is potentially unsafe,
# but it is the best we can do for now, until the deadcode team won't introduce
# a flag to ignore files by pattern.
sed -i '/test_.*util.go\|test_.*utils.go/d' ./deadcode-output.txt

if [ -s deadcode-output.txt ]; then
echo "The following function(s) is/are not used in the code:"
cat deadcode-output.txt
exit 1
else
echo "No dead code found!"
exit 0
fi

0 comments on commit 3a4945a

Please sign in to comment.