diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73ba101..be04446 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,9 +30,13 @@ 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 }} + 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 +67,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/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..8e5612e 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" @@ -18,6 +19,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 +185,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" @@ -231,6 +242,14 @@ func main() { os.Exit(1) } + // Get minimum free space requirement from env var or use default + 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 + } + } + if *reportFormat != "json" { fmt.Printf("tile-diff - Ops Manager Product Tile Comparison\n") fmt.Printf("================================================\n\n") @@ -265,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 { 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) {