at 25.11-pre 3.2 kB view raw
1#!/usr/bin/env nix-shell 2#!nix-shell -i python3 -p "python3.withPackages(ps: with ps; [ requests pyquery click ])" 3 4# To use, just execute this script with --help to display help. 5 6import subprocess 7import json 8import sys 9 10import click 11import requests 12from pyquery import PyQuery as pq 13 14def map_dict (f, d): 15 for k,v in d.items(): 16 d[k] = f(v) 17 18maintainers_json = subprocess.check_output([ 19 'nix-instantiate', '-A', 'lib.maintainers', '--eval', '--strict', '--json' 20]) 21maintainers = json.loads(maintainers_json) 22MAINTAINERS = map_dict(lambda v: v.get('github', None), maintainers) 23 24def get_response_text(url): 25 return pq(requests.get(url).text) # IO 26 27EVAL_FILE = { 28 'nixos': 'nixos/release.nix', 29 'nixpkgs': 'pkgs/top-level/release.nix', 30} 31 32 33def get_maintainers(attr_name): 34 try: 35 nixname = attr_name.split('.') 36 meta_json = subprocess.check_output([ 37 'nix-instantiate', 38 '--eval', 39 '--strict', 40 '-A', 41 '.'.join(nixname[1:]) + '.meta', 42 EVAL_FILE[nixname[0]], 43 '--arg', 44 'nixpkgs', 45 './.', 46 '--json']) 47 meta = json.loads(meta_json) 48 return meta.get('maintainers', []) 49 except: 50 return [] 51 52def filter_github_users(maintainers): 53 github_only = [] 54 for i in maintainers: 55 if i.get('github'): 56 github_only.append(i) 57 return github_only 58 59def print_build(table_row): 60 a = pq(table_row)('a')[1] 61 print("- [ ] [{}]({})".format(a.text, a.get('href')), flush=True) 62 63 job_maintainers = filter_github_users(get_maintainers(a.text)) 64 if job_maintainers: 65 print(" - maintainers: {}".format(" ".join(map(lambda u: '@' + u.get('github'), job_maintainers)))) 66 # TODO: print last three persons that touched this file 67 # TODO: pinpoint the diff that broke this build, or maybe it's transient or maybe it never worked? 68 69 sys.stdout.flush() 70 71@click.command() 72@click.option( 73 '--jobset', 74 default="nixos/release-19.09", 75 help='Hydra project like nixos/release-19.09') 76def cli(jobset): 77 """ 78 Given a Hydra project, inspect latest evaluation 79 and print a summary of failed builds 80 """ 81 82 url = "https://hydra.nixos.org/jobset/{}".format(jobset) 83 84 # get the last evaluation 85 click.echo(click.style( 86 'Getting latest evaluation for {}'.format(url), fg='green')) 87 d = get_response_text(url) 88 evaluations = d('#tabs-evaluations').find('a[class="row-link"]') 89 latest_eval_url = evaluations[0].get('href') 90 91 # parse last evaluation page 92 click.echo(click.style( 93 'Parsing evaluation {}'.format(latest_eval_url), fg='green')) 94 d = get_response_text(latest_eval_url + '?full=1') 95 96 # TODO: aborted evaluations 97 # TODO: dependency failed without propagated builds 98 print('\nFailures:') 99 for tr in d('img[alt="Failed"]').parents('tr'): 100 print_build(tr) 101 102 print('\nDependency failures:') 103 for tr in d('img[alt="Dependency failed"]').parents('tr'): 104 print_build(tr) 105 106 107 108if __name__ == "__main__": 109 try: 110 cli() 111 except Exception as e: 112 import pdb;pdb.post_mortem()