diff --git a/.github/workflows/go-check.yml b/.github/workflows/go-check.yml index 0ca0a28..17474dd 100644 --- a/.github/workflows/go-check.yml +++ b/.github/workflows/go-check.yml @@ -10,19 +10,63 @@ on: pull_request: jobs: + lint: + name: Lint + 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 Linters + run: make lint - build: + test: + name: Test (Unit + Integration) 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' + + # --- Setup Integration Test Dependencies --- + - name: Set up Helm + uses: azure/setup-helm@v3 + with: + version: 'v3.11.1' - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.20' + - name: Set up Kubectl + uses: azure/setup-kubectl@v3 + with: + version: 'v1.28.0' - - name: Build - run: go build -v ./... + - 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 - - name: Test - run: go test -v ./... + # --- Run Tests --- + - name: Run All Tests + run: make test + + 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 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 +}