Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ie version command #238

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-test-release-tagged.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v4
- name: Build all targets.
run: |
make build-all
make build-all RELEASE_BUILD=true
- name: Run unit tests across all targets.
run: |
make test-all
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-test-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v4
- name: Build all targets.
run: |
make build-all
make build-all RELEASE_BUILD=true
- name: Run unit tests across all targets.
run: |
make test-all
Expand Down
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ API_BINARY := $(BINARY_DIR)/api

# -------------------------- Native build targets ------------------------------

RELEASE_BUILD := false
LATEST_TAG := $(shell git describe --tags --abbrev=0)
LATEST_COMMIT := $(shell git rev-parse --short HEAD)
BUILD_DATE := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
MODULE_ROOT := $(shell go list -m)
build-ie:
@echo "Building the Innovation Engine CLI..."
@CGO_ENABLED=0 go build -o "$(IE_BINARY)" cmd/ie/ie.go
ifeq ($(RELEASE_BUILD), true)
@CGO_ENABLED=0 go build -ldflags "-X $(MODULE_ROOT)/cmd/ie/commands.VERSION=$(LATEST_TAG) -X $(MODULE_ROOT)/cmd/ie/commands.COMMIT=$(LATEST_COMMIT) -X $(MODULE_ROOT)/cmd/ie/commands.DATE=$(BUILD_DATE)" -o "$(IE_BINARY)" cmd/ie/ie.go
else
@CGO_ENABLED=0 go build -ldflags "-X $(MODULE_ROOT)/cmd/ie/commands.VERSION=dev -X $(MODULE_ROOT)/cmd/ie/commands.COMMIT=$(LATEST_COMMIT) -X $(MODULE_ROOT)/cmd/ie/commands.DATE=$(BUILD_DATE)" -o "$(IE_BINARY)" cmd/ie/ie.go
endif


build-all: build-ie
Expand All @@ -17,7 +26,7 @@ build-all: build-ie

install-ie:
@echo "Installing the Innovation Engine CLI..."
@CGO_ENABLED=0 go install cmd/ie/ie.go
@CGO_ENABLED=0 go install -ldflags "-X $(MODULE_ROOT)/cmd/ie/commands.VERSION=dev -X $(MODULE_ROOT)/cmd/ie/commands.COMMIT=$(LATEST_COMMIT) -X $(MODULE_ROOT)/cmd/ie/commands.DATE=$(BUILD_DATE)" cmd/ie/ie.go

# ------------------------------ Test targets ----------------------------------

Expand Down
25 changes: 25 additions & 0 deletions cmd/ie/commands/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package commands

import "github.com/spf13/cobra"

var (
VERSION = "dev"
COMMIT = "N/A"
DATE = "N/A"
)

var versionCommand = &cobra.Command{
Use: "version",
Short: "Print the version of the Innovation Engine",
RunE: func(cmd *cobra.Command, args []string) error {
cmd.Printf("Version: %s\n", VERSION)
cmd.Printf("Commit: %s\n", COMMIT)
cmd.Printf("Date: %s\n", DATE)

return nil
},
}

func init() {
rootCommand.AddCommand(versionCommand)
}
Loading