Skip to content

Commit

Permalink
Add a CI check for unreachable code using deadcode (#251)
Browse files Browse the repository at this point in the history
Add a CI check for unreachable code using the [`deadcode`
tool](https://go.dev/blog/deadcode).

Remove 3 unused functions that were detected by the tool.
  • Loading branch information
andrew-farries committed Jan 25, 2024
1 parent 908485f commit f798ba5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
26 changes: 25 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 found the following dead code:"
cat deadcode.out
exit 1
fi
license-check:
name: license check
runs-on: ubuntu-latest
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 0 additions & 5 deletions pkg/migrations/op_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io"
"strings"
)

type OpName string
Expand Down Expand Up @@ -40,10 +39,6 @@ func TemporaryName(name string) string {
return temporaryPrefix + name
}

func StripTemporaryPrefix(name string) string {
return strings.TrimPrefix(name, temporaryPrefix)
}

func ReadMigration(r io.Reader) (*Migration, error) {
byteValue, err := io.ReadAll(r)
if err != nil {
Expand Down
14 changes: 0 additions & 14 deletions pkg/migrations/op_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,6 @@ func TableMustHaveColumnCount(t *testing.T, db *sql.DB, schema, table string, n
}
}

func FunctionMustExist(t *testing.T, db *sql.DB, schema, function string) {
t.Helper()
if !functionExists(t, db, schema, function) {
t.Fatalf("Expected function %q to exist", function)
}
}

func FunctionMustNotExist(t *testing.T, db *sql.DB, schema, function string) {
t.Helper()
if functionExists(t, db, schema, function) {
Expand All @@ -188,13 +181,6 @@ func TriggerMustNotExist(t *testing.T, db *sql.DB, schema, table, trigger string
}
}

func TriggerMustExist(t *testing.T, db *sql.DB, schema, table, trigger string) {
t.Helper()
if !triggerExists(t, db, schema, table, trigger) {
t.Fatalf("Expected trigger %q to exist", trigger)
}
}

func CheckConstraintMustNotExist(t *testing.T, db *sql.DB, schema, table, constraint string) {
t.Helper()
if checkConstraintExists(t, db, schema, table, constraint) {
Expand Down

0 comments on commit f798ba5

Please sign in to comment.