Skip to content
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
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ GOLANG_CROSS_VERSION ?= v1.23
SYSROOT_DIR ?= sysroots
SYSROOT_ARCHIVE ?= sysroots.tar.bz2

CLI_BUILD_FLAGS := -X 'globstar.dev/pkg/cli.version=$$(git describe --tags 2>/dev/null || echo dev)'

.PHONY: sysroot-pack
sysroot-pack:
@tar cf - $(SYSROOT_DIR) -P | pv -s $[$(du -sk $(SYSROOT_DIR) | awk '{print $1}') * 1024] | pbzip2 > $(SYSROOT_ARCHIVE)
Expand Down Expand Up @@ -48,7 +50,7 @@ release:

.PHONY: test
test:
@CGO_CFLAGS="-w" go test -coverprofile=coverage.out -covermode=atomic ./cmd/... ./pkg/...
@CGO_CFLAGS="-w" go test -coverprofile=coverage.out -covermode=atomic ./cmd/... ./pkg/...
@go tool cover -func=coverage.out | grep total: | awk '{print "Total coverage: " $$3}'
@rm coverage.out

Expand All @@ -59,8 +61,8 @@ fmt:
@echo "Done."

build:
CGO_ENABLED=1 go build -o bin/globstar ./cmd/globstar
CGO_ENABLED=1 go build -ldflags "$(CLI_BUILD_FLAGS)" -o bin/globstar ./cmd/globstar

test-builtin-rules:
echo "Testing built-in rules..."
./bin/globstar test -d checkers/
./bin/globstar test -d checkers/
12 changes: 6 additions & 6 deletions goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ builds:
goarch:
- amd64
ldflags:
- "-X 'main.version={{ .Version }}'"
- "-X 'globstar.dev/pkg/cli.version={{ .Version }}'"
# darwin-arm64
- id: globstar-darwin-arm64
main: ./cmd/globstar
Expand All @@ -29,7 +29,7 @@ builds:
goarch:
- arm64
ldflags:
- "-X 'main.version={{ .Version }}'"
- "-X 'globstar.dev/pkg/cli.version={{ .Version }}'"
# linux-amd64
- id: globstar-linux-amd64
main: ./cmd/globstar
Expand All @@ -43,7 +43,7 @@ builds:
goarch:
- amd64
ldflags:
- "-X 'main.version={{ .Version }}'"
- "-X 'globstar.dev/pkg/cli.version={{ .Version }}'"
# linux-arm64
- id: globstar-linux-arm64
main: ./cmd/globstar
Expand All @@ -57,7 +57,7 @@ builds:
goarch:
- arm64
ldflags:
- "-X 'main.version={{ .Version }}'"
- "-X 'globstar.dev/pkg/cli.version={{ .Version }}'"
# windows-amd64
- id: globstar-windows-amd64
main: ./cmd/globstar
Expand All @@ -72,7 +72,7 @@ builds:
- amd64
ldflags:
- buildmode=exe
- "-X 'main.version={{ .Version }}'"
- "-X 'globstar.dev/pkg/cli.version={{ .Version }}'"
# windows-arm64
- id: globstar-windows-arm64
main: ./cmd/globstar
Expand All @@ -87,7 +87,7 @@ builds:
- arm64
ldflags:
- buildmode=exe
- "-X 'main.version={{ .Version }}'"
- "-X 'globstar.dev/pkg/cli.version={{ .Version }}'"
archives:
- id: arch_rename
builds:
Expand Down
12 changes: 12 additions & 0 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"slices"
"strings"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -49,7 +50,18 @@ func (c *Cli) Run() error {
return err
}

cli.VersionPrinter = func(cmd *cli.Command) {
version := strings.TrimPrefix(cmd.Version, "v")
fmt.Println(version)
}

cmd := &cli.Command{
Name: "globstar",
Usage: "The open-source static analysis toolkit",
Version: version,
Description: `Globstar helps you write and run custom checkers for bad and insecure patterns and run them on
your codebase with a simple command. It comes with built-in checkers that you can use out-of-the-box,\
or you can write your own in the .globstar directory of any repository.`,
Commands: []*cli.Command{
{
Name: "check",
Expand Down
5 changes: 5 additions & 0 deletions pkg/cli/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cli

// current version of globstar
// this will be overridden during the build process
var version = "dev"