1#!/usr/bin/env bash
2
3# This script is meant to be used to mark failing hydra builds as broken in the meta attrs
4# To use the script, you should pass the list of failing attrs as arguments to the script.
5#
6# Example: `cat failing-attrs | xargs ./pkgs/common-updater/scripts/mark-broken`
7#
8# Generating a list of failing attrs: (this should be improved at a later date)
9# - Go to the most recent hydra evaluation with all builds completed
10# - Select the "builds still failing" tab
11# - Highlight and select all packages, should be prefixed with `nixpkgs.`
12# - Use regex and editor foo to leave only the attr names
13# - Use the above example command to then execute the script
14#
15# OTHER NOTES:
16# - The `denyFileList` and `denyAttrList` will likely need to be updated slightly
17# to align with the conventions used in nixpkgs at execution time
18# - Any attrs which failed for any reason will be written to `failed-marks.txt`.
19# Those attrs will likely need manual attention as disablement will likely be conditional.
20
21scriptName=mark-broken # do not use the .wrapped name
22
23failMark() {
24 local attr=$1
25 shift 1
26
27 echo "$attr: $@" >&2
28 echo $attr >> failed-marks.txt
29}
30
31usage() {
32 echo "Usage: $scriptName <attrs>"
33}
34
35if (( "${#@}" < 1 )); then
36 echo "$scriptName: Too few arguments"
37 usage
38 exit 1
39fi
40
41# in case we resolve to an auto-generated file, just skip these entries
42denyFileList=(
43 node-packages.nix # node, it will mark all node packages as broken
44 generic-builder.nix # haskell, it will mark all haskell packages as broken
45)
46
47# ignore older versions of parameterized packages sets, these likely need
48# to be conditionally disabled
49denyAttrList=(
50 python27Packages
51 linuxPackages_
52 rubyPackages_
53)
54
55function attemptToMarkBroken() {
56 local attr=$1
57
58 # skip likely to be noisy attrs
59 for badAttr in ${denyAttrList[@]};do
60 if [[ $attr =~ $badAttr ]]; then
61 failMark $attr "attr contained $badAttr, skipped."
62 return
63 fi
64 done
65
66 nixFile=$(nix-instantiate --eval --json -E "with import ./. {}; (builtins.unsafeGetAttrPos \"description\" $attr.meta).file" 2>/dev/null | jq -r .)
67 if [[ ! -f "$nixFile" ]]; then
68 failMark $attr "Couldn't locate correct file"
69 return
70 fi
71
72 # skip files which are auto-generated
73 for filename in ${denyFileList[@]};do
74 if [[ "$filename" == $(basename $nixFile) ]]; then
75 failMark $attr "filename matched $filename, skipped."
76 return
77 fi
78 done
79
80 # Insert broken attribute
81 sed -i.bak "$nixFile" -r \
82 -e "/^\s*broken\s*=.*$/d" \
83 -e "s/(\s*)meta\s*=.*\{/&\n\1 broken = true;/"
84
85 if cmp -s "$nixFile" "$nixFile.bak"; then
86 mv "$nixFile.bak" "$nixFile"
87 failMark $attr "Does it have a meta attribute?"
88 return
89 fi
90
91 # broken should evaluate to true in any case now
92 markedSuccessfully=$(nix-instantiate --eval -E "with import ./. {}; $attr.meta.broken")
93 if [[ "$markedSuccessfully" != "true" ]]; then
94 mv "$nixFile.bak" "$nixFile"
95 failMark $attr "$attr.meta.broken doesn't evaluate to true."
96 return
97 fi
98
99 rm -f "$nixFile.bak"
100}
101
102for attr in $@; do
103 attemptToMarkBroken $attr
104done