From 0dd9b19a8621709fdd79b3499694f830ff9d0331 Mon Sep 17 00:00:00 2001 From: Dominik Winter <2269503+dominikwinter@users.noreply.github.com> Date: Fri, 16 Feb 2024 20:22:28 +0100 Subject: [PATCH] add goreleaser --- .github/workflows/release.yml | 33 +++++++++++++++++++++++++++++++++ .goreleaser.yml | 30 ++++++++++++++++++++++++++++++ Makefile | 26 +++++++++++++++----------- main.go | 29 ++++++++++++++++++++++++++++- 4 files changed, 106 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..de78a58 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 }} diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..8b8aae9 --- /dev/null +++ b/.goreleaser.yml @@ -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 diff --git a/Makefile b/Makefile index 7757812..b9d3a9b 100644 --- a/Makefile +++ b/Makefile @@ -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\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 diff --git a/main.go b/main.go index fb8997e..2a72198 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "runtime/debug" "github.com/dominikwinter/pno/cmd" ) @@ -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) @@ -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)