-
Notifications
You must be signed in to change notification settings - Fork 2
HYPERFLEET-878 - feat: pre-commit hooks registry with commitlint with Go binary #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # Build artifacts | ||
| bin/ | ||
| *.exe | ||
| *.dll | ||
| *.so | ||
| *.dylib | ||
|
|
||
| # IDE and editor files | ||
| .idea/ | ||
| .vscode/ | ||
| *.swp | ||
| *.swo | ||
| *~ | ||
| .DS_Store | ||
|
|
||
| # Git | ||
| .git/ | ||
| .gitignore | ||
| .github/ | ||
|
|
||
| # Environment files | ||
| .env | ||
| .env.* | ||
|
|
||
| # Local config files | ||
| *.local.yaml | ||
|
|
||
| # CI/CD files (not needed in container) | ||
| .gitlab-ci.yml | ||
| .travis.yml | ||
| Jenkinsfile | ||
|
|
||
| # Kubernetes and deployment files | ||
| chart/ | ||
| charts/ | ||
| deployments/ | ||
|
|
||
| # License and owners | ||
| LICENSE | ||
| OWNERS | ||
| CONTRIBUTING.md | ||
|
|
||
| # Temporary files | ||
| tmp/ | ||
| temp/ | ||
| *.tmp | ||
|
|
||
| # Log files | ||
| *.log | ||
|
|
||
| # Test and coverage files | ||
| coverage/ | ||
| *.out | ||
| *.test | ||
| *.prof | ||
|
|
||
| # Linter config (not needed for build) | ||
| .golangci.yml | ||
|
|
||
| # AI assistant config | ||
| .claude/ | ||
|
|
||
| # Dockerfile itself | ||
| Dockerfile | ||
|
|
||
| # Documentation (not needed in container) | ||
| *.md | ||
| docs/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Binaries | ||
| bin/ | ||
| *.exe | ||
| *.dll | ||
| *.so | ||
| *.dylib | ||
|
|
||
| # Test artifacts | ||
| coverage.out | ||
| coverage.html | ||
| *.test | ||
|
|
||
| # Go workspace | ||
| go.work | ||
| go.work.sum | ||
|
|
||
| # IDE | ||
| .idea/ | ||
| .vscode/ | ||
| *.swp | ||
| *.swo | ||
| *~ | ||
|
|
||
| # OS | ||
| .DS_Store | ||
| Thumbs.db | ||
|
|
||
| # Node.js (if any legacy files exist) | ||
| node_modules/ | ||
| package-lock.json | ||
|
|
||
| # temporary | ||
| tmp/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| # HyperFleet pre-commit hooks registry | ||
| # https://pre-commit.com/ | ||
|
|
||
| - id: hyperfleet-commitlint | ||
| name: Validate commit message (HyperFleet Standard) | ||
| description: > | ||
| Validates commit messages against the HyperFleet Commit Standard | ||
| (Conventional Commits with optional JIRA prefix). | ||
| entry: hyperfleet-hooks commitlint | ||
| language: golang | ||
| stages: [commit-msg] | ||
| pass_filenames: true | ||
| always_run: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| ARG BASE_IMAGE=registry.access.redhat.com/ubi9-micro:latest | ||
|
|
||
| FROM registry.access.redhat.com/ubi9/go-toolset:1.25 AS builder | ||
|
|
||
| ARG GIT_SHA=unknown | ||
| ARG GIT_DIRTY="" | ||
| ARG BUILD_DATE="" | ||
| ARG APP_VERSION="0.0.0-dev" | ||
|
|
||
| USER root | ||
| RUN dnf install -y make && dnf clean all | ||
| WORKDIR /build | ||
| RUN chown 1001:0 /build | ||
| USER 1001 | ||
|
|
||
| COPY --chown=1001:0 go.mod go.sum ./ | ||
| RUN --mount=type=cache,target=/opt/app-root/src/go/pkg/mod,uid=1001 \ | ||
| go mod download | ||
|
|
||
| COPY --chown=1001:0 . . | ||
|
|
||
| # CGO_ENABLED=0 produces a static binary. The default ubi-minimal runtime | ||
| # supports both static and dynamically linked binaries. | ||
| # For FIPS-compliant builds, use CGO_ENABLED=1 + GOEXPERIMENT=boringcrypto. | ||
| RUN --mount=type=cache,target=/opt/app-root/src/go/pkg/mod,uid=1001 \ | ||
| --mount=type=cache,target=/opt/app-root/src/.cache/go-build,uid=1001 \ | ||
| CGO_ENABLED=0 GOOS=linux \ | ||
| GIT_SHA=${GIT_SHA} GIT_DIRTY=${GIT_DIRTY} BUILD_DATE=${BUILD_DATE} APP_VERSION=${APP_VERSION} \ | ||
| make build | ||
|
|
||
| # Runtime stage | ||
| FROM ${BASE_IMAGE} | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY --from=builder /build/bin/hyperfleet-hooks /app/hyperfleet-hooks | ||
|
|
||
| USER 65532:65532 | ||
|
|
||
| ENTRYPOINT ["/app/hyperfleet-hooks"] | ||
| CMD ["--help"] | ||
|
|
||
| ARG APP_VERSION="0.0.0-dev" | ||
| LABEL name="hyperfleet-hooks" \ | ||
| vendor="Red Hat" \ | ||
| version="${APP_VERSION}" \ | ||
| summary="HyperFleet Hooks - Commit Message Validator" \ | ||
| description="Validates commit messages against HyperFleet standards" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| # ============================================================================== | ||
| # Makefile for hyperfleet-hooks | ||
| # ============================================================================== | ||
|
|
||
| .PHONY: help build build-all test test-coverage lint clean install validate-commits | ||
|
|
||
| # ============================================================================== | ||
| # Configuration | ||
| # ============================================================================== | ||
|
|
||
| # Binary configuration | ||
| BINARY_NAME := hyperfleet-hooks | ||
| BIN_DIR := bin | ||
|
|
||
| # Version information (auto-detected from git) | ||
| APP_VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev") | ||
| GIT_SHA ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown") | ||
| GIT_DIRTY ?= $(shell [ -z "$$(git status --porcelain 2>/dev/null)" ] || echo "-modified") | ||
| BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ") | ||
|
|
||
| # Build flags | ||
| GOFLAGS ?= -trimpath | ||
| LDFLAGS := -ldflags "\ | ||
| -s -w \ | ||
| -X github.com/openshift-hyperfleet/hyperfleet-hooks/pkg/version.Version=$(APP_VERSION) \ | ||
| -X github.com/openshift-hyperfleet/hyperfleet-hooks/pkg/version.GitCommit=$(GIT_SHA)$(GIT_DIRTY) \ | ||
| -X github.com/openshift-hyperfleet/hyperfleet-hooks/pkg/version.BuildDate=$(BUILD_DATE)" | ||
|
|
||
| # ============================================================================== | ||
| # Targets | ||
| # ============================================================================== | ||
|
|
||
| .DEFAULT_GOAL := help | ||
|
|
||
| help: ## Show this help message | ||
| @echo 'Usage: make [target]' | ||
| @echo '' | ||
| @echo 'Available targets:' | ||
| @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-20s %s\n", $$1, $$2}' $(MAKEFILE_LIST) | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| # Build | ||
| # ------------------------------------------------------------------------------ | ||
|
|
||
| build: ## Build the binary | ||
| @echo "Building $(BINARY_NAME) $(APP_VERSION)..." | ||
| @mkdir -p $(BIN_DIR) | ||
| go build $(GOFLAGS) $(LDFLAGS) -o $(BIN_DIR)/$(BINARY_NAME) ./cmd/hyperfleet-hooks | ||
| @echo "✓ Built $(BIN_DIR)/$(BINARY_NAME)" | ||
|
|
||
| build-all: ## Build binaries for all platforms | ||
| @echo "Building for all platforms..." | ||
| @mkdir -p $(BIN_DIR) | ||
| GOOS=linux GOARCH=amd64 go build $(GOFLAGS) $(LDFLAGS) -o $(BIN_DIR)/$(BINARY_NAME)-linux-amd64 ./cmd/hyperfleet-hooks | ||
| GOOS=linux GOARCH=arm64 go build $(GOFLAGS) $(LDFLAGS) -o $(BIN_DIR)/$(BINARY_NAME)-linux-arm64 ./cmd/hyperfleet-hooks | ||
| GOOS=darwin GOARCH=amd64 go build $(GOFLAGS) $(LDFLAGS) -o $(BIN_DIR)/$(BINARY_NAME)-darwin-amd64 ./cmd/hyperfleet-hooks | ||
| GOOS=darwin GOARCH=arm64 go build $(GOFLAGS) $(LDFLAGS) -o $(BIN_DIR)/$(BINARY_NAME)-darwin-arm64 ./cmd/hyperfleet-hooks | ||
| @echo "✓ Built all platform binaries" | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| # Test | ||
| # ------------------------------------------------------------------------------ | ||
|
|
||
| test: ## Run tests | ||
| @echo "Running tests..." | ||
| go test -v -race -coverprofile=coverage.out ./... | ||
| @echo "✓ Tests passed" | ||
|
|
||
| test-coverage: test ## Run tests with coverage report | ||
| @echo "Generating coverage report..." | ||
| go tool cover -html=coverage.out -o coverage.html | ||
| @echo "✓ Coverage report generated: coverage.html" | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| # Quality | ||
| # ------------------------------------------------------------------------------ | ||
|
|
||
| lint: ## Run linters | ||
| @echo "Running linters..." | ||
| @if command -v golangci-lint >/dev/null 2>&1; then \ | ||
| golangci-lint run --timeout=5m; \ | ||
| else \ | ||
| echo "⚠ golangci-lint not installed, running go fmt only"; \ | ||
| test -z "$$(gofmt -l .)" || (echo "Files need formatting:" && gofmt -l . && exit 1); \ | ||
| fi | ||
| @echo "✓ Linting passed" | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| # Utility | ||
| # ------------------------------------------------------------------------------ | ||
|
|
||
| clean: ## Clean build artifacts | ||
| @echo "Cleaning..." | ||
| rm -rf $(BIN_DIR) | ||
| rm -f coverage.out coverage.html | ||
| @echo "✓ Cleaned" | ||
|
|
||
| install: build ## Install binary to /usr/local/bin | ||
| @echo "Installing $(BINARY_NAME) to /usr/local/bin..." | ||
| @cp $(BIN_DIR)/$(BINARY_NAME) /usr/local/bin/$(BINARY_NAME) | ||
| @echo "✓ Installed $(BINARY_NAME)" | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| # CI | ||
| # ------------------------------------------------------------------------------ | ||
|
|
||
| validate-commits: build ## Validate commits in current branch (CI mode) | ||
| @echo "Validating commits..." | ||
| @./bin/hyperfleet-hooks commitlint --pr | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,44 @@ | ||
| # hyperfleet-hooks | ||
| Pre-commit hooks registry for HyperFleet project ecosystem | ||
| # HyperFleet Hooks | ||
|
|
||
| Validation tools for HyperFleet projects. | ||
|
|
||
| ## Features | ||
|
|
||
| ### Commitlint | ||
|
|
||
| Validates commit messages and PR titles against the [HyperFleet Commit Standard](https://github.com/openshift-hyperfleet/architecture/blob/main/hyperfleet/standards/commit-standard.md). | ||
|
|
||
| **[→ Documentation](docs/commitlint.md)** | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| # Install pre-commit framework | ||
| pip install pre-commit | ||
|
|
||
| # Add to your .pre-commit-config.yaml | ||
| repos: | ||
| - repo: https://github.com/openshift-hyperfleet/hyperfleet-hooks | ||
| rev: main | ||
| hooks: | ||
| - id: hyperfleet-commitlint | ||
|
|
||
| # Install hooks (pre-commit will automatically build the binary) | ||
| pre-commit install --hook-type commit-msg | ||
| ``` | ||
|
|
||
| **Note**: Pre-commit automatically builds the binary. No manual installation needed. | ||
|
|
||
| See [commitlint documentation](docs/commitlint.md) for Prow CI setup and detailed usage. | ||
|
|
||
| ## Development | ||
|
|
||
| ```bash | ||
| make build # Build binary | ||
| make test # Run tests | ||
| make lint # Run linters | ||
| ``` | ||
|
|
||
| ## License | ||
|
|
||
| Apache 2.0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.