diff --git a/.circleci/config.yml b/.circleci/config.yml index 967ae8f6..6f592aaf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,4 +1,17 @@ -version: 2 +version: 2.1 + +workflows: + version: 2 + main: + jobs: + - test + - release: + filters: + branches: + ignore: /.*/ + tags: + only: /v[0-9]+(\.[0-9]+)*(-.*)*/ + jobs: test: docker: @@ -10,8 +23,11 @@ jobs: - run: make check - run: make test -workflows: - version: 2 - test: - jobs: - - test + release: + docker: + - image: cimg/go:1.19 + resource_class: large + steps: + - checkout + - run: go install github.com/goreleaser/goreleaser@latest + - run: goreleaser diff --git a/.gitignore b/.gitignore index 51f03f57..243eddc7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ debug.test TODO profile.out /bin -.idea +/dist diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 00000000..435fc4ff --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,19 @@ +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +project_name: conflow + +release: + prerelease: auto + name_template: "conflow v{{.Version}}" + +builds: + - main: ./cmd/conflow + env: + - CGO_ENABLED=0 + ldflags: + - -s -w -X github.com/conflowio/conflow/src/conflow.Version={{.Version}} + goos: + - linux + - darwin + mod_timestamp: '{{ .CommitTimestamp }}' diff --git a/Makefile b/Makefile index 96b17903..5e5544f4 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,15 @@ .DEFAULT_GOAL := help +VERSION := $(shell git describe --tags --always --dirty --match "v[0-9]+(\.[0-9]+)*(-.*)*") + .PHONY: help help: ## Show help @cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' +.PHONY: version +version: + @echo "${VERSION}" + .PHONY: test test: ## Runs all tests @./test.sh @@ -18,7 +24,7 @@ build: bin/conflow ## Build the conflow binary bin/conflow: @echo "Building bin/conflow" @go version - @GOBIN="$(PWD)/bin" go install -ldflags="-s -w" ./cmd/conflow/ + GOBIN="$(PWD)/bin" go install -ldflags="-s -w -X github.com/conflowio/conflow/src/conflow.Version=${VERSION}" ./cmd/conflow/ .PHONY: clean clean: ## Clean all built files diff --git a/cmd/conflow/main.go b/cmd/conflow/main.go index 836ffa47..5c7af335 100644 --- a/cmd/conflow/main.go +++ b/cmd/conflow/main.go @@ -17,6 +17,7 @@ import ( "github.com/conflowio/conflow/cmd/conflow/generate" "github.com/conflowio/conflow/cmd/conflow/openapi" + "github.com/conflowio/conflow/src/conflow" ) func rootCommand() *cobra.Command { @@ -26,17 +27,31 @@ func rootCommand() *cobra.Command { Args: cobra.NoArgs, SilenceUsage: true, SilenceErrors: true, + Version: conflow.Version, RunE: func(cmd *cobra.Command, args []string) error { return cmd.Help() }, } + cmd.AddCommand(versionCmd()) cmd.AddCommand(generate.Command()) cmd.AddCommand(openapi.Command()) return cmd } +func versionCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "version", + Short: "Returns the version number", + Args: cobra.NoArgs, + Run: func(cmd *cobra.Command, args []string) { + cmd.Println(conflow.Version) + }, + } + return cmd +} + func main() { ctx, cancel := context.WithCancel(context.Background()) defer cancel() diff --git a/src/conflow/version.go b/src/conflow/version.go new file mode 100644 index 00000000..954f4d2b --- /dev/null +++ b/src/conflow/version.go @@ -0,0 +1,9 @@ +// Copyright (c) 2017 Opsidian Ltd. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +package conflow + +var Version = "v0.0.0"