From cbe26c57971c1bda8f3eada8008190fe1395ea7c Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Thu, 21 Feb 2019 15:59:16 +0100 Subject: [PATCH] Add makefile --- Makefile | 42 ++++++++++++++++++++++++++++++++++++++++++ go.mod | 2 ++ go.sum | 4 ++++ internal/tools.go | 21 +++++++++++++++++++++ scripts/git-version.sh | 21 +++++++++++++++++++++ 5 files changed, 90 insertions(+) create mode 100644 Makefile create mode 100644 internal/tools.go create mode 100755 scripts/git-version.sh diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..b8c9cb8a --- /dev/null +++ b/Makefile @@ -0,0 +1,42 @@ +PROJDIR=$(dir $(realpath $(firstword $(MAKEFILE_LIST)))) + +# change to project dir so we can express all as relative paths +$(shell cd $(PROJDIR)) + +PROJ=agola +ORG_PATH=github.com/sorintlab +REPO_PATH=$(ORG_PATH)/$(PROJ) + +VERSION ?= $(shell scripts/git-version.sh) + +LD_FLAGS="-w -X $(REPO_PATH)/version.Version=$(VERSION)" + +$(shell mkdir -p bin ) +$(shell mkdir -p tools/bin ) + +AGOLA_TAGS = sqlite_unlock_notify + +.PHONY: all +all: build + +.PHONY: build +build: bin/agola bin/agola-toolbox + +.PHONY: test +test: tools/bin/gocovmerge + @scripts/test.sh + +# don't use existing file names and track go sources, let's do this to the go tool +.PHONY: bin/agola +bin/agola: + GO111MODULE=on go build $(if $(AGOLA_TAGS),-tags "$(AGOLA_TAGS)") -ldflags $(LD_FLAGS) -o $(PROJDIR)/bin/agola $(REPO_PATH)/cmd/agola + +# toolbox MUST be statically compiled so it can be used in any image for that arch +# TODO(sgotti) cross compile to multiple archs +.PHONY: bin/agola-toolbox +bin/agola-toolbox: + CGO_ENABLED=0 GO111MODULE=on go build $(if $(AGOLA_TAGS),-tags "$(AGOLA_TAGS)") -ldflags $(LD_FLAGS) -o $(PROJDIR)/bin/agola-toolbox $(REPO_PATH)/cmd/toolbox + +.PHONY: tools/bin/gocovmerge +tools/bin/gocovmerge: + GOBIN=$(PROJDIR)/tools/bin go install github.com/wadey/gocovmerge diff --git a/go.mod b/go.mod index 5f2b99ea..dccfd536 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,8 @@ require ( github.com/docker/docker v1.13.1 github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.3.3 // indirect + github.com/dsnet/compress v0.0.0-20171208185109-cc9eb1d7ad76 // indirect + github.com/go-bindata/go-bindata v1.0.0 // indirect github.com/go-ini/ini v1.42.0 // indirect github.com/go-sql-driver/mysql v1.4.1 // indirect github.com/google/go-cmp v0.3.0 diff --git a/go.sum b/go.sum index 4429e940..c07c5b7b 100644 --- a/go.sum +++ b/go.sum @@ -32,6 +32,7 @@ github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKoh github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/docker/go-units v0.3.3 h1:Xk8S3Xj5sLGlG5g67hJmYMmUgXv5N4PhkjJHHqrwnTk= github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/dsnet/compress v0.0.0-20171208185109-cc9eb1d7ad76/go.mod h1:KjxHHirfLaw19iGT70HvVjHQsL1vq1SRQB4yOsAfy2s= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4 h1:qk/FSDDxo05wdJH28W+p5yivv7LuLYLRXPPD8KQCtZs= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= @@ -39,6 +40,9 @@ github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-bindata/go-bindata v1.0.0 h1:DZ34txDXWn1DyWa+vQf7V9ANc2ILTtrEjtlsdJRF26M= +github.com/go-bindata/go-bindata v1.0.0/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo= +github.com/go-ini/ini v1.41.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-ini/ini v1.42.0 h1:TWr1wGj35+UiWHlBA8er89seFXxzwFn11spilrrj+38= github.com/go-ini/ini v1.42.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA= diff --git a/internal/tools.go b/internal/tools.go new file mode 100644 index 00000000..cf0a5e76 --- /dev/null +++ b/internal/tools.go @@ -0,0 +1,21 @@ +// Copyright 2019 Sorint.lab +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build tools + +package tools + +import ( + _ "github.com/go-bindata/go-bindata" +) diff --git a/scripts/git-version.sh b/scripts/git-version.sh new file mode 100755 index 00000000..a60cdc40 --- /dev/null +++ b/scripts/git-version.sh @@ -0,0 +1,21 @@ +#!/bin/sh -e + +# parse the current git commit hash +COMMIT=`git rev-parse HEAD` + +# check if the current commit has a matching tag +TAG=$(git describe --exact-match --abbrev=0 --tags ${COMMIT} 2> /dev/null || true) + +# use the matching tag as the version, if available +if [ -z "$TAG" ]; then + VERSION=$COMMIT +else + VERSION=$TAG +fi + +# check for changed files (not untracked files) +if [ -n "$(git diff --shortstat 2> /dev/null | tail -n1)" ]; then + VERSION="${VERSION}-dirty" +fi + +echo $VERSION