Skip to content

Commit

Permalink
Merge pull request #11 from dominikwinter/10-goreleaser-for-automatic…
Browse files Browse the repository at this point in the history
…-release-of-new-go-versions

add goreleaser
  • Loading branch information
dominikwinter authored Feb 16, 2024
2 parents cbcba6e + 0dd9b19 commit 9e1f576
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 12 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: goreleaser

on:
push:
tags:
- "*"

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Fetch all tags
run: git fetch --force --tags
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.22
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: ${{ env.GITHUB_REF_NAME }}
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.PUBLISHER_TOKEN }}
30 changes: 30 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
builds:
- binary: pno
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=0
flags:
- -mod=vendor

release:
prerelease: auto

universal_binaries:
- replace: true

brews:
-
name: pno
homepage: https://github.com/dominikwinter/pno
tap:
owner: dominikwinter
name: homebrew-tap

checksum:
name_template: checksum.txt
26 changes: 15 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
.PHONY: default
default: build

help: Makefile ## Display this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "; printf "Usage:\n\n make \033[36m<target>\033[0m [VARIABLE=value...]\n\nTargets:\n\n"}; {printf " \033[36m%-10s\033[0m %s\n", $$1, $$2}'

.PHONY: run
run:
run: ## Run app for development
go run

.PHONY: test
test:
test: ## Run tests
go test -v --race -cpu 2 -cover -shuffle on -vet '' ./...

.PHONY: build
build:
go build -trimpath -o ./bin/pno
go build -ldflags="-s -w" -trimpath -o ./bin/pno

.PHONY: install
install:
install: ## Install app
install -b -S -v ./bin/pno ${GOPATH}/bin/.

.PHONY: clean
clean:
clean: ## Clean up
rm -rf ./bin/*
go mod tidy

.PHONY: release
release:
release: ## Build release binaries
mkdir -p bin
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o bin/pno-macos-arm64
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/pno-linux-amd64
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -o bin/pno-linux-386
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o bin/pno-windows-amd64.exe
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -o bin/pno-windows-386.exe
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" -trimpath -o bin/pno-macos-arm64
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -trimpath -o bin/pno-linux-amd64
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags="-s -w" -trimpath -o bin/pno-linux-386
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -trimpath -o bin/pno-windows-amd64.exe
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags="-s -w" -trimpath -o bin/pno-windows-386.exe
29 changes: 28 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"runtime/debug"

"github.com/dominikwinter/pno/cmd"
)
Expand All @@ -15,7 +16,8 @@ func main() {
val Validate a personal number
args:
-h Help`
-h Help
-V Version`

if len(os.Args) < 2 {
fmt.Fprintln(os.Stderr, usage)
Expand All @@ -26,6 +28,31 @@ func main() {
command, args := os.Args[1], os.Args[2:]

switch command {
case "-h":
fmt.Fprintln(os.Stderr, usage)
os.Exit(0)

case "-V":
info, ok := debug.ReadBuildInfo()
if !ok {
return
}

var revision string
var time string

for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
revision = setting.Value
}
if setting.Key == "vcs.time" {
time = setting.Value
}
}

fmt.Fprintf(os.Stdout, "%s %s\n", revision, time)
os.Exit(0)

case "gen":
cmd.Gen(args)

Expand Down

0 comments on commit 9e1f576

Please sign in to comment.