From 97eae0915cccce7fff1cce5387a9140e1320333a Mon Sep 17 00:00:00 2001 From: Michael Fridman Date: Wed, 13 Oct 2021 09:06:10 -0400 Subject: [PATCH] Add CI workflows to generate GitHub Releases and binaries on new tag push (#277) --- .github/workflows/goreleaser.yml | 30 +++++++++++++++++++ .goreleaser.yml | 51 ++++++++++++++++++++++++++++++++ cmd/goose/main.go | 10 ++++++- goose.go | 3 +- 4 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/goreleaser.yml create mode 100644 .goreleaser.yml diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml new file mode 100644 index 0000000..377671f --- /dev/null +++ b/.github/workflows/goreleaser.yml @@ -0,0 +1,30 @@ +name: goreleaser + +on: + push: + tags: + - "*" + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + # either 'goreleaser' (default) or 'goreleaser-pro' + distribution: goreleaser + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution + # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..0f2efdc --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,51 @@ +# Documentation at https://goreleaser.com +project_name: goose + +gomod: + proxy: true + +builds: + - env: + - CGO_ENABLED=0 + main: ./cmd/goose + binary: goose + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + # Custom ldflags templates. + # Default is `-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser`. + ldflags: + - -s -w + +# You can disable this pipe in order to not upload any artifacts. +# Defaults to false. +release: + disable: false + +archives: + - replacements: + 386: i386 + amd64: x86_64 + name_template: "{{ tolower .Binary }}_{{ tolower .Os }}_{{ tolower .Arch }}" + format: binary + +checksum: + name_template: "checksums.txt" + +snapshot: + name_template: "{{ incpatch .Version }}-next" + +changelog: + use: github + sort: asc + # Commit messages matching the regexp listed here will be removed from + # the changelog. + filters: + exclude: + - "^docs:" + - "^test:" +# TODO(mf): add docker support? diff --git a/cmd/goose/main.go b/cmd/goose/main.go index e2e9947..5f40092 100644 --- a/cmd/goose/main.go +++ b/cmd/goose/main.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "os" + "runtime/debug" "github.com/pressly/goose/v3" ) @@ -20,12 +21,19 @@ var ( sequential = flags.Bool("s", false, "use sequential numbering for new migrations") ) +var ( + gooseVersion = "" +) + func main() { flags.Usage = usage flags.Parse(os.Args[1:]) if *version { - fmt.Println(goose.VERSION) + if buildInfo, ok := debug.ReadBuildInfo(); ok && buildInfo != nil && gooseVersion == "" { + gooseVersion = buildInfo.Main.Version + } + fmt.Printf("goose version:%s\n", gooseVersion) return } if *verbose { diff --git a/goose.go b/goose.go index f3abd95..0816461 100644 --- a/goose.go +++ b/goose.go @@ -7,7 +7,8 @@ import ( "strconv" ) -const VERSION = "v3.0.0" +// Deprecated: VERSION will no longer be supported in v4. +const VERSION = "v3.2.0" var ( minVersion = int64(0)