Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ build/
# Test binary, built with `go test -c`
*.test

tests/end-to-end/results
tests/developement-versions

# Output of the go coverage tool
*.out
*.prof
coverage/
!coverage/badge.svg

# Go workspace
go.work
Expand Down
31 changes: 31 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
repos:
- repo: local
hooks:
- id: go-fmt
name: go fmt
entry: bash -c 'gofmt -w -s . && git add -A'
language: system
files: \.go$
pass_filenames: false

- id: go-vet
name: go vet
entry: go vet ./...
language: system
files: \.go$
pass_filenames: false

- id: go-test
name: go test
entry: bash -c 'cd tests && go test -v -timeout 30s'
language: system
files: \.go$
pass_filenames: false

- id: go-coverage
name: update coverage badge
entry: make coverage
language: system
files: \.go$
pass_filenames: false
stages: [commit]
33 changes: 31 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Thank you for your interest in contributing to Pilot Protocol. This document cov
### Setup

```bash
git clone https://github.com/user/web4.git
cd web4
git clone git clone git@github.com:TeoSlayer/pilotprotocol.git
cd pilotprotocol
go build ./...
```

Expand Down Expand Up @@ -125,3 +125,32 @@ docs/ # Documentation
## License

By contributing to Pilot Protocol, you agree that your contributions will be licensed under the [GNU Affero General Public License v3.0](LICENSE).


---

## Development

### Running tests

```bash
make test # Run all tests
make coverage # Run tests with coverage and update badge
make coverage-html # Generate HTML coverage report
```

### Pre-commit hooks

Set up automatic code quality checks before each commit:

```bash
./scripts/setup-hooks.sh
```

This installs a git hook that automatically runs:
- `go fmt` - Code formatting
- `go vet` - Static analysis
- `go test` - All tests
- Coverage badge update

To skip the hook temporarily: `git commit --no-verify`
16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.PHONY: all build test clean vet ci release
.PHONY: all build test clean vet ci release coverage coverage-html

BINDIR := bin
COVERDIR := coverage
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
LDFLAGS := -s -w -X main.version=$(VERSION)
PLATFORMS := linux/amd64 linux/arm64 darwin/amd64 darwin/arm64
Expand Down Expand Up @@ -29,8 +30,19 @@ build:
test:
go test -parallel 4 -count=1 ./tests/...

coverage:
@mkdir -p $(COVERDIR)
@cd tests && go test -parallel 4 -count=1 -coverprofile=../$(COVERDIR)/coverage.out -covermode=atomic -timeout 30s
@go tool cover -func=$(COVERDIR)/coverage.out | tail -1 | awk '{print "Total coverage: " $$3}'
@go tool cover -func=$(COVERDIR)/coverage.out -o=$(COVERDIR)/coverage.txt
@./scripts/generate-coverage-badge.sh

coverage-html: coverage
@go tool cover -html=$(COVERDIR)/coverage.out -o=$(COVERDIR)/coverage.html
@echo "Coverage report generated: $(COVERDIR)/coverage.html"

clean:
rm -rf $(BINDIR)
rm -rf $(BINDIR) $(COVERDIR)

# Build for Linux (GCP deployment)
build-linux:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
<img src="https://img.shields.io/badge/lang-Go-00ADD8?logo=go&logoColor=white" alt="Go">
<img src="https://img.shields.io/badge/deps-zero-brightgreen" alt="Zero Dependencies">
<img src="https://img.shields.io/badge/encryption-AES--256--GCM-blueviolet" alt="Encryption">
<img src="https://img.shields.io/badge/tests-223%20pass-success" alt="Tests">
<img src="https://img.shields.io/badge/tests-202%20pass-success" alt="Tests">
<img src="coverage/badge.svg" alt="Coverage">
<img src="https://img.shields.io/badge/license-AGPL--3.0-blue" alt="License">
<img src="https://polo.pilotprotocol.network/api/badge/nodes" alt="Online Nodes">
<img src="https://polo.pilotprotocol.network/api/badge/trust" alt="Trust Links">
Expand Down
Loading
Loading