Verified Commit 6a5281ef authored by Olivier Robardet's avatar Olivier Robardet
Browse files

Dedicated package for internal config

parent 4272b97a
Pipeline #158845986 passed with stages
in 5 minutes and 21 seconds
# Olivier Robardet's Go Makefile v1.0.0
#
# Targets:
#
# - setup: install dev dependencies (needs a valid and workin Go environment)
# - imports: list all direct imports for all the packages of the application
# - deps: list all dependencies (imports recursively) for all the packages of the application
# - all: default, just match 'build' target
......@@ -48,20 +51,21 @@ BINARY?=$(if $(filter $(OS),Windows_NT),$(BUILDDIR)/$(PROGRAM_NAME).exe,$(BUILDD
DEBUG:=0
# Version number to use when building the program
VERSION?=$(shell git describe --tags --always --match=v* 2> /dev/null || cat ${SOURCEDIR}/VERSION 2> /dev/null || echo v0.0.0)+dev
VERSION?=$(shell git describe --tags --match=v* 2> /dev/null || cat ${SOURCEDIR}/VERSION 2> /dev/null || echo v0.0.0)+dev
# Revision or VCS hash to use when building the program. Can be long, it may be truncated by the program at
REVISION?=$(shell git rev-parse HEAD || echo "")
# Build date&time to use when building the programme. Unlikely needed to be overriden.
BUILDTIME?=$(shell date +%FT%T%z)
MAIN_PACKAGE_PATH=$(shell go list . 2> /dev/null)/
LDFLAGS+=-X $(MAIN_PACKAGE_PATH)main.VERSION=${VERSION} -X $(MAIN_PACKAGE_PATH)main.REVISION=${REVISION} -X $(MAIN_PACKAGE_PATH)main.BUILDTIME=${BUILDTIME}
LDFLAGS+=-X $(MAIN_PACKAGE_PATH)config.VERSION=${VERSION} -X $(MAIN_PACKAGE_PATH)config.REVISION=${REVISION} -X $(MAIN_PACKAGE_PATH)config.BUILDTIME=${BUILDTIME}
ifeq ($(DEBUG),0)
LDFLAGS+=-s -w
else
LDFLAGS+=-X $(MAIN_PACKAGE_PATH)main.RELEASE=false
endif
CYCLOTHRESHOLD?=20
SOURCES:=$(shell find $(SOURCEDIR) -name '*.go' -not -path "$(SOURCEDIR)/vendor/*" 2>/dev/null)
PACKAGES:=$(shell go list ./...)
PACKAGEPATHS:=$(shell go list -f "{{.Dir}}" ./...)
CYCLOTHRESHOLD?=15
GOTESTCMD?=go test
GOTESTFLAGS?=
......@@ -75,6 +79,7 @@ PACKAGEPATHS:=$(shell go list -f "{{.Dir}}" ./...)
.DEFAULT_GOAL: all
.PHONY: all
all: build
.PHONY: has-depends _godoc_binary _golint_binary _gocyclo_binary _gosec_binary _upx_binary
......@@ -106,6 +111,11 @@ release: _upx_binary build
rebuild: clean build
.PHONY: setup
setup:
cd $(GOPATH)
go get -u golang.org/x/sys golang.org/x/text golang.org/x/lint/golint github.com/alecthomas/gocyclo github.com/securego/gosec/cmd/gosec
.PHONY: imports
imports:
@go list -f '{{ join .Imports "\n" }}' ./... | sort -u
......@@ -114,8 +124,8 @@ imports:
deps:
@go list -f '{{ join .Deps "\n" }}' ./... | sort -u
.PHONY: check checksmake g
check: fmt vet checkstyle cyclo secucheck
.PHONY: check checks
check: fmt vet checkstyle cyclo secucheck test
checks: check
.PHONY: fmt dofmt
......@@ -147,7 +157,7 @@ secucheck: $(SOURCES) | _gosec_binary
run: $(BINARY)
$(BINARY) $(RUNARGS)
$(BINARY): $(SOURCES) |
$(BINARY): $(SOURCES)
go build -ldflags "${LDFLAGS}" -o ${BINARY}
.PHONY: install
......@@ -160,7 +170,7 @@ clean:
if [ -f "$(BINARY)" ] ; then rm $(BINARY) ; fi
rm -fr $(COVERAGEREPORTDIR)
rm -fr $(DOCBUILDDIR)
rm -fr $(BUILDDIR)
-rmdir $(BUILDDIR) 2>/dev/null || true
$(COVERAGEREPORTDIR):
mkdir -p $(COVERAGEREPORTDIR)
......@@ -182,7 +192,7 @@ test-package/%: | $(COVERAGEREPORTDIR)
.SECONDEXPANSION:
COVERFILES=$(shell find $(COVERAGEREPORTDIR) -name '*.cover' -printf "%f\n" 2>/dev/null)
html-cover: _html-cover | $(COVERAGEREPORTDIR)
_html-cover: test $(addprefix html-cover-package/,$(COVERFILES))
_html-cover: $(addprefix html-cover-package/,$(COVERFILES))
html-cover-package/%: | $(COVERAGEREPORTDIR)
go tool cover -html=$(COVERAGEREPORTDIR)/$* -o $(COVERAGEREPORTDIR)/$(*:.cover=.html)
......
// Package config contains the internal configuration of the program.
package config
// APPNAME contains the application name
var APPNAME = "gitlab-ci-linter"
// VERSION contains the version of the program
var VERSION = "0.0.0-dev"
// REVISION contains the revision of the program
var REVISION = "HEAD"
// BUILDTIME contains the build date and time of the program
var BUILDTIME = ""
package config_test
import (
"github.com/stretchr/testify/assert"
"gitlab.com/orobardet/gitlab-ci-linter/config"
"testing"
)
func Test_APPNAME(t *testing.T) {
asserter := assert.New(t)
asserter.NotEmpty(config.APPNAME)
}
func Test_VERSION(t *testing.T) {
asserter := assert.New(t)
asserter.NotEmpty(config.VERSION)
}
func Test_REVISION(t *testing.T) {
asserter := assert.New(t)
asserter.NotEmpty(config.REVISION)
}
......@@ -24,6 +24,7 @@ import (
"encoding/json"
"errors"
"fmt"
"gitlab.com/orobardet/gitlab-ci-linter/config"
"io/ioutil"
"net"
"net/http"
......@@ -96,7 +97,7 @@ func initGitlabHTTPClientRequest(method string, url string, content string) (*ht
req, err := http.NewRequest(method, url, strings.NewReader(content))
req.Header.Add("Accept", "*/*")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("User-Agent", fmt.Sprintf("%s/%s", APPNAME, VERSION))
req.Header.Add("User-Agent", fmt.Sprintf("%s/%s", config.APPNAME, config.VERSION))
if personalAccessToken != "" {
req.Header.Add("PRIVATE-TOKEN", personalAccessToken)
}
......
......@@ -8,6 +8,7 @@ require (
github.com/go-ini/ini v1.52.0
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/stretchr/testify v1.6.1
github.com/urfave/cli/v2 v2.1.1
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd // indirect
gopkg.in/ini.v1 v1.52.0 // indirect
......
......@@ -3,6 +3,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSY
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/go-ini/ini v1.52.0 h1:3UeUAveYUTCYV/G0jNDiIrrtIeAl1oAjshYyU2PaAlQ=
......@@ -27,6 +29,9 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykE
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/urfave/cli/v2 v2.1.1 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k=
github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
......@@ -42,7 +47,10 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384 h1:TFlARGu6Czu1z7q93HTxcP1P+/ZFC/IKythI5RzrnRg=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.52.0 h1:j+Lt/M1oPPejkniCg1TkWE2J3Eh1oZTsHSXzMTzUXn4=
gopkg.in/ini.v1 v1.52.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
......@@ -24,24 +24,13 @@ import (
"fmt"
"github.com/fatih/color"
"github.com/urfave/cli/v2"
"gitlab.com/orobardet/gitlab-ci-linter/config"
"math"
"net/url"
"os"
"path/filepath"
)
// APPNAME contains the application name
var APPNAME = "gitlab-ci-linter"
// VERSION contains the version of the program
var VERSION = "0.0.0-dev"
// REVISION contains the revision of the program
var REVISION = "HEAD"
// BUILDTIME contains the build date and time of the program
var BUILDTIME = ""
// The Gitlab instance root URL to use.
var gitlabRootURL string
......@@ -88,7 +77,7 @@ func processPathArgument(path string) {
func main() {
cli.VersionPrinter = func(c *cli.Context) {
fmt.Printf("version=%s revision=%s built on=%s\n", VERSION, REVISION, BUILDTIME)
fmt.Printf("version=%s revision=%s built on=%s\n", config.VERSION, config.REVISION, config.BUILDTIME)
}
cli.AppHelpTemplate = `{{.Name}} - {{.Usage}}
......@@ -110,8 +99,8 @@ Usage:
{{end}}`
app := cli.NewApp()
app.Name = APPNAME
app.Version = fmt.Sprintf("%s (%s)", VERSION, REVISION[:int(math.Min(float64(len(REVISION)), 7))])
app.Name = config.APPNAME
app.Version = fmt.Sprintf("%s (%s)", config.VERSION, config.REVISION[:int(math.Min(float64(len(config.REVISION)), 7))])
app.Authors = []*cli.Author{
{Name: "Olivier ROBARDET"},
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment