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

v2 release WIP #166

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
13 changes: 8 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ jobs:
- name: Checkout
uses: actions/checkout@v3.1.0

- name: Setup go
uses: actions/setup-go@v3.3.0
with:
go-version: 1.20.x

- name: golangci-lint
uses: golangci/golangci-lint-action@v3.2.0
with:
version: v1.49.0
version: v1.51.1

mod-tidy:
name: Go Mod Tidy
Expand All @@ -34,7 +39,7 @@ jobs:
- name: Setup go
uses: actions/setup-go@v3.3.0
with:
go-version: 1.15.x
go-version: 1.20.x

- name: Cache
uses: actions/cache@v3.0.10
Expand All @@ -57,9 +62,7 @@ jobs:
strategy:
matrix:
go-version:
- 1.17.x
- 1.18.x
- 1.19.x
- 1.20.x

steps:
- name: Checkout
Expand Down
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ linters:
- gocritic
- gofmt
- goimports
- golint
- gosec
- govet
- lll
- maligned
- megacheck
- misspell
- nakedret
- prealloc
- revive
- stylecheck
- unconvert
- unparam
Expand Down
121 changes: 59 additions & 62 deletions bin/style
Original file line number Diff line number Diff line change
@@ -1,62 +1,59 @@
#!/usr/bin/env ruby

require 'fileutils'
require 'open3'
require 'open-uri'

class Style
class << self
INSTALLER_URL = 'https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh'
EXECUTABLE = 'golangci-lint'
VERSION = '1.49.0'
VERSION_TAG = "v#{VERSION}"

def call
install unless up_to_date?
run(*ARGV)
end

private

def install_path
gopath = ENV.fetch('GOPATH', ENV.fetch('HOME')).split(':').first
File.join(gopath, 'bin')
end

def bin_path
File.join(install_path, EXECUTABLE)
end

def exist?
File.executable?(bin_path)
end

def up_to_date?
return false unless exist?
out, stat = Open3.capture2(bin_path, '--version')
raise("Unable to check version of #{bin_path}") unless stat.success?
out.match(/\b#{VERSION}\b/)
end

def install
puts "Installing #{EXECUTABLE}..."

open(INSTALLER_URL) do |installer|
Open3.popen2('sh', '-s', '--', '-b', install_path, VERSION_TAG) do |stdin, out, stat|
IO.copy_stream(installer, stdin)
stdin.close
print out.read

raise("failed to install #{EXECUTABLE} #{VERSION_TAG}") unless stat.value.success?
end
end
end

def run(*argv)
config = ENV.fetch('GOLANGCI_CONFIG', '.golangci.yml')
exec(bin_path, 'run', '--config', config, *argv)
end
end
end

__FILE__ == $PROGRAM_NAME and Style.call
#!/bin/sh

# This script is intentionally written to be POSIX compliant to be as portable as possible

set -e

VERSION="1.51.1"
VERSION_TAG="v${VERSION}"

INSTALLER_URL="github.com/golangci/golangci-lint/cmd/golangci-lint"
EXECUTABLE="$(basename "${INSTALLER_URL}")"

INSTALL_PATH="${HOME}/.local/share/${EXECUTABLE}/${VERSION}"
EXECUTABLE_PATH="${INSTALL_PATH}/${EXECUTABLE}" # e.g. $HOME/.local/share/golangci/1.32.0/golangci-lint

GOPATH="${GOPATH:-${HOME}}"
GOPATH_PRIMARY="${GOPATH%%:*}" # Delete :* from the end, yielding the first path
BIN_INSTALL_PATH="${GOPATH_PRIMARY}/bin"
BIN_EXECUTABLE_PATH="${BIN_INSTALL_PATH}/${EXECUTABLE}" # e.g. $HOME/bin/golangci-lint

installed() {
[ -x "${EXECUTABLE_PATH}" ]
}

install() {
echo "Installing ${EXECUTABLE} version ${VERSION}" >&2

mkdir -p "${INSTALL_PATH}"
GOBIN="${INSTALL_PATH}" go install "${INSTALLER_URL}@${VERSION_TAG}"
}

linked() {
[ -L "${BIN_EXECUTABLE_PATH}" ] && [ "$(readlink "${BIN_EXECUTABLE_PATH}")" = "${EXECUTABLE_PATH}" ]
}

link() {
mkdir -p "${BIN_INSTALL_PATH}"
rm -fv "${BIN_EXECUTABLE_PATH}"
ln -sfv "${EXECUTABLE_PATH}" "${BIN_EXECUTABLE_PATH}"
}

case "$1" in
"--installed")
installed
;;
"--install")
installed || install
;;
"--linked")
installed && linked
;;
"--link")
(installed || install) && (linked || link)
;;
*)
installed || install
exec "${EXECUTABLE_PATH}" "$@"
;;
esac
2 changes: 1 addition & 1 deletion bugsnag/bugsnagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (snagger *bugsnagger) Setup(apiKey string, commit string, env string, packa
// Add the bugsnag package and it's folder location on disk to bugsnag's ProjectPackages.
// This will ensure that Notify calls from bugsnagger.go will always share the same file name
// and will retain grouping across Shopify/goose dependency upgrades.
packages = append(packages, "main*", "github.com/Shopify/goose/bugsnag")
packages = append(packages, "main*", "github.com/Shopify/goose/v2/bugsnag")
if _, file, _, ok := runtime.Caller(0); ok {
gooseMod := strings.TrimSuffix(file, "bugsnag/bugsnagger.go")
packages = append(packages, gooseMod+"*")
Expand Down
2 changes: 1 addition & 1 deletion bugsnag/bugsnagger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestSetup(t *testing.T) {
require.Equal(t, env, bugsnaggo.Config.ReleaseStage)
require.Equal(t, pack, bugsnaggo.Config.ProjectPackages[0])
require.Equal(t, "main*", bugsnaggo.Config.ProjectPackages[1])
require.Equal(t, "github.com/Shopify/goose/bugsnag", bugsnaggo.Config.ProjectPackages[2])
require.Equal(t, "github.com/Shopify/goose/v2/bugsnag", bugsnaggo.Config.ProjectPackages[2])
require.True(t, strings.Contains(bugsnaggo.Config.ProjectPackages[3], projectDir+"/*"))
require.True(t, bugsnaggo.Config.Synchronous)
}
Expand Down
2 changes: 1 addition & 1 deletion bugsnag/with_class_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestFormatErrorClass(t *testing.T) {
err := WithErrorClass(errors.New("test error"), "FOO")
formatted := fmt.Sprintf("%+v", err)
require.Contains(t, formatted, "FOO: test error")
require.Contains(t, formatted, "github.com/Shopify/goose/bugsnag.TestFormatErrorClass")
require.Contains(t, formatted, "github.com/Shopify/goose/v2/bugsnag.TestFormatErrorClass")
require.Contains(t, formatted, projectDir+"/bugsnag/with_class_test.go")
require.Contains(t, formatted, "testing.tRunner")
require.Contains(t, formatted, "src/testing/testing.go")
Expand Down
2 changes: 1 addition & 1 deletion concurrency/limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"golang.org/x/sync/semaphore"

"github.com/Shopify/goose/statsd"
"github.com/Shopify/goose/v2/statsd"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion concurrency/throttler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"time"

"github.com/Shopify/goose/timetracker"
"github.com/Shopify/goose/v2/timetracker"
)

func NewThrottler(limiter Limiter, tracker timetracker.Tracker, waitTimeout time.Duration) Throttler {
Expand Down
2 changes: 1 addition & 1 deletion concurrency/throttler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/Shopify/goose/timetracker"
"github.com/Shopify/goose/v2/timetracker"
)

func TestThrottler(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: goose

up:
- go:
version: "1.19.2"
version: "1.20"
modules: true

commands:
Expand All @@ -11,7 +11,7 @@ commands:
godoc -http=:6060
test: go test -race ./...
style:
run: bin/style
desc: Static verification using gometalinter or autofix issues when possible.
run: bin/style run
desc: Static verification using golangci or autofix issues when possible.
syntax:
optional: --fix
2 changes: 1 addition & 1 deletion genmain/component.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package genmain

import "github.com/Shopify/goose/safely"
import "github.com/Shopify/goose/v2/safely"

// Component is used to represent various "components". At a high level, main()
// essentially cobbles together a few components whose lifecycles are managed
Expand Down
8 changes: 4 additions & 4 deletions genmain/genmain.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (

"gopkg.in/tomb.v2"

"github.com/Shopify/goose/logger"
"github.com/Shopify/goose/metrics"
"github.com/Shopify/goose/safely"
"github.com/Shopify/goose/statsd"
"github.com/Shopify/goose/v2/logger"
"github.com/Shopify/goose/v2/metrics"
"github.com/Shopify/goose/v2/safely"
"github.com/Shopify/goose/v2/statsd"
)

var log = logger.New("genmain")
Expand Down
2 changes: 1 addition & 1 deletion genmain/genmain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/require"
"gopkg.in/tomb.v2"

"github.com/Shopify/goose/genmain"
"github.com/Shopify/goose/v2/genmain"
)

type testComponent struct {
Expand Down
19 changes: 14 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
module github.com/Shopify/goose
module github.com/Shopify/goose/v2

go 1.15
go 1.20

require (
github.com/DataDog/datadog-go v4.8.1+incompatible
github.com/Microsoft/go-winio v0.5.0 // indirect
github.com/bugsnag/bugsnag-go/v2 v2.1.1
github.com/bugsnag/panicwrap v1.3.4
github.com/google/pprof v0.0.0-20210804190019-f964ff605595
github.com/gorilla/mux v1.8.0
github.com/ianlancetaylor/demangle v0.0.0-20210724235854-665d3a6fe486 // indirect
github.com/imdario/mergo v0.3.12
github.com/leononame/clock v0.1.6
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
Expand All @@ -18,9 +16,20 @@ require (
github.com/stretchr/testify v1.8.1
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637
)

require (
github.com/Microsoft/go-winio v0.5.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/ianlancetaylor/demangle v0.0.0-20210724235854-665d3a6fe486 // indirect
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
golang.org/x/sys v0.0.0-20210817190340-bfb29a6856f2 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ github.com/Microsoft/go-winio v0.5.0 h1:Elr9Wn+sGKPlkaBvwu4mTrxtmOp3F3yV9qhaHbXG
github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y=
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/bugsnag/bugsnag-go/v2 v2.1.1 h1:/X6xB3DvfMCNOSopEvGkOpDSk0iTq4yBSp7SkiV7nM8=
github.com/bugsnag/bugsnag-go/v2 v2.1.1/go.mod h1:XEgTxTSo37lM/jpzZY9a8FJgJCqZMEagthLA6TSDl+o=
Expand Down Expand Up @@ -62,16 +61,11 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cO
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210817190340-bfb29a6856f2 h1:c8PlLMqBbOHoqtjteWm5/kbe6rNY2pbRfbIMVnepueo=
golang.org/x/sys v0.0.0-20210817190340-bfb29a6856f2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
6 changes: 3 additions & 3 deletions logger/loggable.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
)

// This create a private key-space in the Context, meaning that only this package can get or set "contextKey" types
type contextKey int
type contextKey struct{}

const (
logFieldsKey contextKey = iota
var (
logFieldsKey = contextKey{}
)

type Loggable interface {
Expand Down
15 changes: 1 addition & 14 deletions logger/loggable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func ExampleWatchingLoggable() {
func TestEmptyContext(t *testing.T) {
ctx := context.Background()
// Using a basic type on purpose, disable linter
ctx = context.WithValue(ctx, "a", "b") //nolint:golint,staticcheck
ctx = context.WithValue(ctx, "a", "b") //nolint:revive,staticcheck
// Not showing up in logs
checkData(ctx, t, logrus.Fields{"component": "testing"})
}
Expand Down Expand Up @@ -116,19 +116,6 @@ func TestWithField(t *testing.T) {
})
}

func TestLoggableKeyClash(t *testing.T) {
ctx := context.Background()
ctx = WithField(ctx, "a", "b")

// logFieldsKey is an int declared as a contextKey, so trying to set an int shouldn't override the contextKey
// Using a basic type on purpose, disable linter
ctx = context.WithValue(ctx, int(logFieldsKey), "foo") //nolint:golint,staticcheck

checkData(ctx, t, logrus.Fields{
"a": "b",
})
}

func TestChildContext(t *testing.T) {
ctx := context.Background()
ctx = WithField(ctx, "a", "b")
Expand Down
Loading