From cbdf92d17270268a7614c82774eac10b31ecb3d0 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 4 Jun 2025 08:52:38 -0400 Subject: [PATCH 1/3] Closes #265: Enable pre-commit --- .pre-commit-config.yaml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..2efe9fd --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,30 @@ +repos: +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.11.12 + hooks: + - id: ruff + name: "Ruff linter" + args: [ netbox_branching/ ] +- repo: local + hooks: + - id: django-check + name: "Django system check" + description: "Run Django's internal check for common problems" + entry: python netbox/manage.py check + language: system + pass_filenames: false + types: [python] + - id: django-makemigrations + name: "Django migrations check" + description: "Check for any missing Django migrations" + entry: python netbox/manage.py makemigrations netbox_branching --check + language: system + pass_filenames: false + types: [python] + - id: mkdocs-build + name: "Build documentation" + description: "Build the documentation with mkdocs" + files: 'docs/' + entry: mkdocs build + language: system + pass_filenames: false From 3de2c5f33832f4d6f21b0cb16cfb1fab7e146af8 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 4 Jun 2025 09:13:08 -0400 Subject: [PATCH 2/3] Clean up rendered docs after testing 'mkdocs build' --- .hooks/mkdocs-build.sh | 17 +++++++++++++++++ .pre-commit-config.yaml | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100755 .hooks/mkdocs-build.sh diff --git a/.hooks/mkdocs-build.sh b/.hooks/mkdocs-build.sh new file mode 100755 index 0000000..f68865b --- /dev/null +++ b/.hooks/mkdocs-build.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -euo pipefail + +echo "Running mkdocs build..." + +TEMP_SITE_DIR=$(mktemp -d) + +# Run mkdocs build into temp dir +if mkdocs build --site-dir "$TEMP_SITE_DIR" --strict; then + echo "Build successful." +else + echo "Build failed." >&2 + exit 1 +fi + +# Cleanup +rm -rf "$TEMP_SITE_DIR" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2efe9fd..1635912 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,6 +25,6 @@ repos: name: "Build documentation" description: "Build the documentation with mkdocs" files: 'docs/' - entry: mkdocs build + entry: .hooks/mkdocs-build.sh language: system pass_filenames: false From 96d5dc7a39fb14dba64d1b5fcd4936ed7672ebcd Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 4 Jun 2025 09:20:00 -0400 Subject: [PATCH 3/3] Omit Django checks for brevity --- .pre-commit-config.yaml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1635912..20f58f5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,20 +7,6 @@ repos: args: [ netbox_branching/ ] - repo: local hooks: - - id: django-check - name: "Django system check" - description: "Run Django's internal check for common problems" - entry: python netbox/manage.py check - language: system - pass_filenames: false - types: [python] - - id: django-makemigrations - name: "Django migrations check" - description: "Check for any missing Django migrations" - entry: python netbox/manage.py makemigrations netbox_branching --check - language: system - pass_filenames: false - types: [python] - id: mkdocs-build name: "Build documentation" description: "Build the documentation with mkdocs"