Skip to content
Closed
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
68 changes: 68 additions & 0 deletions .dockerignore
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/
33 changes: 33 additions & 0 deletions .gitignore
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/
14 changes: 14 additions & 0 deletions .pre-commit-hooks.yaml
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
48 changes: 48 additions & 0 deletions Dockerfile
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"
109 changes: 109 additions & 0 deletions Makefile
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
46 changes: 44 additions & 2 deletions README.md
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
Loading