Pre-commit hooks
This commit is contained in:
57
.github/scripts/ensure_compose_image.py
vendored
Normal file
57
.github/scripts/ensure_compose_image.py
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
try:
|
||||
import yaml
|
||||
except Exception as e:
|
||||
sys.stderr.write("PyYAML is required to run this hook.\n")
|
||||
raise
|
||||
|
||||
EXPECTED_IMAGE = "cooldockerizer93/spotizerr"
|
||||
|
||||
|
||||
def validate_compose_image(path: Path) -> int:
|
||||
if not path.exists():
|
||||
sys.stderr.write(f"File not found: {path}\n")
|
||||
return 1
|
||||
|
||||
try:
|
||||
with path.open("r", encoding="utf-8") as f:
|
||||
data = yaml.safe_load(f)
|
||||
except Exception as e:
|
||||
sys.stderr.write(f"Failed to parse YAML from {path}: {e}\n")
|
||||
return 1
|
||||
|
||||
image = (
|
||||
(data or {})
|
||||
.get("services", {})
|
||||
.get("spotizerr", {})
|
||||
.get("image")
|
||||
)
|
||||
|
||||
errors = []
|
||||
if not isinstance(image, str):
|
||||
errors.append("services.spotizerr.image is missing or not a string")
|
||||
else:
|
||||
if image != EXPECTED_IMAGE:
|
||||
errors.append(
|
||||
f"services.spotizerr.image must be '{EXPECTED_IMAGE}' (found '{image}')"
|
||||
)
|
||||
|
||||
if errors:
|
||||
sys.stderr.write("docker-compose.yaml validation failed:\n")
|
||||
for err in errors:
|
||||
sys.stderr.write(f" - {err}\n")
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
compose_path = Path(argv[1]) if len(argv) > 1 else Path("docker-compose.yaml")
|
||||
return validate_compose_image(compose_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv))
|
||||
@@ -1,32 +1,11 @@
|
||||
repos:
|
||||
# Various general + format-specific helpers
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v5.0.0
|
||||
rev: v4.6.0
|
||||
hooks:
|
||||
- id: check-symlinks
|
||||
exclude: ^spotizerr-ui/
|
||||
- id: trailing-whitespace
|
||||
exclude: ^spotizerr-ui/
|
||||
- id: mixed-line-ending
|
||||
args: [--fix=lf]
|
||||
exclude: ^spotizerr-ui/
|
||||
- id: check-yaml
|
||||
exclude: 'mkdocs.yml|^spotizerr-ui/'
|
||||
- id: check-toml
|
||||
exclude: ^spotizerr-ui/
|
||||
- id: check-json
|
||||
exclude: ^spotizerr-ui/
|
||||
- id: check-ast
|
||||
exclude: ^spotizerr-ui/
|
||||
- id: debug-statements
|
||||
exclude: ^spotizerr-ui/
|
||||
- id: check-merge-conflict
|
||||
exclude: ^spotizerr-ui/
|
||||
- id: check-shebang-scripts-are-executable
|
||||
exclude: ^spotizerr-ui/
|
||||
- id: check-added-large-files
|
||||
args: [--maxkb=10000]
|
||||
exclude: ^spotizerr-ui/
|
||||
- id: end-of-file-fixer
|
||||
- id: trailing-whitespace
|
||||
- repo: https://github.com/python-jsonschema/check-jsonschema
|
||||
rev: '0.33.0'
|
||||
hooks:
|
||||
@@ -53,3 +32,10 @@ repos:
|
||||
exclude: ^spotizerr-ui/
|
||||
# NOTE: you might need to add some deps here:
|
||||
additional_dependencies: [waitress==3.0.2, types-waitress, types-requests]
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: ensure-compose-image
|
||||
name: Ensure docker-compose image is cooldockerizer93/spotizerr
|
||||
entry: python3 .github/scripts/ensure_compose_image.py docker-compose.yaml
|
||||
language: system
|
||||
files: ^docker-compose\.ya?ml$
|
||||
|
||||
@@ -2,7 +2,7 @@ name: spotizerr
|
||||
|
||||
services:
|
||||
spotizerr:
|
||||
image: cooldockerizer93/spotizerr:beta
|
||||
image: cooldockerizer93/spotizerr:eee
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
- ./downloads:/app/downloads # <-- Change this for your music library dir
|
||||
|
||||
Reference in New Issue
Block a user