diff --git a/.bindown.yaml b/.bindown.yaml new file mode 100644 index 0000000..96f6d2d --- /dev/null +++ b/.bindown.yaml @@ -0,0 +1,264 @@ +systems: +- darwin/amd64 +- linux/amd64 +dependencies: + gofumpt: + template: origin#gofumpt + vars: + version: 0.5.0 + golangci-lint: + template: origin#golangci-lint + vars: + version: 1.51.2 + goreleaser: + template: origin#goreleaser + vars: + version: 1.18.2 + handcrafted: + template: origin#handcrafted + vars: + version: 0.0.0 + semver-next: + template: origin#semver-next + vars: + version: 0.12.2 + shellcheck: + template: origin#shellcheck + vars: + version: 0.9.0 +templates: + benchdiff: + url: https://github.com/WillAbides/benchdiff/releases/download/v{{.version}}/benchdiff_{{.version}}_{{.os}}_{{.arch}}.tar.gz + required_vars: + - version + systems: + - darwin/amd64 + - linux/386 + - linux/amd64 + gofumpt: + url: https://github.com/mvdan/gofumpt/releases/download/v{{.version}}/gofumpt_v{{.version}}_{{.os}}_{{.arch}}{{.suffix}} + archive_path: gofumpt_v{{.version}}_{{.os}}_{{.arch}}{{.suffix}} + bin: gofumpt{{.suffix}} + vars: + suffix: "" + required_vars: + - version + overrides: + - matcher: + os: + - windows + dependency: + vars: + suffix: .exe + origin#gofumpt: + homepage: https://github.com/mvdan/gofumpt + description: A stricter gofmt + url: https://github.com/mvdan/gofumpt/releases/download/v{{.version}}/gofumpt_v{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} + archive_path: gofumpt_v{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} + bin: gofumpt + vars: + archivePathSuffix: "" + urlSuffix: "" + required_vars: + - version + overrides: + - matcher: + os: + - windows + dependency: + vars: + urlSuffix: .exe + systems: + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - windows/386 + - windows/amd64 + origin#golangci-lint: + homepage: https://github.com/golangci/golangci-lint + description: Fast linters Runner for Go + url: https://github.com/golangci/golangci-lint/releases/download/v{{.version}}/golangci-lint-{{.version}}-{{.os}}-{{.arch}}{{.urlSuffix}} + archive_path: golangci-lint-{{.version}}-{{.os}}-{{.arch}}/golangci-lint{{.archivePathSuffix}} + bin: golangci-lint + vars: + archivePathSuffix: "" + urlSuffix: .tar.gz + required_vars: + - version + overrides: + - matcher: + os: + - windows + dependency: + vars: + archivePathSuffix: .exe + urlSuffix: .zip + systems: + - darwin/amd64 + - darwin/arm64 + - freebsd/386 + - freebsd/amd64 + - linux/386 + - linux/amd64 + - linux/arm64 + - linux/loong64 + - linux/mips64 + - linux/mips64le + - linux/ppc64le + - linux/riscv64 + - linux/s390x + - netbsd/386 + - netbsd/amd64 + - windows/386 + - windows/amd64 + - windows/arm64 + origin#goreleaser: + homepage: https://github.com/goreleaser/goreleaser + description: Deliver Go binaries as fast and easily as possible + url: https://github.com/goreleaser/goreleaser/releases/download/v{{.version}}/goreleaser_{{.os}}_{{.arch}}{{.urlSuffix}} + archive_path: goreleaser{{.archivePathSuffix}} + bin: goreleaser + vars: + archivePathSuffix: "" + urlSuffix: .tar.gz + required_vars: + - version + overrides: + - matcher: + os: + - windows + dependency: + vars: + archivePathSuffix: .exe + urlSuffix: .zip + substitutions: + arch: + "386": i386 + amd64: x86_64 + os: + windows: Windows + substitutions: + arch: + "386": i386 + amd64: x86_64 + os: + darwin: Darwin + linux: Linux + systems: + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - linux/ppc64 + - windows/386 + - windows/amd64 + - windows/arm64 + origin#handcrafted: + homepage: https://github.com/willabides/handcrafted + description: lists non-generated go files in a package + url: https://github.com/WillAbides/handcrafted/releases/download/v{{.version}}/handcrafted_{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} + archive_path: handcrafted{{.archivePathSuffix}} + bin: handcrafted + vars: + archivePathSuffix: "" + urlSuffix: .tar.gz + required_vars: + - version + overrides: + - matcher: + os: + - windows + dependency: + vars: + archivePathSuffix: .exe + systems: + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - windows/386 + - windows/amd64 + - windows/arm64 + origin#semver-next: + homepage: https://github.com/WillAbides/semver-next + url: https://github.com/WillAbides/semver-next/releases/download/v{{.version}}/semver-next_{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} + archive_path: semver-next{{.archivePathSuffix}} + bin: semver-next + vars: + archivePathSuffix: "" + urlSuffix: .tar.gz + required_vars: + - version + overrides: + - matcher: + os: + - windows + dependency: + vars: + archivePathSuffix: .exe + systems: + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - windows/386 + - windows/amd64 + - windows/arm64 + origin#shellcheck: + homepage: https://github.com/koalaman/shellcheck + description: ShellCheck, a static analysis tool for shell scripts + url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.{{.os}}.{{.arch}}{{.urlSuffix}} + archive_path: shellcheck-v{{.version}}/shellcheck{{.archivePathSuffix}} + bin: shellcheck + vars: + archivePathSuffix: "" + urlSuffix: .tar.xz + required_vars: + - version + overrides: + - matcher: + os: + - windows + dependency: + url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.zip + archive_path: shellcheck.exe + - matcher: + arch: + - arm64 + os: + - darwin + dependency: + substitutions: + arch: + arm64: x86_64 + substitutions: + arch: + amd64: x86_64 + arm64: aarch64 + systems: + - darwin/amd64 + - darwin/arm64 + - linux/amd64 + - linux/arm64 + - windows/amd64 +template_sources: + benchdiff: https://raw.githubusercontent.com/WillAbides/benchdiff/main/bindown.yml + origin: https://raw.githubusercontent.com/WillAbides/bindown-templates/master/bindown.yml +url_checksums: + https://github.com/WillAbides/handcrafted/releases/download/v0.0.0/handcrafted_0.0.0_darwin_amd64.tar.gz: df5dbf9c8b282d8209a8baddfe3410c5b3ace87bdce808fce0a0d49356c9ff4d + https://github.com/WillAbides/handcrafted/releases/download/v0.0.0/handcrafted_0.0.0_linux_amd64.tar.gz: 1a7885a9854d2455dce1be3bc19f2d61a61ebdc99e2a98e4969ab1965c2a64ad + https://github.com/WillAbides/semver-next/releases/download/v0.12.2/semver-next_0.12.2_darwin_amd64.tar.gz: 2ccb3245b790c5700c0643b8d8b39ec25b080ea98e6cd824f8ead7e0c5dd1ffb + https://github.com/WillAbides/semver-next/releases/download/v0.12.2/semver-next_0.12.2_linux_amd64.tar.gz: 15649ff83af46b63fd6c6abb6d2dda7f9b811604b10f05e2f7f6fae24a72edbb + https://github.com/golangci/golangci-lint/releases/download/v1.51.2/golangci-lint-1.51.2-darwin-amd64.tar.gz: 0549cbaa2df451cf3a2011a9d73a9cb127784d26749d9cd14c9f4818af104d44 + https://github.com/golangci/golangci-lint/releases/download/v1.51.2/golangci-lint-1.51.2-linux-amd64.tar.gz: 4de479eb9d9bc29da51aec1834e7c255b333723d38dbd56781c68e5dddc6a90b + https://github.com/goreleaser/goreleaser/releases/download/v1.18.2/goreleaser_Darwin_x86_64.tar.gz: 95338eed333347152e23837b68a8c6ce0c62b9f5abb68bd5b4b08178766400b9 + https://github.com/goreleaser/goreleaser/releases/download/v1.18.2/goreleaser_Linux_x86_64.tar.gz: 811e0c63e347f78f3c8612a19ca8eeb564eb45f0265ce3f38aec39c8fdbcfa10 + https://github.com/koalaman/shellcheck/releases/download/v0.9.0/shellcheck-v0.9.0.darwin.x86_64.tar.xz: 7d3730694707605d6e60cec4efcb79a0632d61babc035aa16cda1b897536acf5 + https://github.com/koalaman/shellcheck/releases/download/v0.9.0/shellcheck-v0.9.0.linux.x86_64.tar.xz: 700324c6dd0ebea0117591c6cc9d7350d9c7c5c287acbad7630fa17b1d4d9e2f + https://github.com/mvdan/gofumpt/releases/download/v0.5.0/gofumpt_v0.5.0_darwin_amd64: 870f05a23541aad3d20d208a3ea17606169a240f608ac1cf987426198c14b2ed + https://github.com/mvdan/gofumpt/releases/download/v0.5.0/gofumpt_v0.5.0_linux_amd64: 759c6ab56bfbf62cafb35944aef1e0104a117e0aebfe44816fd79ef4b28521e4 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..6e6c483 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,22 @@ +name: ci +on: [push] +jobs: + cibuild: + name: cibuild + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - uses: WillAbides/setup-go-faster@v1 + id: setup-go + with: + go-version: '1.20.x' + - uses: actions/cache@v3 + with: + path: | + ${{ steps.setup-go.outputs.GOCACHE }} + ${{ steps.setup-go.outputs.GOMODCACHE }} + key: ${{ runner.os }}-go-test-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go-test + - run: script/test + - run: script/lint + - run: script/generate --check diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 7baa207..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: ci -on: [push] -jobs: - cibuild: - name: cibuild - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - uses: willabides/setup-go-faster@v1.6.0 - with: - go-version: '1.16.x' - - run: script/generate --check - - run: script/test - - run: script/lint diff --git a/.github/workflows/releasable.yaml b/.github/workflows/releasable.yaml new file mode 100644 index 0000000..345699b --- /dev/null +++ b/.github/workflows/releasable.yaml @@ -0,0 +1,22 @@ +name: releasable +on: + pull_request: + branches: + - main + types: + - labeled + - unlabeled + - synchronize + - opened + - reopened + workflow_dispatch: +jobs: + releasable: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: script/bindown -q install semver-next + - name: check releasable + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: bin/semver-next "$GITHUB_REPOSITORY" -r "$GITHUB_SHA" --require-labels diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..af94cc6 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,25 @@ +name: release +on: + push: + branches: + - main +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: WillAbides/setup-go-faster@v1 + id: setup-go + with: + go-version: '1.20.x' + - uses: actions/cache@v3 + with: + path: | + ${{ steps.setup-go.outputs.GOCACHE }} + ${{ steps.setup-go.outputs.GOMODCACHE }} + key: ${{ runner.os }}-release-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-release + - run: script/release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - run: jq '.' dist/metadata.json diff --git a/.golangci.yml b/.golangci.yml index c2fba4f..14579de 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,7 +10,6 @@ issues: - goconst linters: enable: - - golint - gosec - unconvert - gocyclo @@ -18,6 +17,7 @@ linters: - goimports - gocritic - gofumpt + - revive linters-settings: gocritic: enabled-tags: @@ -31,9 +31,10 @@ linters-settings: govet: # report about shadowed variables check-shadowing: true - gocyclo: - # minimal code complexity to report, 30 by default - min-complexity: 15 maligned: # print struct with more effective memory layout or not, false by default suggest-new: true + revive: + rules: + - name: package-comments + disabled: true diff --git a/README.md b/README.md index 09ea6d6..1fea759 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,8 @@ Flags: benchmark command line --bench="." Run only those benchmarks matching a regular expression. To run all benchmarks, use '--bench .'. - --benchmark-args=args Override the default args to the go command. This may be a template. See - https://github.com/willabides/benchdiff for details." + --benchmark-args=args Override the default args to the go command. This may be a template. + See https://github.com/willabides/benchdiff for details." --benchmark-cmd="go" The command to use for benchmarks. --benchmem Memory allocation statistics for benchmarks. --benchtime=STRING Run enough iterations of each benchmark to take t, specified as a diff --git a/bindown.yml b/bindown.yml deleted file mode 100644 index a553de4..0000000 --- a/bindown.yml +++ /dev/null @@ -1,139 +0,0 @@ -systems: -- darwin/amd64 -- linux/amd64 -dependencies: - gofumpt: - template: gofumpt - vars: - version: 0.1.1 - golangci-lint: - template: origin#golangci-lint - vars: - version: 1.39.0 - goreleaser: - template: origin#goreleaser - vars: - version: 0.143.0 - shellcheck: - template: origin#shellcheck - vars: - version: 0.7.2 -templates: - benchdiff: - url: https://github.com/WillAbides/benchdiff/releases/download/v{{.version}}/benchdiff_{{.version}}_{{.os}}_{{.arch}}.tar.gz - required_vars: - - version - systems: - - darwin/amd64 - - linux/386 - - linux/amd64 - gofumpt: - url: https://github.com/mvdan/gofumpt/releases/download/v{{.version}}/gofumpt_v{{.version}}_{{.os}}_{{.arch}}{{.suffix}} - archive_path: gofumpt_v{{.version}}_{{.os}}_{{.arch}}{{.suffix}} - bin: gofumpt{{.suffix}} - vars: - suffix: "" - required_vars: - - version - overrides: - - matcher: - os: - - windows - dependency: - vars: - suffix: .exe - origin#golangci-lint: - url: https://github.com/golangci/golangci-lint/releases/download/v{{.version}}/golangci-lint-{{.version}}-{{.os}}-{{.arch}}{{.urlsuffix}} - archive_path: golangci-lint-{{.version}}-{{.os}}-{{.arch}}/golangci-lint{{.archivepathsuffix}} - bin: golangci-lint - link: true - vars: - archivepathsuffix: "" - urlsuffix: .tar.gz - required_vars: - - version - overrides: - - matcher: - os: - - windows - dependency: - vars: - archivepathsuffix: .exe - urlsuffix: .zip - systems: - - darwin/386 - - darwin/amd64 - - linux/386 - - linux/amd64 - - linux/arm64 - - windows/386 - - windows/amd64 - - freebsd/386 - - freebsd/amd64 - - linux/mips64 - - linux/mips64le - - linux/s390x - - linux/ppc64le - origin#goreleaser: - url: https://github.com/goreleaser/goreleaser/releases/download/v{{.version}}/goreleaser_{{.os}}_{{.arch}}{{.urlsuffix}} - archive_path: goreleaser{{.archivepathsuffix}} - bin: goreleaser - vars: - archivepathsuffix: "" - urlsuffix: .tar.gz - required_vars: - - version - overrides: - - matcher: - os: - - windows - dependency: - vars: - archivepathsuffix: .exe - urlsuffix: .zip - substitutions: - arch: - "386": i386 - amd64: x86_64 - os: - darwin: Darwin - linux: Linux - windows: Windows - systems: - - darwin/amd64 - - linux/386 - - linux/amd64 - - windows/386 - - windows/amd64 - origin#shellcheck: - url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.{{.os}}.{{.arch}}.tar.xz - archive_path: shellcheck-v{{.version}}/shellcheck - bin: shellcheck - required_vars: - - version - overrides: - - matcher: - os: - - windows - dependency: - url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.zip - archive_path: shellcheck-v{{.version}}.exe - substitutions: - arch: - amd64: x86_64 - systems: - - darwin/amd64 - - linux/amd64 - - windows/amd64 -template_sources: - benchdiff: https://raw.githubusercontent.com/WillAbides/benchdiff/main/bindown.yml - origin: https://raw.githubusercontent.com/WillAbides/bindown-templates/master/bindown.yml -url_checksums: - https://github.com/golangci/golangci-lint/releases/download/v1.39.0/golangci-lint-1.39.0-darwin-amd64.tar.gz: 7e9a47ab540aa3e8472fbf8120d28bed3b9d9cf625b955818e8bc69628d7187c - https://github.com/golangci/golangci-lint/releases/download/v1.39.0/golangci-lint-1.39.0-linux-amd64.tar.gz: 3a73aa7468087caa62673c8adea99b4e4dff846dc72707222db85f8679b40cbf - https://github.com/goreleaser/goreleaser/releases/download/v0.143.0/goreleaser_Darwin_x86_64.tar.gz: 0b713827a2c0e21238a211899e6eb81f23c2dc7c9b39ecb426b06ed6efbce568 - https://github.com/goreleaser/goreleaser/releases/download/v0.143.0/goreleaser_Linux_x86_64.tar.gz: cc435eb337889d41414de80fd8474806187a3e908754cbf4599aa0a7604a3134 - https://github.com/koalaman/shellcheck/releases/download/v0.7.2/shellcheck-v0.7.2.darwin.x86_64.tar.xz: 969bd7ef668e8167cfbba569fb9f4a0b2fc1c4021f87032b6a0b0e525fb77369 - https://github.com/koalaman/shellcheck/releases/download/v0.7.2/shellcheck-v0.7.2.linux.x86_64.tar.xz: 70423609f27b504d6c0c47e340f33652aea975e45f312324f2dbf91c95a3b188 - https://github.com/mvdan/gofumpt/releases/download/v0.1.1/gofumpt_v0.1.1_darwin_amd64: 97e4d6d97d70ba6d5177b1fbbbdf7e447bce69b8ccfb0ea64b75699a8393a095 - https://github.com/mvdan/gofumpt/releases/download/v0.1.1/gofumpt_v0.1.1_linux_amd64: 8884cb7b22d09bc8920748db5756d276ddfdb9e0f9a64edd6185b61a61e860ad diff --git a/cmd/benchdiff/internal/benchdiff.go b/cmd/benchdiff/internal/benchdiff.go index 94395f6..5915ee2 100644 --- a/cmd/benchdiff/internal/benchdiff.go +++ b/cmd/benchdiff/internal/benchdiff.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "log" "os" "os/exec" @@ -55,7 +54,7 @@ func fileExists(path string) bool { func (c *Benchdiff) debug() *log.Logger { if c.Debug == nil { - return log.New(ioutil.Discard, "", 0) + return log.New(io.Discard, "", 0) } return c.Debug } @@ -78,7 +77,7 @@ func (c *Benchdiff) cacheKey() string { // runCmd runs cmd sending its stdout and stderr to debug.Write() func runCmd(cmd *exec.Cmd, debug *log.Logger) error { if debug == nil { - debug = log.New(ioutil.Discard, "", 0) + debug = log.New(io.Discard, "", 0) } var bufStderr bytes.Buffer stderr := io.MultiWriter(&bufStderr, debug.Writer()) @@ -101,17 +100,17 @@ stderr: %s`, cmd.String(), exitErr.ExitCode(), bufStderr.String()) return err } -func (c *Benchdiff) runBenchmark(ref, filename, extraArgs string, pause time.Duration, force bool) (err error) { +func (c *Benchdiff) runBenchmark(ref, filename, extraArgs string, pause time.Duration, force bool) (errOut error) { cmd := exec.Command(c.BenchCmd, strings.Fields(c.BenchArgs+" "+extraArgs)...) //nolint:gosec // this is fine stdlib := false if rootPath, err := runGitCmd(c.debug(), c.gitCmd(), c.Path, "rev-parse", "--show-toplevel"); err == nil { // lib/time/zoneinfo.zip is a specific enough path, and it's here to // stay because it's one of the few paths hardcoded into Go binaries. - zoneinfoPath := filepath.Join(string(rootPath), "lib/time/zoneinfo.zip") + zoneinfoPath := filepath.Join(string(rootPath), "lib", "time", "zoneinfo.zip") if _, err := os.Stat(zoneinfoPath); err == nil { stdlib = true - cmd.Path = filepath.Join(string(rootPath), "bin/go") + cmd.Path = filepath.Join(string(rootPath), "bin", "go") } } @@ -124,14 +123,15 @@ func (c *Benchdiff) runBenchmark(ref, filename, extraArgs string, pause time.Dur return nil } } - file, err = os.Create(filename) + //nolint:gosec // user provides filename + file, err := os.Create(filename) if err != nil { return err } defer func() { cErr := file.Close() - if err == nil { - err = cErr + if errOut == nil { + errOut = cErr } }() cmd.Stdout = file @@ -141,11 +141,12 @@ func (c *Benchdiff) runBenchmark(ref, filename, extraArgs string, pause time.Dur if ref == "" { return runCmd(cmd, c.debug()) } - err = runAtGitRef(c.debug(), c.gitCmd(), c.Path, c.BaseRef, func(workPath string) { + err := runAtGitRef(c.debug(), c.gitCmd(), c.Path, c.BaseRef, func(workPath string) { if pause > 0 { time.Sleep(pause) } if stdlib { + //nolint:gosec // workPath is a temp dir makeCmd := exec.Command(filepath.Join(workPath, "src", "make.bash")) makeCmd.Dir = filepath.Join(workPath, "src") runErr = runCmd(makeCmd, c.debug()) diff --git a/cmd/benchdiff/internal/benchdiff_test.go b/cmd/benchdiff/internal/benchdiff_test.go index 4ee9a9c..eb7d61f 100644 --- a/cmd/benchdiff/internal/benchdiff_test.go +++ b/cmd/benchdiff/internal/benchdiff_test.go @@ -1,7 +1,6 @@ package internal import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -15,18 +14,18 @@ func setupTestRepo(t *testing.T, path string) { mustGo(t, path, "mod", "init", "bindiff.test") ex1 := filepath.Join(path, "ex1.go") ex1test := filepath.Join(path, "ex1_test.go") - err := ioutil.WriteFile(ex1, []byte(ex1Rev1), 0o600) + err := os.WriteFile(ex1, []byte(ex1Rev1), 0o600) require.NoError(t, err) - err = ioutil.WriteFile(ex1test, []byte(ex1Bench), 0o600) + err = os.WriteFile(ex1test, []byte(ex1Bench), 0o600) require.NoError(t, err) - err = ioutil.WriteFile(filepath.Join(path, ".gitignore"), []byte("tmp/\n"), 0o600) + err = os.WriteFile(filepath.Join(path, ".gitignore"), []byte("tmp/\n"), 0o600) require.NoError(t, err) mustGit(t, path, "init") err = os.MkdirAll(filepath.Join(path, "tmp"), 0o700) require.NoError(t, err) mustGit(t, path, "add", ".") mustGit(t, path, "commit", "-m", "initial commit") - err = ioutil.WriteFile(ex1, []byte(ex1Rev2), 0o600) + err = os.WriteFile(ex1, []byte(ex1Rev2), 0o600) require.NoError(t, err) } diff --git a/cmd/benchdiff/internal/gitrunner.go b/cmd/benchdiff/internal/gitrunner.go index 36e16f3..4e61eac 100644 --- a/cmd/benchdiff/internal/gitrunner.go +++ b/cmd/benchdiff/internal/gitrunner.go @@ -3,7 +3,6 @@ package internal import ( "bytes" "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -19,7 +18,7 @@ func runGitCmd(debug *log.Logger, gitCmd, repoPath string, args ...string) ([]by } func runAtGitRef(debug *log.Logger, gitCmd, repoPath, ref string, fn func(path string)) error { - worktree, err := ioutil.TempDir("", "benchdiff") + worktree, err := os.MkdirTemp("", "benchdiff") if err != nil { return err } diff --git a/cmd/benchdiff/internal/gitrunner_test.go b/cmd/benchdiff/internal/gitrunner_test.go index 2335f19..248734f 100644 --- a/cmd/benchdiff/internal/gitrunner_test.go +++ b/cmd/benchdiff/internal/gitrunner_test.go @@ -1,7 +1,7 @@ package internal import ( - "io/ioutil" + "os" "path/filepath" "testing" @@ -11,29 +11,28 @@ import ( func Test_runAtGitRef(t *testing.T) { dir := t.TempDir() fooPath := filepath.Join(dir, "foo") - err := ioutil.WriteFile(fooPath, []byte("OG content"), 0o600) + err := os.WriteFile(fooPath, []byte("OG content"), 0o600) require.NoError(t, err) mustGit(t, dir, "init") mustGit(t, dir, "add", "foo") mustGit(t, dir, "commit", "-m", "ignore me") untrackedPath := filepath.Join(dir, "untracked") - err = ioutil.WriteFile(untrackedPath, []byte("untracked"), 0o600) + err = os.WriteFile(untrackedPath, []byte("untracked"), 0o600) require.NoError(t, err) - err = ioutil.WriteFile(fooPath, []byte("new content"), 0o600) + err = os.WriteFile(fooPath, []byte("new content"), 0o600) require.NoError(t, err) fn := func(workDir string) { var got []byte - untrackedPath := filepath.Join(workDir, "untracked") - _, err = ioutil.ReadFile(untrackedPath) + _, err = os.ReadFile(filepath.Join(workDir, "untracked")) require.Error(t, err) wdFooPath := filepath.Join(workDir, "foo") - got, err = ioutil.ReadFile(wdFooPath) + got, err = os.ReadFile(wdFooPath) require.NoError(t, err) require.Equal(t, "OG content", string(got)) } err = runAtGitRef(nil, "git", dir, "HEAD", fn) require.NoError(t, err) - got, err := ioutil.ReadFile(fooPath) + got, err := os.ReadFile(fooPath) require.NoError(t, err) require.Equal(t, "new content", string(got)) } diff --git a/go.mod b/go.mod index 7fc56cb..6b400a5 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,19 @@ module github.com/willabides/benchdiff -go 1.16 +go 1.18 require ( - github.com/alecthomas/kong v0.2.16 - github.com/stretchr/testify v1.5.1 + github.com/alecthomas/kong v0.7.1 + github.com/stretchr/testify v1.8.2 github.com/willabides/mdtable v0.3.1 - golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 + golang.org/x/crypto v0.9.0 golang.org/x/perf v0.0.0-20201207232921-bdcc6220ee90 ) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/mattn/go-runewidth v0.0.9 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/sys v0.8.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum index 20bf4d5..db466ad 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,10 @@ cloud.google.com/go v0.0.0-20170206221025-ce650573d812/go.mod h1:aQUYkXzVsufM+Dw github.com/GoogleCloudPlatform/cloudsql-proxy v0.0.0-20190129172621-c8b1d7a94ddf/go.mod h1:aJ4qN3TfrelA6NZ6AXsXRfmEVaYin3EDbSPJrKS8OXo= github.com/aclements/go-gg v0.0.0-20170118225347-6dbb4e4fefb0/go.mod h1:55qNq4vcpkIuHowELi5C8e+1yUHtoLoOUR9QU5j7Tes= github.com/aclements/go-moremath v0.0.0-20161014184102-0ff62e0875ff/go.mod h1:idZL3yvz4kzx1dsBOAC+oYv6L92P1oFEhUXUB1A/lwQ= -github.com/alecthomas/kong v0.2.16 h1:F232CiYSn54Tnl1sJGTeHmx4vJDNLVP2b9yCVMOQwHQ= -github.com/alecthomas/kong v0.2.16/go.mod h1:kQOmtJgV+Lb4aj+I2LEn40cbtawdWJ9Y8QLq+lElKxE= +github.com/alecthomas/assert/v2 v2.1.0 h1:tbredtNcQnoSd3QBhQWI7QZ3XHOVkw1Moklp2ojoH/0= +github.com/alecthomas/kong v0.7.1 h1:azoTh0IOfwlAX3qN9sHWTxACE2oV8Bg2gAwBsMwDQY4= +github.com/alecthomas/kong v0.7.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U= +github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -15,34 +17,41 @@ github.com/gonum/internal v0.0.0-20181124074243-f884aa714029/go.mod h1:Pu4dmpkhS github.com/gonum/lapack v0.0.0-20181123203213-e4cdc5a0bff9/go.mod h1:XA3DeT6rxh2EAE789SSiSJNqxPaC0aE9J8NTOI0Jo/A= github.com/gonum/matrix v0.0.0-20181209220409-c518dec07be9/go.mod h1:0EXg4mc1CNP0HCqCz+K4ts155PXIlUywf0wqN+GfPZw= github.com/googleapis/gax-go v0.0.0-20161107002406-da06d194a00e/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= +github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-sqlite3 v1.14.5/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/willabides/mdtable v0.3.1 h1:JJw5qo09lr1fjfmw2FXoXUrFuh4bQT2cpK2t2tIszHI= github.com/willabides/mdtable v0.3.1/go.mod h1:o8N6onDZrqSMKjabh3V4Ela8/QODQAs7IxTvkU/uKgY= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= +golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/oauth2 v0.0.0-20170207211851-4464e7848382/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/perf v0.0.0-20201207232921-bdcc6220ee90 h1:P+M61+mQKVHzooHFlNUTNBfj+TqHiQOGgx2kKL7mHbA= golang.org/x/perf v0.0.0-20201207232921-bdcc6220ee90/go.mod h1:KRSrLY7jerMEa0Ih7gBheQ3FYDiSx6liMnniX1o3j2g= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= google.golang.org/api v0.0.0-20170206182103-3d017632ea10/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/grpc v0.0.0-20170208002647-2a6bf6142e96/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/benchstatter/benchstat_test.go b/pkg/benchstatter/benchstat_test.go index 4cad1cd..aba0708 100644 --- a/pkg/benchstatter/benchstat_test.go +++ b/pkg/benchstatter/benchstat_test.go @@ -4,7 +4,6 @@ import ( "bytes" "flag" "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -32,7 +31,7 @@ func TestBenchstat_Run(t *testing.T) { err = td.benchStat.OutputTables(&buf, result.Tables()) require.NoError(t, err) var want []byte - want, err = ioutil.ReadFile(goldenFile(td)) + want, err = os.ReadFile(goldenFile(td)) require.NoError(t, err) require.Equal(t, string(want), buf.String()) }) @@ -286,7 +285,7 @@ func updateGolden() (err error) { if err != nil { return err } - err = ioutil.WriteFile(goldenFile(td), buf.Bytes(), 0o600) + err = os.WriteFile(goldenFile(td), buf.Bytes(), 0o600) if err != nil { return err } diff --git a/script/benchdiff b/script/benchdiff index 3211c7d..7bbfe6a 100755 --- a/script/benchdiff +++ b/script/benchdiff @@ -2,10 +2,10 @@ set -e -workdir="$(pwd)" -CDPATH="" cd -- "$(dirname -- "$(dirname -- "$0")")" -bindir="$(pwd)/bin" +ROOT_DIR="$(CDPATH="" cd -- "$(dirname -- "$0")/.." && pwd -P)" -make -s bin/benchdiff -cd "$workdir" -exec "$bindir/benchdiff" "$@" +mkdir -p "$ROOT_DIR"/bin + +go build -o "$ROOT_DIR"/bin/benchdiff "$ROOT_DIR"/cmd/benchdiff + +exec "$ROOT_DIR"/bin/benchdiff "$@" diff --git a/script/bindown b/script/bindown index fc7bec7..340c4be 100755 --- a/script/bindown +++ b/script/bindown @@ -2,10 +2,12 @@ set -e -CDPATH="" cd -- "$(dirname -- "$(dirname -- "$0")")" +CDPATH="" cd -- "$(dirname -- "$0")/.." mkdir -p bin -[ -f bin/bindown ] || sh -c "$(curl -sfL https://github.com/WillAbides/bindown/releases/download/v3.4.2/bootstrap-bindown.sh)" +[ -f bin/bindown ] || sh -c "$( + curl -sfL https://github.com/WillAbides/bindown/releases/download/v3.20.2/bootstrap-bindown.sh +)" exec bin/bindown "$@" diff --git a/script/fmt b/script/fmt index 88e856c..fbb92ee 100755 --- a/script/fmt +++ b/script/fmt @@ -2,10 +2,11 @@ set -e -CDPATH="" cd -- "$(dirname -- "$(dirname -- "$0")")" +cd "$(git rev-parse --show-toplevel)" -make -s bin/gofumpt bin/handcrafted >/dev/null +script/bindown -q install gofumpt +script/bindown -q install handcrafted -git ls-files -o -c --exclude-standard '*.go' | - bin/handcrafted | - xargs bin/gofumpt -w -e -s +git ls-files -o -c --exclude-standard -- *.go | + bin/handcrafted | + xargs bin/gofumpt -w diff --git a/script/generate b/script/generate index 0aed64f..c659c3f 100755 --- a/script/generate +++ b/script/generate @@ -2,7 +2,7 @@ set -e -CDPATH="" cd -- "$(dirname -- "$(dirname -- "$0")")" +CDPATH="" cd -- "$(dirname -- "$0")/.." if [ "$1" = "--check" ]; then [ -z "$(git status --porcelain)" ] || { diff --git a/script/generate-readme b/script/generate-readme index 03f3611..80748ab 100755 --- a/script/generate-readme +++ b/script/generate-readme @@ -2,7 +2,7 @@ set -e -CDPATH="" cd -- "$(dirname -- "$(dirname -- "$0")")" +CDPATH="" cd -- "$(dirname -- "$0")/.." usage_pattern="*" diff --git a/script/goreleaser b/script/goreleaser index b53c348..47e63e5 100755 --- a/script/goreleaser +++ b/script/goreleaser @@ -2,7 +2,7 @@ set -e -CDPATH="" cd -- "$(dirname -- "$(dirname -- "$0")")" +CDPATH="" cd -- "$(dirname -- "$0")/.." -script/bindown install goreleaser > /dev/null +script/bindown -q install goreleaser bin/goreleaser "$@" diff --git a/script/lint b/script/lint index 8f14124..d4ac7c2 100755 --- a/script/lint +++ b/script/lint @@ -2,8 +2,9 @@ set -e -CDPATH="" cd -- "$(dirname -- "$(dirname -- "$0")")" +CDPATH="" cd -- "$(dirname -- "$0")/.." -make -s bin/golangci-lint bin/shellcheck +script/bindown -q install golangci-lint +script/bindown -q install shellcheck bin/golangci-lint run ./... bin/shellcheck script/* diff --git a/script/release b/script/release new file mode 100755 index 0000000..64bd918 --- /dev/null +++ b/script/release @@ -0,0 +1,22 @@ +#!/bin/sh + +set -e + +CDPATH="" cd -- "$(dirname -- "$0")/.." + +[ -n "$GITHUB_TOKEN" ] || { + echo GITHUB_TOKEN must be set + exit 1 +} + +script/bindown -q install goreleaser +script/bindown -q install semver-next + +GITHUB_SHA="${GITHUB_SHA:-"$(git rev-parse HEAD)"}" +GITHUB_REPOSITORY="${GITHUB_REPOSITORY:-"WillAbides/benchdiff"}" + +bin/semver-next "$GITHUB_REPOSITORY" -r "$GITHUB_SHA" --create-tag --require-labels + +git fetch --tags + +bin/goreleaser release diff --git a/script/test b/script/test index f2c8ea0..fb8e2db 100755 --- a/script/test +++ b/script/test @@ -2,6 +2,6 @@ set -e -CDPATH="" cd -- "$(dirname -- "$(dirname -- "$0")")" +CDPATH="" cd -- "$(dirname -- "$0")/.." go test -race -covermode=atomic ./...