Skip to content
Open
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
29 changes: 29 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,32 @@
stages: [commit-msg]
pass_filenames: true
always_run: true

- id: hyperfleet-golangci-lint
name: Run golangci-lint (bingo-aware)
description: >
Runs golangci-lint via Make target, which leverages the bingo-managed
version from .bingo/ when available.
entry: make lint
language: system
types: [go]
pass_filenames: false

- id: hyperfleet-gofmt
name: Check Go formatting
description: >
Checks Go file formatting via Make target, which leverages the
bingo-managed version from .bingo/ when available.
entry: make gofmt
language: system
types: [go]
pass_filenames: false

- id: hyperfleet-go-vet
name: Run go vet
description: >
Runs go vet via Make target to find suspicious constructs in Go code.
entry: make go-vet
language: system
types: [go]
pass_filenames: false
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ ARG APP_VERSION="0.0.0-dev"
LABEL name="hyperfleet-hooks" \
vendor="Red Hat" \
version="${APP_VERSION}" \
summary="HyperFleet Hooks - Commit Message Validator" \
summary="HyperFleet Hooks - Pre-commit Validators" \
description="Validates commit messages against HyperFleet standards"
49 changes: 48 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,61 @@ From this point on, every `git commit` in that repository will validate the comm

In Prow, a pre-built container image (`quay.io/openshift-hyperfleet/hooks`) is used to validate all commits and the PR title. See the [commitlint documentation](docs/commitlint.md) for Prow configuration details.

## Features
## Available Hooks

| Hook ID | Stage | Description |
| --- | --- | --- |
| `hyperfleet-commitlint` | `commit-msg` | Validates commit messages against the [HyperFleet Commit Standard](https://github.com/openshift-hyperfleet/architecture/blob/main/hyperfleet/standards/commit-standard.md) |
| `hyperfleet-golangci-lint` | `pre-commit` | Runs `make lint` — leverages the repo's existing bingo-managed golangci-lint |
| `hyperfleet-gofmt` | `pre-commit` | Runs `make gofmt` — checks Go file formatting |
| `hyperfleet-go-vet` | `pre-commit` | Runs `make go-vet` — finds suspicious constructs in Go code |

### 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).

**[→ Full Documentation](docs/commitlint.md)**

### Go Tooling Hooks

The Go tooling hooks use `language: system` and delegate to the consuming repo's existing Make targets (`make lint`, `make gofmt`, `make go-vet`). This leverages the repo's existing [bingo](https://github.com/bwplotka/bingo)-managed tool resolution without reimplementing it. See the [dependency pinning standard](https://github.com/openshift-hyperfleet/architecture/blob/main/hyperfleet/standards/dependency-pinning.md) for details.

**[→ Documentation](docs/go-tooling.md)**

## Installation

### Prerequisites

- [pre-commit](https://pre-commit.com/#install) installed
- Go 1.25+ available (for the `commitlint` hook — built automatically by pre-commit)
- `make` targets (`lint`, `gofmt`, `go-vet`) in the consuming repo (for Go tooling hooks)

### Adding to your repository

Add this to your `.pre-commit-config.yaml`:

```yaml
repos:
- repo: https://github.com/openshift-hyperfleet/hyperfleet-hooks
rev: main # Use latest release tag
hooks:
- id: hyperfleet-commitlint
- id: hyperfleet-golangci-lint
- id: hyperfleet-gofmt
- id: hyperfleet-go-vet
```

Then install the hooks:

```bash
pre-commit install --hook-type commit-msg
pre-commit install --hook-type pre-commit
```

**Note**: The `commitlint` hook is built automatically by pre-commit (`language: golang`). The Go tooling hooks (`golangci-lint`, `gofmt`, `go-vet`) use `language: system` and require the consuming repo to have the corresponding Make targets.

See [commitlint documentation](docs/commitlint.md) for Prow CI setup and [go-tooling documentation](docs/go-tooling.md) for bingo configuration.

## Development

These instructions are only needed if you are contributing to this repository.
Expand Down
119 changes: 119 additions & 0 deletions docs/go-tooling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Go Tooling Hooks Documentation

System-level Go tooling hooks that delegate to existing Make targets in HyperFleet repositories.

## Table of Contents

- [Overview](#overview)
- [Hooks](#hooks)
- [Configuration](#configuration)
- [Prerequisites](#prerequisites)
- [Troubleshooting](#troubleshooting)

## Overview

HyperFleet Go repositories use [bingo](https://github.com/bwplotka/bingo) to pin development tool versions (see [dependency pinning standard](https://github.com/openshift-hyperfleet/architecture/blob/main/hyperfleet/standards/dependency-pinning.md)). Rather than reimplementing bingo resolution, these hooks use `language: system` and delegate to the consuming repo's existing Make targets, which already handle tool resolution via bingo.

## Hooks

### hyperfleet-golangci-lint

Runs `make lint` in the consuming repository.

- **Stage**: `pre-commit`
- **Entry**: `make lint`
- **Language**: `system`
- **File filtering**: Triggered by Go file changes (does not pass individual filenames)

### hyperfleet-gofmt

Runs `make gofmt` in the consuming repository.

- **Stage**: `pre-commit`
- **Entry**: `make gofmt`
- **Language**: `system`
- **File filtering**: Triggered by Go file changes (does not pass individual filenames)

### hyperfleet-go-vet

Runs `make go-vet` in the consuming repository.

- **Stage**: `pre-commit`
- **Entry**: `make go-vet`
- **Language**: `system`
- **File filtering**: Triggered by Go file changes (does not pass individual filenames)

## Configuration

### Basic Setup

Add to your `.pre-commit-config.yaml`:

```yaml
repos:
- repo: https://github.com/openshift-hyperfleet/hyperfleet-hooks
rev: main # Use latest release tag
hooks:
- id: hyperfleet-golangci-lint
- id: hyperfleet-gofmt
- id: hyperfleet-go-vet
```

Install the hooks:

```bash
pre-commit install --hook-type pre-commit
```

### Selective Hooks

You don't need to enable all hooks. Pick the ones you need:

```yaml
hooks:
# Just formatting and linting
- id: hyperfleet-gofmt
- id: hyperfleet-golangci-lint
```

## Prerequisites

Since these hooks use `language: system`, the consuming repository **must** have the corresponding Make targets:

- `make lint` — runs golangci-lint (typically via bingo)
- `make gofmt` — checks Go file formatting
- `make go-vet` — runs `go vet ./...`

These targets are already standard in HyperFleet repositories. Ensure bingo-managed tools are built:

```bash
make tools-install
```

## Troubleshooting

### make: *** No rule to make target 'lint'

The consuming repository is missing the required Make target. Ensure your Makefile includes the `lint`, `gofmt`, and `go-vet` targets.

### golangci-lint binary not found

If `make lint` fails because golangci-lint is not installed, build the bingo-managed tools:

```bash
make tools-install
# or
bingo get
```

### Different results from direct make lint

These hooks run the exact same Make targets, so results should be identical. If they differ, check:

1. The bingo binary exists: `ls .bingo/golangci-lint-*`
2. The `.golangci.yml` config is present in your repo root
3. Pre-commit environment is not interfering (check `pre-commit run --verbose`)

### go vet fails but code compiles

`go vet` catches issues that compile successfully but are likely bugs (e.g., unreachable code, incorrect format strings). Fix the reported issues rather than skipping the hook.