Skip to content

Commit

Permalink
feat: add goreleaser build
Browse files Browse the repository at this point in the history
  • Loading branch information
Moch Lutfi committed Sep 29, 2020
1 parent 8a229e2 commit 0f3560a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/gorelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Releaser
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.15
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21 changes: 21 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
project_name: optgen
env:
- GO111MODULE=on
builds:
-
main: main.go
binary: optgen
ldflags:
- -s -w
- -X main.Version={{.Major}}.{{.Minor}}.{{.Patch}}
env:
- CGO_ENABLED=0
goos:
- darwin
- linux
- windows
goarch:
- amd64
hooks:
post:
- upx --brute "{{ .Path }}"
21 changes: 16 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import (
)

var (
sourceFile, tagName, structName string
writeMode, allFields bool
sourceFile, tagName, structName string
writeMode, allFields, showVersion bool

version string = "dev"

funcMap = template.FuncMap{
"title": strings.Title,
Expand All @@ -31,16 +33,25 @@ func initCLI() {
flag.StringVar(&tagName, "tag", "opt", "custom tag")
flag.StringVar(&structName, "name", "", "struct name")
flag.BoolVar(&writeMode, "w", false, "enable write mode")
flag.BoolVar(&showVersion, "v", false, "show version")
flag.BoolVar(&allFields, "all", false, "generate all fields")
flag.Parse()
}

func main() {
initCLI()

if showVersion {
fmt.Printf("version: %s", version)

return
}

const exampleMessage = "e.g: optgen -file sample-file.go -name Thing"
if sourceFile == "" || structName == "" {
log.Fatalf("Source file and struct name must be provided.\n%s", exampleMessage)
}
}

func main() {
initCLI()
source, err := ioutil.ReadFile(sourceFile)
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 0f3560a

Please sign in to comment.