Skip to content

Commit

Permalink
build(make): bye bye Makefile, hello Magefile ^^
Browse files Browse the repository at this point in the history
  • Loading branch information
mgjules committed Apr 11, 2022
1 parent 1b58fb6 commit 08ac99a
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 38 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/release_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ name: goreleaser

on:
push:
branches:
- master
tags:
- "*"
- "v*.*.*"

jobs:
goreleaser:
Expand All @@ -20,8 +22,10 @@ jobs:
with:
go-version: 1.16
-
name: Set up Swaggo
run: go install github.com/swaggo/swag/cmd/swag@latest
name: Set up extra tools
run: |
go install github.com/swaggo/swag/cmd/swag@latest
go install github.com/magefile/mage@latest
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
Expand Down
6 changes: 4 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ env:
- GO111MODULE=on
before:
hooks:
- make go_mod_tidy
- make swag
- mage tidy
- mage vet
- mage test
- mage docs
builds:
- env:
- CGO_ENABLED=0
Expand Down
32 changes: 0 additions & 32 deletions Makefile

This file was deleted.

2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ require (
github.com/golang/protobuf v1.5.1 // indirect
github.com/google/uuid v1.2.0
github.com/iancoleman/strcase v0.1.3
github.com/imdario/mergo v0.3.12 // indirect
github.com/json-iterator/go v1.1.10
github.com/kelseyhightower/envconfig v1.4.0
github.com/leodido/go-urn v1.2.1 // indirect
github.com/magefile/mage v1.11.0
github.com/mailru/easyjson v0.7.7 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
github.com/swaggo/gin-swagger v1.3.0
Expand Down
5 changes: 4 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/iancoleman/strcase v0.1.3 h1:dJBk1m2/qjL1twPLf68JND55vvivMupZ4wIzE8CTdBw=
github.com/iancoleman/strcase v0.1.3/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE=
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
Expand All @@ -95,6 +97,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/magefile/mage v1.11.0 h1:C/55Ywp9BpgVVclD3lRnSYCwXTYxmSppIgLeDYlNuls=
github.com/magefile/mage v1.11.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
Expand Down Expand Up @@ -158,7 +162,6 @@ go.uber.org/dig v1.10.0 h1:yLmDDj9/zuDjv3gz8GQGviXMs9TfysIUMUilCpgzUJY=
go.uber.org/dig v1.10.0/go.mod h1:X34SnWGr8Fyla9zQNO2GSO2D+TIuqB14OS8JhYocIyw=
go.uber.org/fx v1.13.1 h1:CFNTr1oin5OJ0VCZ8EycL3wzF29Jz2g0xe55RFsf2a4=
go.uber.org/fx v1.13.1/go.mod h1:bREWhavnedxpJeTq9pQT53BbvwhUv7TcpsOqcH4a+3w=
go.uber.org/goleak v0.10.0 h1:G3eWbSNIskeRqtsN/1uI5B+eP73y3JUuBsv9AZjehb4=
go.uber.org/goleak v0.10.0/go.mod h1:VCZuO8V8mFPlL0F5J5GK1rtHV3DrFcQ1R8ryq7FK0aI=
go.uber.org/multierr v1.4.0 h1:f3WCSC2KzAcBXGATIxAB1E2XuCpNU255wNKZ505qi3E=
go.uber.org/multierr v1.4.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
Expand Down
116 changes: 116 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// +build mage

package main

import (
"os"

"github.com/imdario/mergo"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)

const (
binPath = "./bin"
projectName = "spoty"
ldFlags = "-s -w"
tags = "jsoniter"
opts = "-trimpath"
)

var defaultEnvs = map[string]string{
"CGO_ENABLED": "0",
}

func init() {
os.Setenv("GO111MODULE", "on")
}

// Run tests
func Test() error {
return sh.Run("go", "test", "./...")
}

// Run tests with race detector
func TestRace() error {
return sh.Run("go", "test", "-race", "./...")
}

// Run go vet linter
func Vet() error {
return sh.Run("go", "vet", "./...")
}

// Run go mod tidy
func Tidy() error {
return sh.Run("go", "mod", "tidy")
}

// Generates docs
func Docs() error {
return sh.Run("swag", "init", "--parseDependency", "--parseInternal")
}

type Build mg.Namespace

// Builds for all supported popular OS/Arch
func (b Build) All() error {
mg.Deps(
b.LinuxAmd64,
b.LinuxArm64,
b.MacOSAmd64,
b.MacOSArm64,
b.WinAmd64,
)
return nil
}

// Builds for Linux 64bit
func (Build) LinuxAmd64() error {
env := map[string]string{
"GOOS": "linux",
"GOARCH": "amd64",
}
return sh.RunWith(flagEnvs(env), "go", "build", opts, "-tags", tags, "-ldflags", ldFlags, "-o", binPath+"/"+projectName+"-linux-amd64")
}

// Builds for Linux ARM 64bit
func (Build) LinuxArm64() error {
env := map[string]string{
"GOOS": "linux",
"GOARCH": "arm64",
}
return sh.RunWith(flagEnvs(env), "go", "build", opts, "-tags", tags, "-ldflags", ldFlags, "-o", binPath+"/"+projectName+"-linux-arm64")
}

// Builds for MacOS 64bit
func (Build) MacOSAmd64() error {
env := map[string]string{
"GOOS": "darwin",
"GOARCH": "amd64",
}
return sh.RunWith(flagEnvs(env), "go", "build", opts, "-tags", tags, "-ldflags", ldFlags, "-o", binPath+"/"+projectName+"-macos-amd64")
}

// Builds for MacOS M1
func (Build) MacOSArm64() error {
env := map[string]string{
"GOOS": "darwin",
"GOARCH": "arm64",
}
return sh.RunWith(flagEnvs(env), "go", "build", opts, "-tags", tags, "-ldflags", ldFlags, "-o", binPath+"/"+projectName+"-macos-arm64")
}

// Builds for Windows 64bit
func (Build) WinAmd64() error {
env := map[string]string{
"GOOS": "windows",
"GOARCH": "amd64",
}
return sh.RunWith(flagEnvs(env), "go", "build", opts, "-tags", tags, "-ldflags", ldFlags, "-o", binPath+"/"+projectName+"-win-amd64.exe")
}

func flagEnvs(env map[string]string) map[string]string {
mergo.Merge(&env, defaultEnvs)
return env
}

0 comments on commit 08ac99a

Please sign in to comment.