From 11e9aba08d793a01c8c79529d5db6ee56e3bf22b Mon Sep 17 00:00:00 2001 From: Alokzh Date: Wed, 5 Nov 2025 15:34:48 +0530 Subject: [PATCH 1/3] Refactored GitHub Actions workflow & Makefile for improved testing Signed-off-by: Alokzh --- .github/workflows/go-check.yml | 50 +++++++++++++++++++++------- Makefile | 60 +++++++++++++++++++++++++++++----- 2 files changed, 90 insertions(+), 20 deletions(-) diff --git a/.github/workflows/go-check.yml b/.github/workflows/go-check.yml index 0ca0a28..1312df9 100644 --- a/.github/workflows/go-check.yml +++ b/.github/workflows/go-check.yml @@ -10,19 +10,45 @@ on: pull_request: jobs: - - build: + lint: + name: Lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.17' + + - name: Run Linters + run: make lint - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.20' - - - name: Build - run: go build -v ./... + test: + name: Test (Unit + Integration) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.17' + + - name: Run All Tests + run: make test - - name: Test - run: go test -v ./... + build: + name: Build + runs-on: ubuntu-latest + needs: [lint, test] + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.17' + + - name: Build + run: go build -v ./... diff --git a/Makefile b/Makefile index b76fd5f..51d49f7 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,52 @@ -.PHONEY: build -build: - GOOS=windows GOARCH=amd64 go build -o bin/kubeslice-cli-windows-amd64.exe main.go - GOOS=linux GOARCH=amd64 go build -o bin/kubeslice-cli-linux-amd64 main.go - GOOS=linux GOARCH=arm go build -o bin/kubeslice-cli-linux-arm main.go - GOOS=linux GOARCH=arm64 go build -o bin/kubeslice-cli-linux-arm64 main.go - GOOS=darwin GOARCH=amd64 go build -o bin/kubeslice-cli-darwin-amd64 main.go - GOOS=darwin GOARCH=arm64 go build -o bin/kubeslice-cli-darwin-arm64 main.go \ No newline at end of file +GO_VERSION := 1.17 + +.PHONY: all build clean test test-unit test-integration lint tidy + +all: build + +# test-unit: Runs all unit tests. +# Uses -short to skip long-running tests. +test-unit: + @echo "Running unit tests..." + @go test -v -race -short -cover ./... + +# test-integration: Runs only integration tests. +# Requires the 'integration' build tag. +test-integration: + @echo "Running integration tests..." + @go test -v -race -cover -tags=integration -run Integration ./... + +# test: Runs All tests +test: + @echo "Running all tests..." + @make test-unit + @make test-integration + +build: tidy + @echo "Building binaries for all platforms..." + @GOOS=windows GOARCH=amd64 go build -o bin/kubeslice-cli-windows-amd64.exe main.go + @GOOS=linux GOARCH=amd64 go build -o bin/kubeslice-cli-linux-amd64 main.go + @GOOS=linux GOARCH=arm go build -o bin/kubeslice-cli-linux-arm main.go + @GOOS=linux GOARCH=arm64 go build -o bin/kubeslice-cli-linux-arm64 main.go + @GOOS=darwin GOARCH=amd64 go build -o bin/kubeslice-cli-darwin-amd64 main.go + @GOOS=darwin GOARCH=arm64 go build -o bin/kubeslice-cli-darwin-arm64 main.go + @echo "Build complete." + +lint: + @echo "Running linter..." + @if [ "$$(gofmt -l . | wc -l)" -gt 0 ]; then \ + echo "Go files are not formatted. Please run 'gofmt -w .'"; \ + gofmt -l .; \ + exit 1; \ + fi + @go vet ./... + @echo "Linting passed!" + +tidy: + @echo "Running go mod tidy..." + @go mod tidy + +clean: + @echo "Cleaning up..." + @rm -f bin/kubeslice-cli-* + @rm -rf bin From dc3b99c1ed08c8eb9394ef692ed4d3806f90f8ad Mon Sep 17 00:00:00 2001 From: Alokzh Date: Wed, 5 Nov 2025 15:42:38 +0530 Subject: [PATCH 2/3] Fix: Added newline at end of file in util/file-generation.go Signed-off-by: Alokzh --- util/file-generation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/file-generation.go b/util/file-generation.go index fa7270d..d0bafac 100644 --- a/util/file-generation.go +++ b/util/file-generation.go @@ -25,4 +25,4 @@ func DumpFile(template, filename string) { if err2 != nil { Fatalf("%s Failed to write %s", Cross, filename) } -} \ No newline at end of file +} From ac8f673f07a6641157c9b59c699a79e79233515b Mon Sep 17 00:00:00 2001 From: Alokzh Date: Wed, 19 Nov 2025 14:53:43 +0530 Subject: [PATCH 3/3] Update workflow by adding setup for Helm, Kubectl & Kind for integration testing Signed-off-by: Alokzh --- .github/workflows/go-check.yml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/go-check.yml b/.github/workflows/go-check.yml index 1312df9..17474dd 100644 --- a/.github/workflows/go-check.yml +++ b/.github/workflows/go-check.yml @@ -34,7 +34,25 @@ jobs: uses: actions/setup-go@v5 with: go-version: '1.17' - + + # --- Setup Integration Test Dependencies --- + - name: Set up Helm + uses: azure/setup-helm@v3 + with: + version: 'v3.11.1' + + - name: Set up Kubectl + uses: azure/setup-kubectl@v3 + with: + version: 'v1.28.0' + + - name: Install Kind + run: | + curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64 + chmod +x ./kind + sudo mv ./kind /usr/local/bin/kind + + # --- Run Tests --- - name: Run All Tests run: make test