scripts/mark-broken: improve

This improves on the previous verison of this script.

Previously it only accepted one attr, and required
explicit passing of the "broken" value.

This script is meant to be used to mark failing hydra builds as broken in the meta attrs
To use the script, you should pass the list of failing attrs as arguments to the script.

Example: `cat failing-attrs | xargs ./pkgs/common-update/scripts/mark-broken`

Generating a list of failing attrs: (this should be improved at a later date)
  - Go to the most recent hydra evaluation with all builds completed
  - Select the "builds still failing" tab
  - Highlight and select all packages, should be prefixed with `nixpkgs.`
  - Use regex and editor foo to leave only the attr names
  - Use the above example command to then execute the script

OTHER NOTES:
  - The `denyFileList` and `denyAttrList` will likely need to be updated slightly
    to align with the conventions used in nixpkgs at execution time
  - Any attrs which failed for any reason will be written to `failed-marks.txt`.
    Those attrs will likely need manual attention as disablement will likely be conditional.
This commit is contained in:
Jonathan Ringer 2020-10-25 22:07:10 -07:00 committed by Jonathan Ringer
parent b8f45c32f8
commit 0544a7f672

View file

@ -1,86 +1,106 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e
# This script is meant to be used to mark failing hydra builds as broken in the meta attrs
# To use the script, you should pass the list of failing attrs as arguments to the script.
#
# Example: `cat failing-attrs | xargs ./pkgs/common-update/scripts/mark-broken`
#
# Generating a list of failing attrs: (this should be improved at a later date)
# - Go to the most recent hydra evaluation with all builds completed
# - Select the "builds still failing" tab
# - Highlight and select all packages, should be prefixed with `nixpkgs.`
# - Use regex and editor foo to leave only the attr names
# - Use the above example command to then execute the script
#
# OTHER NOTES:
# - The `denyFileList` and `denyAttrList` will likely need to be updated slightly
# to align with the conventions used in nixpkgs at execution time
# - Any attrs which failed for any reason will be written to `failed-marks.txt`.
# Those attrs will likely need manual attention as disablement will likely be conditional.
scriptName=mark-broken # do not use the .wrapped name scriptName=mark-broken # do not use the .wrapped name
die() { failMark() {
echo "$scriptName: error: $1" >&2 local attr=$1
exit 1 shift 1
echo "$attr: $@" >&2
echo $attr >> failed-marks.txt
} }
usage() { usage() {
echo "Usage: $scriptName <attr> [--new-value=<new-value>]" echo "Usage: $scriptName <attrs>"
} }
args=() if (( "${#@}" < 1 )); then
for arg in "$@"; do
case $arg in
--new-value=*)
newValue="${arg#*=}"
;;
--help)
usage
exit 0
;;
--*)
echo "$scriptName: Unknown argument: $arg"
usage
exit 1
;;
*)
args["${#args[*]}"]=$arg
;;
esac
done
attr=${args[0]}
if (( "${#args[*]}" < 1 )); then
echo "$scriptName: Too few arguments" echo "$scriptName: Too few arguments"
usage usage
exit 1 exit 1
fi fi
if (( "${#args[*]}" > 1 )); then # in case we resolve to an auto-generated file, just skip these entries
echo "$scriptName: Too many arguments" denyFileList=(
usage node-packages.nix # node, it will mark all node packages as broken
exit 1 generic-builder.nix # haskell, it will mark all haskell packages as broken
fi )
if [ -z $newValue ]; then # ignore older versions of parameterized packages sets, these likely need
newValue="true" # to be conditionally disabled
fi denyAttrList=(
python27Packages
python37Packages
libsForQt512
linuxPackages_
rubyPackages_
)
nixFile=$(nix-instantiate --eval --json -E "with import ./. {}; (builtins.unsafeGetAttrPos \"description\" $attr.meta).file" | jq -r .) function attemptToMarkBroken() {
if [[ ! -f "$nixFile" ]]; then local attr=$1
die "Couldn't evaluate 'builtins.unsafeGetAttrPos \"description\" $attr.meta' to locate the .nix file!"
fi
# Insert broken attribute # skip likely to be noisy attrs
sed -i.bak "$nixFile" -r \ for badAttr in ${denyAttrList[@]};do
if [[ $attr =~ $badAttr ]]; then
failMark $attr "attr contained $badAttr, skipped."
return
fi
done
nixFile=$(nix-instantiate --eval --json -E "with import ./. {}; (builtins.unsafeGetAttrPos \"description\" $attr.meta).file" 2>/dev/null | jq -r .)
if [[ ! -f "$nixFile" ]]; then
failMark $attr "Couldn't locate correct file"
return
fi
# skip files which are auto-generated
for filename in ${denyFileList[@]};do
if [[ "$filename" == $(basename $nixFile) ]]; then
failMark $attr "filename matched $filename, skipped."
return
fi
done
# Insert broken attribute
sed -i.bak "$nixFile" -r \
-e "/^\s*broken\s*=.*$/d" \ -e "/^\s*broken\s*=.*$/d" \
-e "s/(\s*)meta\s*=.*\{/&\n\1 broken = $newValue;/" -e "s/(\s*)meta\s*=.*\{/&\n\1 broken = true;/"
if cmp -s "$nixFile" "$nixFile.bak"; then if cmp -s "$nixFile" "$nixFile.bak"; then
mv "$nixFile.bak" "$nixFile" mv "$nixFile.bak" "$nixFile"
die "Failed to mark the package as broken! Does it have a meta attribute?" failMark $attr "Does it have a meta attribute?"
fi return
fi
if [[ "$newValue" == "true" ]]; then
# broken should evaluate to true in any case now # broken should evaluate to true in any case now
markedSuccessfully=$(nix-instantiate --eval -E "with import ./. {}; $attr.meta.broken" || true) markedSuccessfully=$(nix-instantiate --eval -E "with import ./. {}; $attr.meta.broken")
if [[ ! "$markedSuccessfully" == "true" ]]; then if [[ "$markedSuccessfully" != "true" ]]; then
mv "$nixFile.bak" "$nixFile" mv "$nixFile.bak" "$nixFile"
die "Couldn't verify the broken attribute to be set correctly, restoring backup!" failMark $attr "$attr.meta.broken doesn't evaluate to true."
return
fi fi
else
# we can not check if broken evaluates to the correct value, but we can check that it does evaluate
if ! nix-instantiate --eval -E "with import ./. {}; $attr.meta.broken" >/dev/null; then
mv "$nixFile.bak" "$nixFile"
die "Couldn't verify the broken attribute to be set correctly, restoring backup!"
fi
fi
rm -f "$nixFile.bak" rm -f "$nixFile.bak"
rm -f "$attr.fetchlog" }
for attr in $@; do
attemptToMarkBroken $attr
done