change to meta package, move config
ci/woodpecker/push/build Pipeline was successful Details

main
gapodo 2023-12-26 22:21:27 +01:00
parent e5b2ecec93
commit e8ec5009c8
9 changed files with 60 additions and 19 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
go-import-redirector
/go-import-redirector
go-import-redirector.yaml
**.old

View File

@ -1,7 +1,7 @@
variables:
- &golang_image 'golang:1.20'
- &golang_image 'golang:1.21'
- &goproxy_override ''
- &goproxy_setup |-
if [ -n "$${GOPROXY_OVERRIDE:-}" ]; then

View File

@ -20,10 +20,14 @@ SHASUM ?= shasum -a 256
# Construct the version strings
# VERSION default to dev or in CI next
# VERSION default to dev or in CI next for default branch, and branch name for everything else...
ifneq ($(CI),)
# in CI
VERSION ?= next
ifeq ($(CI_REPO_DEFAULT_BRANCH),$(CI_COMMIT_BRANCH))
VERSION ?= next
else
VERSION ?= $(CI_COMMIT_BRANCH)
endif
else
# not in CI
VERSION ?= dev
@ -34,8 +38,11 @@ VERSION_NUMBER ?= 0.0.0
# Use CI_COMMIT_TAG from CI if set as version and version number
ifneq ($(CI_COMMIT_TAG),)
ISTAG := "true"
VERSION := $(CI_COMMIT_TAG:v%=%)
VERSION_NUMBER := ${VERSION}
else
ISTAG := "false"
endif
# Use CI provided SHA, else use git
@ -46,6 +53,8 @@ endif
SOURCE_SHA ?= $(shell git rev-parse HEAD)
SOURCE_SHA_SHORT := $(shell echo ${SOURCE_SHA} | head -c 8)
COMMITTIME = $(shell git log -1 --format=%ct | xargs -I{} date -u +%Y%m%d%H%M%S -d "@{}")
# VERSIONED_BINARY is the base output name for xgo
VERSIONED_BINARY := $(BINARY_BASE_NAME)-$(VERSION)
@ -55,7 +64,13 @@ VERSIONED_BINARY := $(BINARY_BASE_NAME)-$(VERSION)
# WP CI=woodpecker CI_COMMIT_TAG CI_REPO_DEFAULT_BRANCH CI_COMMIT_SHA CI_COMMIT_PULL_REQUEST
# Default LDFlags, stripping, dwarfing, statically linking and adding the version and commit to pkg/meta, extendable via LDFLAGS
LDFLAGS := $(LDFLAGS) -s -w -X ${GO_PACKAGE}/pkg/meta.version=${VERSION} -X ${GO_PACKAGE}/pkg/meta.commit=${SOURCE_SHA}
LDFLAGS := $(LDFLAGS) -s -w
LDFLAGS := $(LDFLAGS) -X ${GO_PACKAGE}/pkg/meta.version=${VERSION}
LDFLAGS := $(LDFLAGS) -X ${GO_PACKAGE}/pkg/meta.commit=${SOURCE_SHA}
LDFLAGS := $(LDFLAGS) -X ${GO_PACKAGE}/pkg/meta.commitTime=${COMMITTIME}
LDFLAGS := $(LDFLAGS) -X ${GO_PACKAGE}/pkg/meta.isTag=${ISTAG}
LDFLAGS := $(LDFLAGS) -X ${GO_PACKAGE}/pkg/meta.branch=${CI_COMMIT_BRANCH}
LDFLAGS := $(LDFLAGS) -X ${GO_PACKAGE}/pkg/meta.defaultBranch=${CI_REPO_DEFAULT_BRANCH}
# Disable cgo, but overridable
CGO_ENABLED ?= 0

View File

@ -42,7 +42,7 @@ func Execute() {
func init() {
cobra.OnInitialize(initConfig)
rootCmd.Flags().StringVarP(&cfgFile, "config", "c", "", "config file (default order is $HOME/go-import-redirector.yaml, /etc/go-import-redirector.yaml, ./go-import-redirector.yaml)")
rootCmd.Flags().StringVarP(&cfgFile, "config", "c", "", "config file (default order is $HOME/go-import-redirector.yaml, /etc/go-import-redirector/go-import-redirector.yaml, ./go-import-redirector.yaml)")
rootCmd.Flags().StringVarP(&bind, "bind", "b", ":3000", "the address and port on which to serve the webserver (default :3000)")
rootCmd.Flags().BoolVarP(&hotReload, "hotreload", "r", true, "Change hot reloading (default true)")
}

3
go.mod
View File

@ -1,11 +1,12 @@
module git.kle.li/tools/go-import-redirector
go 1.20
go 1.21.5
require (
github.com/fsnotify/fsnotify v1.6.0
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.15.0
go.kle.li/tools/go-meta v0.0.1
)
require (

7
go.sum
View File

@ -57,6 +57,7 @@ github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5y
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
@ -99,6 +100,7 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
@ -131,9 +133,11 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
@ -147,6 +151,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/afero v1.9.3 h1:41FoI0fD7OR7mGcKE/aOiLkGreyf8ifIOQmJANWogMk=
github.com/spf13/afero v1.9.3/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y=
@ -177,6 +182,8 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.kle.li/tools/go-meta v0.0.1 h1:0ShRamAYgITCUE6DiCbkwzWe6aEo6aHyfS25umzRaXc=
go.kle.li/tools/go-meta v0.0.1/go.mod h1:B05kZ1niBY70bR2C355aafM4PF1quBFAAFYFVBZCXo0=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=

View File

@ -38,7 +38,7 @@ func New(cfgFile string, hotReload bool, reloadFunction func()) *Configuration {
fmt.Println("Unable to determine $HOME, not searching it for potential config")
}
c.v.AddConfigPath("/etc/")
c.v.AddConfigPath("/etc/go-import-redirector/")
c.v.AddConfigPath(".")
c.v.SetConfigType("yaml")
c.v.SetConfigName("go-import-redirector")

View File

@ -3,24 +3,42 @@
package meta
import "strings"
var (
version = "dev"
commit = "none"
import (
"go.kle.li/tools/go-meta/buildmeta"
"go.kle.li/tools/go-meta/shared"
)
var (
isTag = "false"
branch = ""
defaultBranch = ""
version = ""
commit = ""
commitTime = ""
)
var mdp = buildmeta.NewPackageMetadata(&shared.PackageMetadataInput{
IsTag: isTag,
Branch: branch,
Version: version,
CommitSha: commit,
CommitTime: commitTime,
DefaultBranch: defaultBranch,
})
func GetVersion() string {
return strings.TrimSpace(version)
return mdp.Version
}
func GetPackageVersion() string {
return mdp.GoCommitVersion
}
func GetCommit() string {
return strings.TrimSpace(commit)
return mdp.CommitSha
}
func GetShortCommit() string {
if len(GetCommit()) <= 8 {
return GetCommit()
}
return GetCommit()[:8]
_, slug := mdp.GetCommitShaSlug(8)
return slug
}