diff --git a/.github/workflows/go-cross.yml b/.github/workflows/go-cross.yml new file mode 100644 index 00000000..d284bd45 --- /dev/null +++ b/.github/workflows/go-cross.yml @@ -0,0 +1,32 @@ +name: Go Matrix +on: [push, pull_request] + +jobs: + + cross: + name: Go + runs-on: ${{ matrix.os }} + env: + CGO_ENABLED: 0 + + strategy: + matrix: + go-version: [ oldstable, stable ] + os: [ubuntu-latest, macos-latest, windows-latest] + + steps: + # https://github.com/marketplace/actions/checkout + - name: Checkout code + uses: actions/checkout@v4 + + # https://github.com/marketplace/actions/setup-go-environment + - name: Set up Go ${{ matrix.go-version }} + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + + - name: Test + run: go test -v -cover ./... + + - name: Build + run: go build -v -ldflags "-s -w" -trimpath diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..8d8ce522 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,43 @@ +name: Main + +on: + push: + branches: + - main + pull_request: + +jobs: + + main: + name: Main Process + runs-on: ubuntu-latest + env: + GO_VERSION: stable + GOLANGCI_LINT_VERSION: v1.57.0 + CGO_ENABLED: 0 + + steps: + # https://github.com/marketplace/actions/checkout + - name: Check out code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # https://github.com/marketplace/actions/setup-go-environment + - name: Set up Go ${{ env.GO_VERSION }} + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Check and get dependencies + run: | + go mod download + go mod tidy + git diff --exit-code go.mod + + # https://golangci-lint.run/usage/install#other-ci + - name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }} + run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION} + + - name: Make + run: make diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..c9ec2929 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +/dupl diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b8ee13ab..00000000 --- a/.travis.yml +++ /dev/null @@ -1,4 +0,0 @@ -language: go -go: - - 1.14 - - 1.15 diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..0a100173 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +.PHONY: clean check test build + +default: clean check test build + +clean: + rm -rf dist/ cover.out + +test: clean + go test -v -cover ./... + +check: + golangci-lint run + +build: + go build -ldflags "-s -w" -trimpath diff --git a/README.md b/README.md index 4267fe23..3529aff9 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# dupl [![Build Status](https://travis-ci.org/mibk/dupl.png)](https://travis-ci.org/mibk/dupl) +# dupl **dupl** is a tool written in Go for finding code clones. So far it can find clones only in the Go source files. The method uses suffix tree for serialized ASTs. It ignores values of AST nodes. It just operates with their types (e.g. `if a == 13 {}` and `if x == 100 {}` are considered the same provided it exceeds the minimal token sequence size). -Due to the used method dupl can report so called "false positives" on the output. These are +Due to the used method dupl can report so-called "false positives" on the output. These are the ones we do not consider clones (whether they are too small, or the values of the matched tokens are completely different). diff --git a/go.mod b/go.mod index 7ce61159..3ee554e5 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/mibk/dupl -go 1.14 +go 1.21 diff --git a/main.go b/main.go index 93451f77..b6c95d3c 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,6 @@ import ( "bufio" "flag" "fmt" - "io/ioutil" "log" "os" "path/filepath" @@ -80,7 +79,7 @@ func main() { } else if *plumbing { newPrinter = printer.NewPlumbing } - p := newPrinter(os.Stdout, ioutil.ReadFile) + p := newPrinter(os.Stdout, os.ReadFile) if err := printDupls(p, duplChan); err != nil { log.Fatal(err) }