From a54243a807040dab7af21952548a3a38b6e10752 Mon Sep 17 00:00:00 2001 From: Moshe Beladev Date: Sat, 23 Jul 2022 01:35:25 +0300 Subject: [PATCH] wip . . . . . . . . . . . . . . . --- .github/workflows/lint-test.yml | 58 +++++++++++++++++++++++++++++++++ .github/workflows/lint.yml | 12 ------- .github/workflows/test.yml | 22 ------------- .gitignore | 1 + .goreleaser.yaml | 38 +++++++++++++++++++++ Makefile | 20 +++++++----- cmd/version.go | 18 ++-------- version/version.go | 23 +++++++++++++ 8 files changed, 133 insertions(+), 59 deletions(-) create mode 100644 .github/workflows/lint-test.yml delete mode 100644 .github/workflows/lint.yml delete mode 100644 .github/workflows/test.yml create mode 100644 .goreleaser.yaml create mode 100644 version/version.go diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml new file mode 100644 index 00000000..9a4eae7f --- /dev/null +++ b/.github/workflows/lint-test.yml @@ -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) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index f0e0bcd3..00000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: lint -on: push - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: golangci/golangci-lint-action@v2 - name: golangci-lint - with: - version: v1.45.0 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index b6e43794..00000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: test -on: push -jobs: - test: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - goVer: [1.17] - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.goVer }} - - run: go test -cover ./... - env: - CGO_ENABLED: 0 - - name: coverage - if: github.repository_owner == 'moshebe' - run: | - make coverage - bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5264e6e9..20f9a0e7 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ gebug .gebug coverage.txt +dist diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 00000000..e8d1df8f --- /dev/null +++ b/.goreleaser.yaml @@ -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 diff --git a/Makefile b/Makefile index e31e96a6..d9416331 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,21 @@ +# 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) -VERSION ?= $(GITHUB_ACTION_VERSION_TAG) +BUILD_DATE ?= $(shell date -u +"%Y-%m-%d") +VERSION ?= $(shell git describe --long --tags) BASENAME ?= gebug BINARY ?= ${BASENAME} -VERSION_PKG = github.com/moshebe/gebug/cmd +VERSION_PKG = github.com/moshebe/gebug/version +LDFLAGS = -ldflags \ + "-X ${VERSION_PKG}.Version=${VERSION} -X ${VERSION_PKG}.Revision=${COMMIT} -X ${VERSION_PKG}.Branch=${BRANCH}" STATICCHECK := staticcheck @@ -29,9 +32,8 @@ PKGS := $(shell go list ./...) all: compile package compile: test build -.PHONY: build build: - go build -ldflags "-X ${VERSION_FILE}.Commit=${COMMIT} -X ${VERSION_FILE}.Tag=${VERSION}" + go build ${LDFLAGS} .PHONY: buildall $(MAKE) build GOOS=windows BINARY=${BINARY}-windows-${GOARCH}.exe @@ -54,7 +56,7 @@ package: cp -r conf $(OUTDIR) check: - go install honnef.co/go/tools/cmd/staticcheck + go install honnef.co/go/tools/cmd/staticcheck@latest staticcheck ./... clean: @@ -63,4 +65,4 @@ clean: rm -rf $(WORKROOT)/.gebug rm -rf $(GOPATH)/pkg/linux_amd64 -.PHONY: all compile test package clean build \ No newline at end of file +.PHONY: all compile test package clean build buildall \ No newline at end of file diff --git a/cmd/version.go b/cmd/version.go index c2b09266..f23d3568 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -3,14 +3,10 @@ package cmd import ( "fmt" + "github.com/moshebe/gebug/version" "github.com/spf13/cobra" ) -var ( - Tag string - Commit string -) - func init() { rootCmd.AddCommand(versionCmd) } @@ -20,16 +16,6 @@ var versionCmd = &cobra.Command{ Short: "Gebug version", Long: "Print the version number of Gebug", Run: func(cmd *cobra.Command, args []string) { - var v string - switch { - case Tag != "": - v = Tag - case Commit != "": - v = "dev-" + Commit - default: - v = "development" - } - - fmt.Println("version: ", v) + fmt.Println(version.Name()) }, } diff --git a/version/version.go b/version/version.go new file mode 100644 index 00000000..3c408653 --- /dev/null +++ b/version/version.go @@ -0,0 +1,23 @@ +package version + +var ( + Version string + Revision string + Branch string +) + +func Name() string { + if Version != "" { + return Version + } + v := "" + if Branch != "" { + v = Branch + "-" + } + + if Revision != "" { + return v + Revision + } + + return "development" +}