Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
.

.

.

.

.

.

.

.

.

.

.

.

.

.

.
  • Loading branch information
moshebe committed Jul 22, 2022
1 parent e7a90e4 commit a54243a
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 59 deletions.
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
20 changes: 11 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -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:
Expand All @@ -63,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
18 changes: 2 additions & 16 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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())
},
}
23 changes: 23 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit a54243a

Please sign in to comment.