From 0cd7dab556f1f6583291a439b4acfd77320f80d5 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Wed, 14 Aug 2019 01:10:28 +0100 Subject: [PATCH] ci: added release (semi)automation - security: updated Golang version to 1.12.8 for CI builds - added: configuration for build and release automation using GoReleaser (https://goreleaser.com) - (Releases will be semi-automatic for now due to the need of the access token. When/if project specific access token is supported then I'll complete the release stage of the pipeline.) - added: version.go for printing out the versions --- .gitignore | 1 + .gitlab-ci.yml | 23 +++++++---------------- .goreleaser.yml | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 13 ++++++++----- bin/.gitkeep | 0 version.go | 14 ++++++++++++++ 6 files changed, 80 insertions(+), 21 deletions(-) create mode 100644 .goreleaser.yml delete mode 100644 bin/.gitkeep create mode 100644 version.go diff --git a/.gitignore b/.gitignore index 83522d7..0fda4a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ tags bin/* !bin/.gitkeep +dist/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ba621f5..dea0993 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,25 +1,16 @@ --- -image: golang:1.12.6 +image: golang:1.12.8 + +variables: + CGO_ENABLED: 0 stages: - test -- build #- release -test: +test:unit: stage: test script: - - make test + - make test_unit -build: - stage: build - script: - - make build - artifacts: - expire_in: 1 hour - name: "pominal-$CI_COMMIT_REF_SLUG" - paths: - - bin/pominal - only: - refs: - - master +#release diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..5564d2c --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,50 @@ +--- +project_name: pominal + +before: + hooks: + - go mod download + +builds: +- binary: pominal + env: + - CGO_ENABLED=0 + flags: + - -a + - -v + goarch: + - 386 + - amd64 + goos: + - linux + id: pominal-build + ldflags: + - s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}} -X main.goversion={{.Env.GOVERSION}} + +archives: +- files: + - LICENSE + - README.md + format: tar.gz + id: pominal-archive + name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}" + replacements: + 386: i386 + amd64: x86_64 + wrap_in_directory: true + +checksum: + algorithm: sha256 + name_template: "{{ .ProjectName }}-{{ .Version }}-CHECKSUMS.txt" + +snapshot: + name_template: "SNAPSHOT-{{ .ShortCommit }}" + +changelog: + sort: desc + filters: + exclude: + - "^docs:" + - "^test:" + - "^chore:" + - "^ci:" diff --git a/Makefile b/Makefile index 7d89eeb..cab15e3 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,16 @@ -.PHONY: all test build clean +NAME := pominal +BIN_DIR := ./bin +BIN_FILE := $(BIN_DIR)/$(NAME) -all: test build +.PHONY: all test_unit build clean -test: +all: test_unit build + +test_unit: go test -v -cover ./... build: - go build -a -v -o bin/pominal + go build -a -v -o $(BIN_FILE) clean: go clean - find bin -type f -not -iname .gitkeep | xargs -I v rm v diff --git a/bin/.gitkeep b/bin/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/version.go b/version.go new file mode 100644 index 0000000..0c950ae --- /dev/null +++ b/version.go @@ -0,0 +1,14 @@ +package main + +import "fmt" + +var ( + commit string + date string + goversion string + version string +) + +func Version() { + fmt.Printf("Version: %s\nCommit: %s\nGo Version: %s\nDate: %s", version, commit, goversion, date) +}