Verified Commit 1a67fe0a authored by Tomasz Maczukin's avatar Tomasz Maczukin
Browse files

Add compilation CI job

parent 8416c704
Pipeline #113365891 passed with stage
in 1 minute and 1 second
compile:
image: golang:1.13.7-alpine3.11
script:
- apk add -U bash git make
- make version_info compile_all
artifacts:
paths:
- ./build/
expire_in: 7d
export VERSION ?= $(shell (scripts/version 2>/dev/null || echo "dev") | sed -e 's/^v//g')
export REVISION ?= $(shell git rev-parse --short HEAD || echo "unknown")
export BRANCH ?= $(shell git show-ref | grep "$(REVISION)" | grep -v HEAD | awk '{print $$2}' | sed 's|refs/remotes/origin/||' | sed 's|refs/heads/||' | sort | head -n 1)
export BUILT ?= $(shell date -u +%Y-%m-%dT%H:%M:%S%z)
export CGO_ENABLED ?= 0
export GOPATH ?= ".go/"
export BUILD_PLATFORMS ?= -osarch 'linux/amd64' -osarch 'darwin/amd64'
gox ?= $(GOPATH)/bin/gox
PKG := $(shell go list .)
PKGs := $(shell go list ./... | grep -vE "^/vendor/")
GO_LDFLAGS := -X $(PKG).VERSION=$(VERSION) \
-X $(PKG).REVISION=$(REVISION) \
-X $(PKG).BRANCH=$(BRANCH) \
-X $(PKG).BUILT=$(BUILT) \
-s -w
.PHONY: version_info
version_info:
# VERSION: $(VERSION)
# REVISION: $(REVISION)
# BRANCH: $(BRANCH)
# BUILT: $(BUILT)
.PHONY: compile
compile:
go build \
-o build/tlsctl \
-ldflags "$(GO_LDFLAGS)" \
.
.PHONY: compile_all
compile_all: $(gox)
# Building project in version $(VERSION) for $(BUILD_PLATFORMS)
$(gox) $(BUILD_PLATFORMS) \
-ldflags "$(GO_LDFLAGS)" \
-output="build/tlsctl-{{.OS}}-{{.Arch}}" \
.
.PHONY: fmt
fmt:
# Fixing project code formatting...
@go fmt $(PKGs) | awk '{if (NF > 0) {if (NR == 1) print "Please run go fmt for:"; print "- "$$1}} END {if (NF > 0) {if (NR > 0) exit 1}}'
$(gox):
# Installing gox
@go install github.com/mitchellh/gox
package main
import (
"fmt"
"os"
"github.com/sirupsen/logrus"
......@@ -12,6 +13,11 @@ func main() {
app.Name = "tlsctl"
app.Usage = "Set of commands to debug TLS certificates for GitLab Runner."
app.Description = "Set of commands to debug TLS certificates for GitLab Runner."
app.Version = Version().ShortLine()
cli.VersionPrinter = func(_ *cli.Context) {
fmt.Print(Version().Extended())
}
app.Commands = []cli.Command{
makeSaveCMD(),
......
#!/usr/bin/env bash
set -eo pipefail
version=$(cat VERSION || echo dev | sed -e 's/^v//g')
exact_tag=$(git describe --exact-match --tags --always 2>/dev/null | sed -e 's/^v//g' || echo "")
if [[ $(echo ${exact_tag} | grep -E "^[0-9]+\.[0-9]+\.[0-9]+$") ]]; then
echo ${exact_tag}
exit 0
fi
if [[ $(echo ${exact_tag} | grep -E "^[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]+$") ]]; then
echo ${exact_tag}
exit 0
fi
pre_release_info=$(git describe --long | sed -r "s/v[0-9\.]+(-rc[0-9]+)?-//")
echo "${version}-beta-${pre_release_info}"
package main
import (
"fmt"
"runtime"
"time"
)
var (
NAME = "tlsctl"
VERSION = "dev"
REVISION = "HEAD"
BRANCH = "HEAD"
BUILT = "now"
AuthorName = "GitLab Inc."
AuthorEmail = "support@gitlab.com"
)
type VersionInfo struct {
Name string
Version string
Revision string
Branch string
GOVersion string
BuiltAt string
OS string
Architecture string
}
func (v *VersionInfo) ShortLine() string {
return fmt.Sprintf("%s (%s)", v.Version, v.Revision)
}
func (v *VersionInfo) Extended() string {
version := fmt.Sprintln(v.Name)
version += fmt.Sprintf("Version: %s\n", v.Version)
version += fmt.Sprintf("Git revision: %s\n", v.Revision)
version += fmt.Sprintf("Git branch: %s\n", v.Branch)
version += fmt.Sprintf("GO version: %s\n", v.GOVersion)
version += fmt.Sprintf("Built: %s\n", v.BuiltAt)
version += fmt.Sprintf("OS/Arch: %s/%s\n", v.OS, v.Architecture)
return version
}
var version *VersionInfo
func Version() *VersionInfo {
if version != nil {
return version
}
built := BUILT
if built == "now" {
built = time.Now().UTC().Format(time.RFC3339)
}
version = &VersionInfo{
Name: NAME,
Version: VERSION,
Revision: REVISION,
Branch: BRANCH,
GOVersion: runtime.Version(),
BuiltAt: built,
OS: runtime.GOOS,
Architecture: runtime.GOARCH,
}
return version
}
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