mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
ci: move validate maintainers logic to lib
Allow easily running the individual checks outside of GHA for easier testing/modification. Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
parent
bc9f3c8413
commit
defabc11ab
4 changed files with 131 additions and 88 deletions
91
.github/workflows/validate-maintainers.yml
vendored
91
.github/workflows/validate-maintainers.yml
vendored
|
|
@ -25,96 +25,11 @@ jobs:
|
||||||
with:
|
with:
|
||||||
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/${{ steps.get-nixpkgs.outputs.rev }}.tar.gz
|
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/${{ steps.get-nixpkgs.outputs.rev }}.tar.gz
|
||||||
- name: Validate Nix syntax
|
- name: Validate Nix syntax
|
||||||
run: |
|
run: ./lib/python/validate-maintainers-syntax.py
|
||||||
echo "🔍 Validating maintainers.nix syntax..."
|
|
||||||
if nix eval --file modules/lib/maintainers.nix --json > /dev/null; then
|
|
||||||
echo "✅ Valid Nix syntax"
|
|
||||||
else
|
|
||||||
echo "❌ Invalid Nix syntax"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
- name: Validate maintainer entries
|
- name: Validate maintainer entries
|
||||||
run: |
|
run: ./lib/python/validate-maintainer-entries.py
|
||||||
echo "🔍 Validating maintainer entries..."
|
|
||||||
python3 -c "
|
|
||||||
import json
|
|
||||||
import re
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
|
|
||||||
# Get the maintainers data from the Nix file
|
|
||||||
result = subprocess.run(['nix', 'eval', '--file', 'modules/lib/maintainers.nix', '--json'],
|
|
||||||
capture_output=True, text=True, check=True)
|
|
||||||
maintainers = json.loads(result.stdout)
|
|
||||||
errors = []
|
|
||||||
|
|
||||||
for name, data in maintainers.items():
|
|
||||||
# Check REQUIRED fields - github and githubId are mandatory
|
|
||||||
if 'github' not in data:
|
|
||||||
errors.append(f'{name}: Missing required field \"github\"')
|
|
||||||
if 'githubId' not in data:
|
|
||||||
errors.append(f'{name}: Missing required field \"githubId\"')
|
|
||||||
|
|
||||||
# Validate GitHub ID is a positive integer (NOT a string)
|
|
||||||
if 'githubId' in data:
|
|
||||||
github_id = data['githubId']
|
|
||||||
if not isinstance(github_id, int):
|
|
||||||
errors.append(f'{name}: githubId must be a number, not a string: {github_id} (type: {type(github_id).__name__})')
|
|
||||||
elif github_id <= 0:
|
|
||||||
errors.append(f'{name}: githubId must be positive: {github_id}')
|
|
||||||
|
|
||||||
if errors:
|
|
||||||
print('❌ Validation errors found:')
|
|
||||||
for error in errors:
|
|
||||||
print(f' - {error}')
|
|
||||||
sys.exit(1)
|
|
||||||
else:
|
|
||||||
print('✅ All maintainer entries are valid')
|
|
||||||
print(f'✅ Validated {len(maintainers)} maintainer entries')
|
|
||||||
"
|
|
||||||
- name: Check for duplicate maintainers
|
- name: Check for duplicate maintainers
|
||||||
run: |
|
run: ./lib/python/check-duplicate-maintainers.py
|
||||||
echo "🔍 Checking for duplicate maintainers between HM and nixpkgs..."
|
|
||||||
python3 -c "
|
|
||||||
import json
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
|
|
||||||
hm_result = subprocess.run(['nix', 'eval', '--file', 'modules/lib/maintainers.nix', '--json'],
|
|
||||||
capture_output=True, text=True, check=True)
|
|
||||||
hm_maintainers = json.loads(hm_result.stdout)
|
|
||||||
hm_github_users = set()
|
|
||||||
for name, data in hm_maintainers.items():
|
|
||||||
if 'github' in data:
|
|
||||||
hm_github_users.add(data['github'])
|
|
||||||
|
|
||||||
nixpkgs_result = subprocess.run(['nix', 'eval', 'nixpkgs#lib.maintainers', '--json'],
|
|
||||||
capture_output=True, text=True, check=True)
|
|
||||||
nixpkgs_maintainers = json.loads(nixpkgs_result.stdout)
|
|
||||||
nixpkgs_github_users = set()
|
|
||||||
for name, data in nixpkgs_maintainers.items():
|
|
||||||
if isinstance(data, dict) and 'github' in data:
|
|
||||||
nixpkgs_github_users.add(data['github'])
|
|
||||||
|
|
||||||
duplicates = hm_github_users.intersection(nixpkgs_github_users)
|
|
||||||
|
|
||||||
if duplicates:
|
|
||||||
print(f'❌ Found {len(duplicates)} duplicate maintainers between HM and nixpkgs:')
|
|
||||||
for github_user in sorted(duplicates):
|
|
||||||
# Find the HM attribute name for this github user
|
|
||||||
hm_attr = None
|
|
||||||
for attr_name, data in hm_maintainers.items():
|
|
||||||
if data.get('github') == github_user:
|
|
||||||
hm_attr = attr_name
|
|
||||||
break
|
|
||||||
print(f' - {github_user} (HM attribute: {hm_attr})')
|
|
||||||
print()
|
|
||||||
print('These maintainers should be removed from HM maintainers file to avoid duplication.')
|
|
||||||
print('They can be referenced directly from nixpkgs instead.')
|
|
||||||
sys.exit(1)
|
|
||||||
else:
|
|
||||||
print('✅ No duplicate maintainers found')
|
|
||||||
"
|
|
||||||
- name: Test generation
|
- name: Test generation
|
||||||
if: inputs.run_tests == true
|
if: inputs.run_tests == true
|
||||||
run: |
|
run: |
|
||||||
|
|
|
||||||
57
lib/python/check-duplicate-maintainers.py
Executable file
57
lib/python/check-duplicate-maintainers.py
Executable file
|
|
@ -0,0 +1,57 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Check for duplicate maintainers between home-manager and nixpkgs
|
||||||
|
|
||||||
|
This script compares the maintainers in home-manager with those in nixpkgs
|
||||||
|
to identify duplicates that should be removed from home-manager.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print("🔍 Checking for duplicate maintainers between HM and nixpkgs...")
|
||||||
|
|
||||||
|
# Get home-manager maintainers
|
||||||
|
hm_result = subprocess.run(['nix', 'eval', '--file', 'modules/lib/maintainers.nix', '--json'],
|
||||||
|
capture_output=True, text=True, check=True)
|
||||||
|
hm_maintainers = json.loads(hm_result.stdout)
|
||||||
|
hm_github_users = set()
|
||||||
|
for name, data in hm_maintainers.items():
|
||||||
|
if 'github' in data:
|
||||||
|
hm_github_users.add(data['github'])
|
||||||
|
|
||||||
|
# Get nixpkgs maintainers
|
||||||
|
nixpkgs_result = subprocess.run(['nix', 'eval', 'nixpkgs#lib.maintainers', '--json'],
|
||||||
|
capture_output=True, text=True, check=True)
|
||||||
|
nixpkgs_maintainers = json.loads(nixpkgs_result.stdout)
|
||||||
|
nixpkgs_github_users = set()
|
||||||
|
for name, data in nixpkgs_maintainers.items():
|
||||||
|
if isinstance(data, dict) and 'github' in data:
|
||||||
|
nixpkgs_github_users.add(data['github'])
|
||||||
|
|
||||||
|
# Find duplicates
|
||||||
|
duplicates = hm_github_users.intersection(nixpkgs_github_users)
|
||||||
|
|
||||||
|
if duplicates:
|
||||||
|
print(f'❌ Found {len(duplicates)} duplicate maintainers between HM and nixpkgs:')
|
||||||
|
for github_user in sorted(duplicates):
|
||||||
|
# Find the HM attribute name for this github user
|
||||||
|
hm_attr = None
|
||||||
|
for attr_name, data in hm_maintainers.items():
|
||||||
|
if data.get('github') == github_user:
|
||||||
|
hm_attr = attr_name
|
||||||
|
break
|
||||||
|
print(f' - {github_user} (HM attribute: {hm_attr})')
|
||||||
|
print()
|
||||||
|
print('These maintainers should be removed from HM maintainers file to avoid duplication.')
|
||||||
|
print('They can be referenced directly from nixpkgs instead.')
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
print('✅ No duplicate maintainers found')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
46
lib/python/validate-maintainer-entries.py
Executable file
46
lib/python/validate-maintainer-entries.py
Executable file
|
|
@ -0,0 +1,46 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Validate maintainer entries in modules/lib/maintainers.nix
|
||||||
|
|
||||||
|
This script validates that all maintainer entries have required fields
|
||||||
|
and that the data types are correct.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print("🔍 Validating maintainer entries...")
|
||||||
|
|
||||||
|
result = subprocess.run(['nix', 'eval', '--file', 'modules/lib/maintainers.nix', '--json'],
|
||||||
|
capture_output=True, text=True, check=True)
|
||||||
|
maintainers = json.loads(result.stdout)
|
||||||
|
errors = []
|
||||||
|
|
||||||
|
for name, data in maintainers.items():
|
||||||
|
if 'github' not in data:
|
||||||
|
errors.append(f'{name}: Missing required field "github"')
|
||||||
|
if 'githubId' not in data:
|
||||||
|
errors.append(f'{name}: Missing required field "githubId"')
|
||||||
|
|
||||||
|
if 'githubId' in data:
|
||||||
|
github_id = data['githubId']
|
||||||
|
if not isinstance(github_id, int):
|
||||||
|
errors.append(f'{name}: githubId must be a number, not a string: {github_id} (type: {type(github_id).__name__})')
|
||||||
|
elif github_id <= 0:
|
||||||
|
errors.append(f'{name}: githubId must be positive: {github_id}')
|
||||||
|
|
||||||
|
if errors:
|
||||||
|
print('❌ Validation errors found:')
|
||||||
|
for error in errors:
|
||||||
|
print(f' - {error}')
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
print('✅ All maintainer entries are valid')
|
||||||
|
print(f'✅ Validated {len(maintainers)} maintainer entries')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
25
lib/python/validate-maintainers-syntax.py
Executable file
25
lib/python/validate-maintainers-syntax.py
Executable file
|
|
@ -0,0 +1,25 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Validate maintainers.nix syntax
|
||||||
|
|
||||||
|
This script validates that the maintainers.nix file has valid Nix syntax.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print("🔍 Validating maintainers.nix syntax...")
|
||||||
|
|
||||||
|
try:
|
||||||
|
subprocess.run(['nix', 'eval', '--file', 'modules/lib/maintainers.nix', '--json'],
|
||||||
|
capture_output=True, text=True, check=True)
|
||||||
|
print("✅ Valid Nix syntax")
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
print("❌ Invalid Nix syntax")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue