Skip to content

Commit

Permalink
Add goreleaser and version
Browse files Browse the repository at this point in the history
  • Loading branch information
bandesz committed Oct 16, 2022
1 parent e7f2afd commit f794760
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 8 deletions.
28 changes: 22 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ debug.test
TODO
profile.out
/bin
.idea
/dist
19 changes: 19 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -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 }}'
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions cmd/conflow/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions src/conflow/version.go
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit f794760

Please sign in to comment.