Skip to content
Merged

V2 #8

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
20 changes: 8 additions & 12 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,26 @@ jobs:
runs-on: ubuntu-latest
name: Update coverage badge
steps:
- uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup go
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version: '^1.18'
- uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
go-version: stable
cache: true

- name: Run Test
run: |
go test -v ./... -covermode=count -coverprofile=coverage.out
go tool cover -func=coverage.out -o=coverage.out

- name: Go Coverage Badge # Pass the `coverage.out` output to this action
- name: Go Coverage Badge
uses: tj-actions/coverage-badge-go@v3
with:
filename: coverage.out

- name: Verify Changed files
uses: tj-actions/verify-changed-files@v18
uses: tj-actions/verify-changed-files@v20
id: verify-changed-files
with:
files: README.md
Expand All @@ -47,7 +43,7 @@ jobs:

- name: Push changes
if: steps.verify-changed-files.outputs.files_changed == 'true'
uses: ad-m/github-push-action@v0.8.0
uses: ad-m/github-push-action@v1
with:
github_token: ${{ github.token }}
branch: ${{ github.head_ref }}
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Tagged Release
runs-on: ubuntu-latest
steps:
- uses: "marvinpinto/action-automatic-releases@latest"
- uses: actions/checkout@v6
- uses: softprops/action-gh-release@v3
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
generate_release_notes: true
22 changes: 12 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,31 @@ on:

jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup go
uses: actions/setup-go@v6
with:
go-version: '^1.24'
- name: golangci-lint
go-version: stable
- name: Setup golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: latest
args: --verbose
test:
needs: lint
strategy:
matrix:
go: ["1.18", "1.19", "1.20", "1.21", "1.22", "1.23", "1.24", "1.25", "1.26"]
go: ["1.21", "1.22", "1.23", "1.24", "1.25", "1.26"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Checkout Code
uses: actions/checkout@v6
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version: ${{ matrix.go }}
- name: Run Tests
run: |
go test -v ./...
run: go test -v ./...
79 changes: 46 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,46 @@
# Makefile for go-validator

SHELL := /bin/bash
GO ?= go
PKG ?= ./...
TEST_FLAGS ?= -race -count=1
COVER_PROFILE ?= coverage.out
BIN ?= go-validator
GOLANGCI_LINT ?= golangci-lint
LINT_VERSION ?= v1.61.0

.PHONY: help lint tidy test coverage bench clean

help: ## Show this help
@awk 'BEGIN {FS = ":.*##"}; /^[a-zA-Z0-9_.-]+:.*##/ {printf "\033[36m%-18s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

test: ## Run unit tests
$(GO) test $(TEST_FLAGS) $(PKG)

coverage: ## Run tests with coverage and generate reports
$(GO) test -race -covermode=atomic -coverprofile $(COVER_PROFILE) $(PKG)
$(GO) tool cover -func=$(COVER_PROFILE) | tail -n 1
@echo "HTML report: $(COVER_PROFILE).html"
$(GO) tool cover -html=$(COVER_PROFILE) -o $(COVER_PROFILE).html

bench: ## Run benchmarks
$(GO) test -bench=. -benchmem $(PKG)

lint: ## Run golangci-lint
$(GOLANGCI_LINT) run ./...

clean: ## Clean generated artifacts
rm -f $(COVER_PROFILE) $(COVER_PROFILE).html
# Colors for output
GREEN := \033[32m
YELLOW := \033[33m
CYAN := \033[36m
RESET := \033[0m

.DEFAULT_GOAL := help

.PHONY: help
help: ## Show this help message
@echo "$(GREEN)Go Validator Makefile$(RESET)"
@echo "Usage: make $(CYAN)<target>$(RESET)"
@awk 'BEGIN {FS = ":.*##";} \
/^[a-zA-Z0-9_-]+:.*?##/ { printf " $(CYAN)%-15s$(RESET) %s\n", $$1, $$2 } \
/^##@/ { printf "\n$(YELLOW)%s$(RESET)\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

.PHONY: test test-coverage clean fmt lint tidy

test: ## Run tests
@echo "$(GREEN)Running tests (with race)...$(RESET)"
@go test -v -race ./...

test-coverage: ## Run tests with coverage
@echo "$(GREEN)Running tests with coverage...$(RESET)"
@go test -coverprofile=coverage.out ./...
@echo "$(GREEN)Coverage file created: coverage.out$(RESET)"

clean: ## Clean coverage files
@echo "$(YELLOW)Cleaning coverage files...$(RESET)"
@rm -f coverage.out
@echo "$(GREEN)Clean complete$(RESET)"

fmt: ## Format code using golangci-lint formatter
@echo "$(GREEN)Formatting code with golangci-lint...$(RESET)"
@golangci-lint fmt
@echo "$(GREEN)Code formatting complete$(RESET)"

lint: ## Lint code using golangci-lint linter
@echo "$(GREEN)Linting code with golangci-lint...$(RESET)"
@golangci-lint run
@echo "$(GREEN)Linting complete$(RESET)"

tidy: ## Run go mod tidy
@echo "$(GREEN)Running go mod tidy...$(RESET)"
@go mod tidy
@echo "$(GREEN)Go modules tidied$(RESET)"
Loading
Loading