Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version info and goreleaser #473

Merged
merged 2 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: lint-test
on:
push:
tags:
- v*
branches:
- "*"
paths-ignore:
- '**/README.md'
- '**/webui'
pull_request:
permissions:
contents: read
jobs:
golangci:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '^1.18'
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.46.2
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.18.x
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/cache@v2
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Test
run: go test -cover ./...
- name: Coverage
if: github.repository_owner == 'moshebe'
run: |
make coverage
bash <(curl -s https://codecov.io/bash)
12 changes: 0 additions & 12 deletions .github/workflows/lint.yml

This file was deleted.

22 changes: 0 additions & 22 deletions .github/workflows/test.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
gebug
.gebug
coverage.txt
dist
38 changes: 38 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
before:
hooks:
- go mod tidy
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
ldflags:
- -X github.com/moshebe/gebug/version.Version={{.Version}}
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
brews:
- name: gebug
homepage: https://github.com/moshebe/gebug
tap:
owner: moshebe
name: homebrew-pkg
32 changes: 27 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
# Makefile params
SHELL = /bin/bash -o pipefail

WORKROOT := $(shell pwd)
OUTDIR := $(WORKROOT)/output

export PATH := $(shell go env GOPATH)/bin:$(PATH)
export GO111MODULE := on
GOARCH = amd64
GOOS ?= $(shell go env GOOS)
GOPATH ?= $(shell go env GOPATH)
COMMIT ?= $(shell git rev-parse HEAD)
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
BUILD_DATE ?= $(shell date -u +"%Y-%m-%d")
VERSION ?= $(shell git describe --long --tags)
BASENAME ?= gebug
BINARY ?= ${BASENAME}
VERSION_PKG = github.com/moshebe/gebug/version
LDFLAGS = -ldflags \
"-X ${VERSION_PKG}.Version=${VERSION} -X ${VERSION_PKG}.Revision=${COMMIT} -X ${VERSION_PKG}.Branch=${BRANCH}"

GOFLAGS := -race
STATICCHECK := staticcheck

ARCH := $(shell getconf LONG_BIT)
Expand All @@ -21,7 +33,12 @@ all: compile package

compile: test build
build:
go build -ldflags "-X main.version=$(GEBUG_VERSION) -X main.commit=$(GIT_COMMIT)"
go build ${LDFLAGS}

.PHONY: buildall
$(MAKE) build GOOS=windows BINARY=${BINARY}-windows-${GOARCH}.exe
$(MAKE) build GOOS=linux BINARY=${BINARY}-linux-${GOARCH}
$(MAKE) build GOOS=darwin BINARY=${BINARY}-darwin-${GOARCH}

test: test-case vet-case
test-case:
Expand All @@ -33,6 +50,11 @@ coverage:
echo -n > coverage.txt
for pkg in $(PKGS) ; do go test -coverprofile=profile.out -covermode=atomic $${pkg} && cat profile.out >> coverage.txt; done

package:
mkdir -p $(OUTDIR)/bin
mv bfe $(OUTDIR)/bin
cp -r conf $(OUTDIR)

check:
go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck ./...
Expand All @@ -43,4 +65,4 @@ clean:
rm -rf $(WORKROOT)/.gebug
rm -rf $(GOPATH)/pkg/linux_amd64

.PHONY: all compile test package clean build
.PHONY: all compile test package clean build buildall
5 changes: 3 additions & 2 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"

"github.com/moshebe/gebug/version"
"github.com/spf13/cobra"
)

Expand All @@ -12,9 +13,9 @@ func init() {

var versionCmd = &cobra.Command{
Use: "version",
Short: "Gebug's version",
Short: "Gebug version",
Long: "Print the version number of Gebug",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("v0.0.1")
fmt.Println(version.Name())
},
}
27 changes: 13 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,44 @@ go 1.18
require (
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/gin-gonic/contrib v0.0.0-20201101042839-6a891bf89f19
github.com/gin-gonic/gin v1.8.1
github.com/gin-gonic/gin v1.7.4
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-retryablehttp v0.7.1
github.com/iancoleman/strcase v0.2.0
github.com/manifoldco/promptui v0.9.0
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
github.com/pkg/errors v0.9.1
github.com/spf13/afero v1.9.2
github.com/spf13/cobra v1.5.0
github.com/stretchr/testify v1.8.0
github.com/stretchr/testify v1.7.0
go.uber.org/zap v1.21.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.10.1 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/go-playground/validator/v10 v10.9.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/ugorji/go/codec v1.2.6 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/crypto v0.0.0-20220408190544-5352b0902921 // indirect
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f // indirect
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
Loading