Repository: pressly/goose (language: go)

Issue:
Binary releases
Hi all,

First off - thanks for stepping up and taking over this project!

I'd love to see binary releases published to your GitHub repo. Doing a `go get` to grab the CLI at runtime is a little scary, since we can't pin a version (to my knowledge). Even scarier given that this is mucking with databases.

In terms of implementation, we're big fans of [goreleaser](https://goreleaser.com/) - it does all the heavy lifting for you.

Would be happy to take a crack at a PR if y'all would be open to it.


Discussion / hints:
Yep, `goreleaser` is awesome and I am a big fan. Kudos to @caarlos0

We were short on bandwidth but would happily accept a PR to build binaries with `goreleaser`
@mfridman We do have this `dist` target in Makefile:
https://github.com/pressly/goose/blob/master/Makefile#L2-L9

Please feel free to use it to generate new binaries in `bin/` folder and then upload them into Github release.
I always forget to do this 😅

To clarify, do you want to continue doing this manually and close this issue, or should we automate it?
Up to you :)

I mean, automated releases via Github Actions would be the best of course :)
Agreed, automated CI for releases (incl. binaries) driven by GitHub Actions 🚀
Alright, let's do this.

Historically, we built binaries for:

```
GOOS=darwin  GOARCH=amd64
GOOS=linux   GOARCH=amd64
GOOS=linux   GOARCH=386
GOOS=windows GOARCH=amd64
GOOS=windows GOARCH=386
```

However, we can probably remove 32-bit support and support `darwin`, `linux` and `windows`, against `arm64` and `amd64`

```
darwin/amd64
darwin/arm64
linux/amd64
linux/arm64
windows/arm64 .. is this possible even?
windows/amd64 
```

looks like `windows/arm64` support was added with https://golang.org/doc/go1.17#windows, nice!

Fix patch:
diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml
new file mode 100644
index 000000000..377671f39
--- /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 000000000..0f2efdc6f
--- /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 e2e994791..5f4009207 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 f3abd95ea..0816461d1 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)


Test patch: