Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
94cfb2723f453c0cd7bffba112d1ee2a89fba996 # Run ruff format on all files
5809b73d4aec68f180d25d2451288250fd6d25ef # Run ruff check on all files
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
name: Docker Compose Validation
name: CI

on:
pull_request:
push:
branches: [ main ]
pull_request:

env:
UV_LOCKED: true # Assert that the `uv.lock` will remain unchanged

jobs:
precommit:
name: Run pre-commit
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v6

- name: Install uv and set the python version
uses: astral-sh/setup-uv@v7
with:
# It is considered best practice to pin to a specific uv version.
version: "0.9.29"
python-version: '3.13'

- name: Install the project
run: uv sync

- name: Cache pre-commit hooks and environments
uses: actions/cache@v5
with:
path: ~/.cache/pre-commit
key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}

- name: Run remaining pre-commit hooks
run: uv run pre-commit run --all-files

validate-compose:
name: Spin up and test health of services
runs-on: ubuntu-latest
needs: precommit # Only run if precommit checks pass

steps:
- name: Checkout repository
Expand Down Expand Up @@ -75,4 +105,4 @@ jobs:

- name: Tear down Docker Compose
if: always()
run: docker compose down -v
run: docker compose down -v
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# .pre-commit-config.yaml
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.0 # pin to a specific Ruff version
hooks:
# Ruff linting (includes some type-related rules if enabled in your config)
- id: ruff-check
args:
- --fix

# Ruff formatting
- id: ruff-format
16 changes: 8 additions & 8 deletions docker/netbox/patch_federation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from pathlib import Path

NETBOX_ROOT = Path('/opt/netbox/netbox')
NETBOX_ROOT = Path("/opt/netbox/netbox")

resolve_reference = '''\
@classmethod
Expand All @@ -10,7 +10,7 @@ def resolve_reference(cls, id: strawberry.ID) -> '{type_name}':
return models.{model_name}.objects.get(pk=id)
'''

type_directives = f"directives=[Key(fields=key, resolvable=UNSET) for key in ['id']],"
type_directives = "directives=[Key(fields=key, resolvable=UNSET) for key in ['id']],"


def insert_import(text: str, import_stmt: str) -> str:
Expand All @@ -19,7 +19,7 @@ def insert_import(text: str, import_stmt: str) -> str:


def patch_types():
file = NETBOX_ROOT / 'dcim/graphql/types.py'
file = NETBOX_ROOT / "dcim/graphql/types.py"
text = file.open().read()

text = insert_import(text, "from strawberry.federation.schema_directives import Key")
Expand All @@ -34,21 +34,21 @@ def patch_types():
text = re.sub(regex_find_class, rf"\1{method}\n", text, count=1, flags=re.DOTALL)

# Add directives to the class decorator
regex_find_decorator = rf"(@strawberry_django.type\(\n\s+models\.{model_name},)"
regex_find_decorator = rf"(@strawberry_django.type\(\n\s+models\.{model_name},)"
text = re.sub(regex_find_decorator, rf"\1 {type_directives}", text, count=1)

with file.open(mode='w') as f:
with file.open(mode="w") as f:
f.write(text)


def patch_subscription_query():
file = NETBOX_ROOT / 'extras/graphql/schema.py'
file = NETBOX_ROOT / "extras/graphql/schema.py"
text = file.open().read()

text = re.sub("subscription:", "nb_subscription:", text, count=1)
text = re.sub("subscription_list:", "nb_subscription_list:", text, count=1)

with file.open(mode='w') as f:
with file.open(mode="w") as f:
f.write(text)


Expand All @@ -60,5 +60,5 @@ def main():
patch_subscription_query()


if __name__ == '__main__':
if __name__ == "__main__":
main()
Loading