Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a CI check for unreachable code using deadcode #251

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading