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
13 changes: 11 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
# =============================================================================
#
# INSTALL
# pip install pre-commit
# pre-commit install
# For detailed setup instructions including uv (recommended) and pip,
# see: boilerplate/openshift/golang-osd-operator/docs/pre-commit.md
#
# Quick start (uv):
# uv sync && source .venv/bin/activate && pre-commit install
#
# Quick start (pip):
# pip install 'pre-commit==4.6.0' && pre-commit install
#
# USAGE
# pre-commit run # staged files only (developer / agent workflow)
Expand Down Expand Up @@ -35,6 +41,9 @@
# pre-existing violations on the first run. Stage and commit those fixes
# separately before day-to-day use.
#
# Fix commits can be excluded from git blame
# https://git-scm.com/docs/git-blame#Documentation/git-blame.txt---ignore-revs-filefile
#
# =============================================================================

repos:
Expand Down
2 changes: 1 addition & 1 deletion boilerplate/_data/last-boilerplate-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5c9b1484a283341e2d9aca8300bf97cfc665ca69
1cb129aed5a91f2098f70c0e141561e00b1e16fc
123 changes: 123 additions & 0 deletions boilerplate/openshift/golang-osd-operator/docs/pre-commit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Pre-Commit Hooks Setup Guide

## Installation

### Recommended: Using uv

[uv](https://github.com/astral-sh/uv) is recommended for Python dependency management. It provides dependency locking with package hashes (supply-chain protection), virtual environment management, and is 10-100x faster than pip.

**Install uv:**
```bash
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

# Via pip
pip install uv
```

**First-time setup:**
```bash
uv init --bare # creates pyproject.toml
uv add --dev pre-commit==4.6.0 # adds dependency, generates uv.lock
source .venv/bin/activate # macOS/Linux (.venv\Scripts\activate on Windows)
pre-commit install
```

**Subsequent setup** (when `pyproject.toml` and `uv.lock` exist):
```bash
uv sync
source .venv/bin/activate
pre-commit install
```

### Alternative: Using pip

```bash
pip install 'pre-commit==4.6.0' # pinned version (Golden Rule 15)
pre-commit install
```

Add to `requirements-dev.txt`: `pre-commit==4.6.0`

## First-Time Setup

Run on all files to catch existing issues:
```bash
pre-commit run --all-files
```

Auto-fix hooks will modify files on first run. Stage and commit these separately:
```bash
git diff
git add .
git commit -m "Fix: Apply pre-commit auto-fixes"
```

**Exclude fix commits from git blame:**
```bash
# Create .git-blame-ignore-revs with commit hashes
git config blame.ignoreRevsFile .git-blame-ignore-revs
```

See [git-blame docs](https://git-scm.com/docs/git-blame#Documentation/git-blame.txt---ignore-revs-filefile).

## Usage

**Automatic** (runs on `git commit`):
```bash
git add <files>
git commit -m "Message"
```

**Manual:**
```bash
pre-commit run # staged files only
pre-commit run --all-files # entire repo
pre-commit run --files path/to/file # specific files
```

**Bypass (use sparingly):**
```bash
SKIP=hook-id git commit -m "Message" # skip one hook
git commit --no-verify # NEVER use (Golden Rule 16)
```

Rules: Agents never bypass hooks. Security hooks (gitleaks) never bypassable.

## Troubleshooting

**macOS timeout issues:**
```bash
brew install coreutils # provides gtimeout
```

**Virtual environment not found:**
```bash
source .venv/bin/activate
uv sync
```

**Hooks not running:**
```bash
ls -la .git/hooks/pre-commit # verify installation
pre-commit install # reinstall
```

**Hook failures:** Read error messages and fix issues:
- `go-build`: Fix compilation errors
- `go-mod-tidy`: Run `go mod tidy` and stage go.mod/go.sum
- `check-yaml`: Fix YAML syntax

## CI Integration

Pre-commit mirrors `ci/prow/lint`. CI is authoritative; pre-commit is developer convenience. All hooks run in CI with same config.

If pre-commit passes but CI fails: `pre-commit autoupdate`

## Resources

- [Pre-Commit Documentation](https://pre-commit.com/)
- [uv Documentation](https://github.com/astral-sh/uv)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import subprocess
import sys
from pathlib import Path
from typing import Any
from typing import Any, Optional

import yaml

Expand Down Expand Up @@ -629,7 +629,7 @@ def write_pko_dockerfile():
)
)

def extract_deployment_selector() -> str | None:
def extract_deployment_selector() -> Optional[str]:
"""
Extract the clusterDeploymentSelector from hack/olm-registry/olm-artifacts-template.yaml.

Expand Down
13 changes: 11 additions & 2 deletions boilerplate/openshift/golang-osd-operator/pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
# =============================================================================
#
# INSTALL
# pip install pre-commit
# pre-commit install
# For detailed setup instructions including uv (recommended) and pip,
# see: boilerplate/openshift/golang-osd-operator/docs/pre-commit.md
#
# Quick start (uv):
# uv sync && source .venv/bin/activate && pre-commit install
#
# Quick start (pip):
# pip install 'pre-commit==4.6.0' && pre-commit install
#
# USAGE
# pre-commit run # staged files only (developer / agent workflow)
Expand Down Expand Up @@ -35,6 +41,9 @@
# pre-existing violations on the first run. Stage and commit those fixes
# separately before day-to-day use.
#
# Fix commits can be excluded from git blame
# https://git-scm.com/docs/git-blame#Documentation/git-blame.txt---ignore-revs-filefile
#
# =============================================================================

repos:
Expand Down
22 changes: 21 additions & 1 deletion boilerplate/openshift/golang-osd-operator/standard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,28 @@ else
$(info Did not find 'config/default' - skipping kustomize manifest generation)
endif

.PHONY: sync-pko-crds
sync-pko-crds:
ifneq (,$(wildcard deploy_pko))
@if [ -d deploy/crds ]; then \
yq_yaml_flag=""; \
if $(YQ) --version 2>&1 | grep -qE "^yq [0-9]"; then \
yq_yaml_flag="-y"; \
fi; \
for crd in deploy/crds/*.yaml; do \
[ -f "$$crd" ] || continue; \
name=$$($(YQ) -r '.metadata.name' "$$crd"); \
$(YQ) $$yq_yaml_flag '.metadata.annotations["package-operator.run/phase"] = "crds" | .metadata.annotations["package-operator.run/collision-protection"] = "IfNoController"' \
"$$crd" > "deploy_pko/CustomResourceDefinition-$$name.yaml"; \
echo "Synced CRD $$name to deploy_pko/"; \
done; \
fi
else
$(info deploy_pko/ not found - skipping PKO CRD sync)
endif

.PHONY: generate
generate: op-generate go-generate openapi-generate manifests
generate: op-generate go-generate openapi-generate manifests sync-pko-crds

ifeq (${FIPS_ENABLED}, true)
go-build: ensure-fips
Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ COPY . .
RUN make go-build

####
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.8-1779809423
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.8-1780378819

ENV USER_UID=1001 \
USER_NAME=pagerduty-operator
Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile.olm-registry
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ COPY ${SAAS_OPERATOR_DIR} manifests
RUN initializer --permissive

# ubi-micro does not work for clusters with fips enabled unless we make OpenSSL available
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.8-1779809423
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.8-1780378819

COPY --from=builder /bin/registry-server /bin/registry-server
COPY --from=builder /bin/grpc_health_probe /bin/grpc_health_probe
Expand Down
Loading