Skip to content

Commit

Permalink
start using goreleaser (#110)
Browse files Browse the repository at this point in the history
* start using goreleaser
  • Loading branch information
natefinch authored Sep 29, 2018
1 parent 23a95a3 commit f8bfaf8
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 22 deletions.
53 changes: 53 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
project_name: gnorm
release:
github:
owner: gnormal
name: gnorm
draft: true
build:
binary: gnorm
main: .
ldflags: -s -w -X gnorm.org/gnorm/cli.timestamp={{.Date}} -X gnorm.org/gnorm/cli.commitHash={{.Commit}} -X gnorm.org/gnorm/cli.version={{.Version}}
goos:
- darwin
- linux
- windows
- freebsd
- netbsd
- openbsd
- dragonfly
goarch:
- amd64
- 386
- arm
- arm64
ignore:
- goos: openbsd
goarch: arm
goarm: 6
env:
- CGO_ENABLED=0
archive:
name_template: "{{.Binary}}_{{.Version}}_{{.Os}}-{{.Arch}}"
replacements:
amd64: 64bit
386: 32bit
arm: ARM
arm64: ARM64
darwin: macOS
linux: Linux
windows: Windows
openbsd: OpenBSD
netbsd: NetBSD
freebsd: FreeBSD
dragonfly: DragonFlyBSD
format: tar.gz
format_overrides:
- goos: windows
format: zip
files:
- LICENSE
snapshot:
name_template: SNAPSHOT-{{ .Commit }}
checksum:
name_template: '{{ .ProjectName }}_{{ .Version }}_checksums.txt'
40 changes: 21 additions & 19 deletions mage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
package main

import (
"errors"
"log"
"os"
"regexp"

"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
Expand Down Expand Up @@ -36,30 +39,29 @@ func Generate() error {
return sh.Run("go", "generate", "./...")
}

// Generates binaries for all supported versions. Currently that means a
// combination of windows, linux, and OSX in 32 bit and 64 bit formats. The
// files will be dumped in the local directory with names according to their
// supported platform.
func All() error {
if err := genSite(); err != nil {
return err
// Generates a new release. Expects the TAG environment variable to be set,
// which will create a new tag with that name.
func Release() (err error) {
releaseTag := regexp.MustCompile(`^v1\.[0-9]+\.[0-9]+$`)

tag := os.Getenv("TAG")
if !releaseTag.MatchString(tag) {
return errors.New("TAG environment variable must be in semver v1.x.x format, but was " + tag)
}
defer cleanup()

ldf, err := flags()
if err != nil {
if err := sh.RunV("git", "tag", "-a", tag, "-m", tag); err != nil {
return err
}
for _, OS := range []string{"windows", "darwin", "linux"} {
for _, ARCH := range []string{"amd64", "386"} {
log.Printf("running go build for GOOS=%s GOARCH=%s", OS, ARCH)
env := []string{"GOOS=" + OS, "GOARCH=" + ARCH}
if err := runWith(env, "go", "build", "-tags", "make", "-o", "gnorm_"+OS+"_"+ARCH, "--ldflags="+ldf); err != nil {
return err
}
}
if err := sh.RunV("git", "push", "origin", tag); err != nil {
return err
}
return err
defer func() {
if err != nil {
sh.RunV("git", "tag", "--delete", "$TAG")
sh.RunV("git", "push", "--delete", "origin", "$TAG")
}
}()
return sh.RunV("goreleaser")
}

// Removes generated cruft. This target shouldn't ever be necessary, since the
Expand Down
11 changes: 8 additions & 3 deletions mage_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@ func gitTag() (string, error) {
func cleanup() error {
log.Print("removing generated hugo site")
err := rm("./cli/public")
if err != nil {
fmt.Println("error removing generated hugo folder:", err)
}
log.Print("removing generated statik package")
if err2 := rm("./cli/statik"); err2 != nil {
return err2
if err := rm("./cli/statik"); err != nil {
fmt.Println("error removing statik folder:", err)
}
if err := rm("dist"); err != nil {
fmt.Println("error removing release folder:", err)
}
return err
}

func genSite() error {
Expand Down

0 comments on commit f8bfaf8

Please sign in to comment.