From 9547208b17b0b224c196c5910f61e6a61aedfed4 Mon Sep 17 00:00:00 2001 From: Mark Alston Date: Mon, 15 Dec 2025 14:28:59 -0700 Subject: [PATCH 1/4] feat: add --version flag to display binary version Add --version flag that displays the current version of tile-diff. The version is injected at build time via ldflags from git tags. Changes: - Add version variable with default value "dev" - Add --version boolean flag to main.go - Update Makefile to inject version using git describe - Add acceptance test for version flag functionality During development builds, the version shows git describe output (e.g., v0.3.0-phase3-98-gea79a59-dirty). During releases, the version shows the clean tag (e.g., v1.0.0). The release workflow already uses ldflags for version injection, so no changes were needed there. --- Makefile | 5 ++++- cmd/tile-diff/main.go | 10 ++++++++++ test/acceptance_test.go | 23 +++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1d73b13..6ca037f 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,11 @@ .PHONY: build test acceptance-test acceptance-test-with-token acceptance-test-fast acceptance-test-fast-with-token clean install lint fmt vet +# Get version from git tags, or use "dev" if not on a tag +VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev") + # Build the binary build: - go build -o tile-diff ./cmd/tile-diff + go build -ldflags "-X main.version=$(VERSION)" -o tile-diff ./cmd/tile-diff # Run unit tests test: diff --git a/cmd/tile-diff/main.go b/cmd/tile-diff/main.go index 727bdd9..2110244 100644 --- a/cmd/tile-diff/main.go +++ b/cmd/tile-diff/main.go @@ -18,6 +18,9 @@ import ( "github.com/malston/tile-diff/pkg/report" ) +// version is set via ldflags during build +var version = "dev" + // EnrichmentResult contains the results of release notes enrichment type EnrichmentResult struct { Matches map[string]releasenotes.Match @@ -181,9 +184,16 @@ func main() { productConfig := flag.String("product-config", "configs/products.yaml", "Path to product config file") verbose := flag.Bool("verbose", false, "Enable verbose output") debugMatching := flag.Bool("debug-matching", false, "Show detailed property-to-feature matching information") + showVersion := flag.Bool("version", false, "Show version information") flag.Parse() + // Handle version flag + if *showVersion { + fmt.Printf("tile-diff version %s\n", version) + os.Exit(0) + } + // Track if we're in JSON mode to suppress non-JSON output jsonMode := *reportFormat == "json" diff --git a/test/acceptance_test.go b/test/acceptance_test.go index 160cf83..b48bfda 100644 --- a/test/acceptance_test.go +++ b/test/acceptance_test.go @@ -12,6 +12,29 @@ import ( . "github.com/onsi/gomega" ) +var _ = Describe("Basic Flags", func() { + BeforeEach(func() { + if _, err := os.Stat(tileDiffBin); os.IsNotExist(err) { + Fail(fmt.Sprintf("tile-diff binary not found at %s - run 'make build' first", tileDiffBin)) + } + }) + + Describe("Version Flag", func() { + It("prints version information when --version is provided", func() { + output, err := runTileDiff("--version") + + // Should succeed + Expect(err).NotTo(HaveOccurred(), "Should exit successfully") + + // Should contain version information + Expect(output).To(ContainSubstring("version"), "Should contain 'version' in output") + + // Should not contain error messages + Expect(output).NotTo(ContainSubstring("Error"), "Should not contain error messages") + }) + }) +}) + var _ = Describe("Pivnet Integration", func() { BeforeEach(func() { if _, err := os.Stat(tileDiffBin); os.IsNotExist(err) { From 0d0d3be70c767b9f4333c388a1814bca6d703f3e Mon Sep 17 00:00:00 2001 From: Mark Alston Date: Mon, 15 Dec 2025 14:43:41 -0700 Subject: [PATCH 2/4] feat: make disk space requirement configurable via environment variable Add PIVNET_MIN_FREE_SPACE_GB environment variable to allow overriding the minimum free disk space requirement for tile downloads. Changes: - Add PIVNET_MIN_FREE_SPACE_GB env var parsing in main.go - Default to 5GB (reduced from hardcoded 20GB) - Set to 2GB in CI workflow to prevent disk space failures - Update CI workflow to test --version flag now that it exists This fixes the "fails with meaningful error for invalid Pivnet token" acceptance test failure in CI, which was failing on disk space check before it could reach the authentication step. The lower default (5GB) is more reasonable for most use cases, and the environment variable allows users to adjust based on their needs. --- .github/workflows/ci.yml | 3 ++- cmd/tile-diff/main.go | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73ba101..9719629 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,7 @@ jobs: - name: Run acceptance tests (Ginkgo) env: PIVNET_TOKEN: ${{ secrets.PIVNET_TOKEN }} + PIVNET_MIN_FREE_SPACE_GB: "2" # Lower requirement for CI tests (default: 5GB) # ENABLE_DOWNLOAD_TESTS: "1" # Uncomment to run all 12 tests (slower, downloads tiles) run: | go build -v ./cmd/tile-diff @@ -63,7 +64,7 @@ jobs: - name: Build binary run: | go build -v -o bin/tile-diff ./cmd/tile-diff - ./bin/tile-diff --version || echo "Version command not implemented yet" + ./bin/tile-diff --version - name: Test binary runs run: | diff --git a/cmd/tile-diff/main.go b/cmd/tile-diff/main.go index 2110244..929b711 100644 --- a/cmd/tile-diff/main.go +++ b/cmd/tile-diff/main.go @@ -7,6 +7,7 @@ import ( "fmt" "os" "path/filepath" + "strconv" "strings" "github.com/malston/tile-diff/pkg/api" @@ -241,6 +242,14 @@ func main() { os.Exit(1) } + // Get minimum free space requirement from env var or use default + minFreeSpaceGB := int64(5) // Default: 5GB + if envSpace := os.Getenv("PIVNET_MIN_FREE_SPACE_GB"); envSpace != "" { + if parsed, err := strconv.ParseInt(envSpace, 10, 64); err == nil && parsed > 0 { + minFreeSpaceGB = parsed + } + } + if *reportFormat != "json" { fmt.Printf("tile-diff - Ops Manager Product Tile Comparison\n") fmt.Printf("================================================\n\n") @@ -275,7 +284,7 @@ func main() { } // Create downloader (quiet mode in JSON to suppress progress output) - downloader := pivnet.NewDownloader(client, cacheDirectory, manifestFile, eulaFile, 20, jsonMode) + downloader := pivnet.NewDownloader(client, cacheDirectory, manifestFile, eulaFile, minFreeSpaceGB, jsonMode) // Download old tile if !jsonMode { From f32da1b50981f1407680292e43a8c9105368dbbf Mon Sep 17 00:00:00 2001 From: Mark Alston Date: Mon, 15 Dec 2025 14:46:03 -0700 Subject: [PATCH 3/4] ci: add disk space diagnostic step --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9719629..be04446 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,9 @@ jobs: - name: Run unit tests run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./pkg/... + - name: Check available disk space + run: df -h / + - name: Run acceptance tests (Ginkgo) env: PIVNET_TOKEN: ${{ secrets.PIVNET_TOKEN }} From 63934435c24359e22157fc4e71c0771af7be0f17 Mon Sep 17 00:00:00 2001 From: Mark Alston Date: Mon, 15 Dec 2025 14:49:49 -0700 Subject: [PATCH 4/4] chore: adjust default min free space to 10GB Most tiles are < 5GB but some exceed 10GB. The 10GB default provides a good buffer for most cases while users can override via PIVNET_MIN_FREE_SPACE_GB for larger tiles. --- cmd/tile-diff/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/tile-diff/main.go b/cmd/tile-diff/main.go index 929b711..8e5612e 100644 --- a/cmd/tile-diff/main.go +++ b/cmd/tile-diff/main.go @@ -243,7 +243,7 @@ func main() { } // Get minimum free space requirement from env var or use default - minFreeSpaceGB := int64(5) // Default: 5GB + minFreeSpaceGB := int64(10) // Default: 10GB (most tiles < 5GB, some > 10GB) if envSpace := os.Getenv("PIVNET_MIN_FREE_SPACE_GB"); envSpace != "" { if parsed, err := strconv.ParseInt(envSpace, 10, 64); err == nil && parsed > 0 { minFreeSpaceGB = parsed