2018-03-22 07:53:38 +03:00
#!/usr/bin/env bash
2018-02-25 07:34:22 +03:00
set -euxo pipefail
2018-03-22 07:53:38 +03:00
SCRIPT_DIR = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd ) "
2018-03-22 08:00:31 +03:00
# shellcheck source=setup-nixpkgs.sh
2018-03-22 07:53:38 +03:00
source " $SCRIPT_DIR /setup-nixpkgs.sh "
NIX_PATH = nixpkgs = " $NIXPKGS "
2018-03-17 17:57:57 +03:00
export NIX_PATH
2018-02-25 07:34:22 +03:00
PACKAGE_NAME = $1
OLD_VERSION = $2
NEW_VERSION = $3
2018-03-22 07:53:38 +03:00
if [ " $# " -eq 4 ]
then
OK_TO_PR_AT = $4
else
OK_TO_PR_AT = "0"
fi
2018-02-25 07:34:22 +03:00
2018-03-04 17:58:53 +03:00
BRANCH_NAME = " auto-update/ $1 "
2018-02-25 07:34:22 +03:00
2018-03-15 08:19:40 +03:00
function cleanup {
git reset --hard
2018-03-22 21:14:04 +03:00
git clean -fd
2018-03-15 08:19:40 +03:00
git checkout master
git reset --hard upstream/master
git branch -D " $BRANCH_NAME " || true
}
function error_exit {
cleanup
2018-03-22 08:00:31 +03:00
if ( true >& 3 ) 2> /dev/null
2018-03-22 07:53:38 +03:00
then
echo " $( date -Iseconds) $1 " >& 3
else
echo " $( date -Iseconds) $1 "
fi
2018-03-15 08:19:40 +03:00
exit 1
}
2018-03-20 07:00:52 +03:00
if ! [ " $( nix eval -f . " (builtins.compareVersions \" $NEW_VERSION \" \" $OLD_VERSION \") " ) " -eq 1 ] ;
2018-03-19 20:18:44 +03:00
then
error_exit " $NEW_VERSION is not newer than $OLD_VERSION according to Nix "
fi
2018-03-07 19:11:18 +03:00
# Package blacklist
case " $PACKAGE_NAME " in
2018-03-18 16:55:13 +03:00
*jquery*) error_exit "this isn't a real package" ; ;
*google-cloud-sdk*) error_exit "complicated package" ; ;
*github-release*) error_exit "complicated package" ; ;
*fcitx*) error_exit "gets stuck in daemons" ; ;
*libxc*) error_exit "currently people don't want to update this https://github.com/NixOS/nixpkgs/pull/35821" ; ;
2018-03-20 16:57:44 +03:00
*perl*) error_exit "currently don't know how to update perl" ; ;
*python*) error_exit "currently don't know how to update python" ; ;
*cdrtools*) error_exit "We keep downgrading this by accident." ; ;
*gst*) error_exit "gstreamer plugins are kept in lockstep." ; ;
2018-03-20 17:06:26 +03:00
*electron*) error_exit "multi-platform srcs in file." ; ;
2018-03-23 03:18:45 +03:00
*linux-headers*) error_exit "Not updated until many packages depend on it (part of stdenv)." ; ;
2018-03-21 06:24:11 +03:00
*mpich*) error_exit "Reported on repology.org as mischaracterized newest version" ; ;
2018-03-22 04:58:49 +03:00
*xfce*) error_exit "@volth asked to not update xfce" ; ;
2018-03-22 19:05:18 +03:00
*cmake-cursesUI-qt4UI*) error_exit "Derivation file is complicated" ; ;
2018-03-15 08:19:40 +03:00
*) true; ;
esac || error_exit "Package on blacklist."
2018-03-07 19:11:18 +03:00
2018-03-22 08:47:07 +03:00
git fetch --prune --multiple upstream origin
2018-03-15 08:19:40 +03:00
if git branch --remote | grep " origin/auto-update/ ${ PACKAGE_NAME } "
then
error_exit "Update branch already on origin."
fi
2018-03-08 07:21:32 +03:00
2018-03-15 08:19:40 +03:00
git reset --hard
2018-03-22 21:14:04 +03:00
git clean -fd
2018-03-14 20:06:37 +03:00
git checkout master
git reset --hard upstream/master
2018-03-22 21:14:04 +03:00
git clean -fd
2018-03-14 20:06:37 +03:00
2018-03-17 01:55:41 +03:00
# This is extremely slow but will give us better results
2018-03-18 08:04:34 +03:00
ATTR_PATH = $( nix-env -qa " $PACKAGE_NAME - $OLD_VERSION " -f . --attr-path | head -n1 | cut -d' ' -f1) || error_exit "nix-env -q failed to find package name with old version"
2018-03-17 01:55:41 +03:00
2018-03-18 16:46:40 +03:00
# Temporarily blacklist gnome sources for lockstep update
if nix eval -f . " pkgs. ${ ATTR_PATH } .src.urls " | grep "gnome"
then
error_exit "Packages from gnome are currently blacklisted."
fi
2018-03-22 06:53:40 +03:00
# Temporarily blacklist lua packages at @teto's request
# https://github.com/NixOS/nixpkgs/pull/37501#issuecomment-375169646
if echo " $ATTR_PATH " | grep "^lua"
then
error_exit "Packages for lua are currently blacklisted."
fi
2018-03-17 17:57:57 +03:00
DERIVATION_FILE = $( EDITOR = "echo" nix edit " $ATTR_PATH " -f .) || error_exit "Couldn't find derivation file."
2018-02-25 07:34:22 +03:00
2018-03-15 08:19:40 +03:00
function error_cleanup {
cleanup
2018-03-07 17:48:03 +03:00
exit 1
2018-02-25 07:34:22 +03:00
}
trap error_cleanup ERR
2018-03-22 21:14:04 +03:00
function interrupt_cleanup {
cleanup
exit 2
}
trap interrupt_cleanup INT
2018-03-22 06:53:30 +03:00
( ( $( grep -c "fetchurl {" " $DERIVATION_FILE " ) + $( grep -c "fetchgit {" " $DERIVATION_FILE " ) + $( grep -c "fetchFromGitHub {" " $DERIVATION_FILE " ) <= 1 ) ) || error_exit " More than one fetcher in $DERIVATION_FILE "
2018-03-22 05:07:06 +03:00
if grep -q "DO NOT EDIT" " $DERIVATION_FILE "
then
error_exit "Derivation file says not to edit it."
fi
2018-02-25 07:34:22 +03:00
2018-03-07 18:56:38 +03:00
# Skip packages that have special builders
2018-03-15 08:19:40 +03:00
if grep -q "buildGoPackage" " $DERIVATION_FILE "
then
error_exit "Derivation contains buildGoPackage."
fi
if grep -q "buildRustCrate" " $DERIVATION_FILE "
then
error_exit "Derivation contains buildRustCrate."
fi
if grep -q "buildPythonPackage" " $DERIVATION_FILE "
then
error_exit "Derivation contains buildPythonPackage."
fi
if grep -q "buildRubyGem" " $DERIVATION_FILE "
then
error_exit "Derivation contains buildRubyGem."
fi
if grep -q "bundlerEnv" " $DERIVATION_FILE "
then
error_exit "Derivation contains bundlerEnv."
fi
2018-03-18 16:46:40 +03:00
if grep -q "buildPerlPackage" " $DERIVATION_FILE "
then
error_exit "Derivation contains buildPerlPackage."
fi
2018-03-07 18:56:38 +03:00
2018-03-22 16:50:54 +03:00
" $SCRIPT_DIR " /check-attrpath-version.sh " $ATTR_PATH " " $NEW_VERSION " || error_exit " Version in attr path $ATTR_PATH not compatible with $NEW_VERSION "
2018-03-22 08:46:21 +03:00
2018-03-07 17:48:03 +03:00
# Make sure it hasn't been updated on master
2018-03-15 08:19:40 +03:00
grep " $OLD_VERSION " " $DERIVATION_FILE " || error_exit "Old version not present in master derivation file."
2018-02-25 07:34:22 +03:00
2018-03-07 17:48:03 +03:00
# Make sure it hasn't been updated on staging
2018-03-15 08:19:40 +03:00
git reset --hard
2018-03-22 21:14:04 +03:00
git clean -fd
2018-03-07 17:48:03 +03:00
git checkout staging
2018-03-14 20:06:37 +03:00
git reset --hard upstream/staging
2018-03-22 21:14:04 +03:00
git clean -fd
2018-03-15 08:19:40 +03:00
grep " $OLD_VERSION " " $DERIVATION_FILE " || error_exit "Old version not present in staging derivation file."
2018-02-25 07:34:22 +03:00
2018-03-17 17:57:57 +03:00
git checkout " $( git merge-base upstream/master upstream/staging) "
2018-03-07 17:48:03 +03:00
git checkout -B " $BRANCH_NAME "
2018-03-17 02:06:12 +03:00
OLD_HASH = $( nix eval -f . --raw " pkgs. $ATTR_PATH .src.drvAttrs.outputHash " || error_exit "Couldn't find old output hash at ATTR_PATH.src.drvAttrs.outputHash." )
2018-03-07 18:42:18 +03:00
2018-03-29 16:39:34 +03:00
OLD_SRC_URL = $( nix eval -f . --raw '(let pkgs = import ./. {}; in builtins.elemAt pkgs.' " $ATTR_PATH " '.src.drvAttrs.urls 0)' )
2018-03-23 05:04:06 +03:00
2018-03-15 08:19:40 +03:00
sed -i " s/ ${ OLD_VERSION // \. / \\ . } / $NEW_VERSION /g " " $DERIVATION_FILE " || error_exit "Could not replace OLD_VERSION with NEW_VERSION."
2018-02-25 07:34:22 +03:00
2018-03-29 16:39:34 +03:00
NEW_SRC_URL = $( nix eval -f . --raw '(let pkgs = import ./. {}; in builtins.elemAt pkgs.' " $ATTR_PATH " '.src.drvAttrs.urls 0)' )
2018-03-23 05:04:06 +03:00
if [ " $OLD_SRC_URL " = = " $NEW_SRC_URL " ]
then
error_exit "Source url did not change."
fi
2018-03-29 16:39:34 +03:00
NEW_HASH = $(
nix-prefetch-url -A " $ATTR_PATH .src " || \
" $SCRIPT_DIR " /fix-src-url.sh " $PACKAGE_NAME " " $OLD_VERSION " " $NEW_VERSION " " $DERIVATION_FILE " " $ATTR_PATH " " $OLD_SRC_URL " || \
error_exit "Could not prefetch new version URL." )
2018-02-25 07:34:22 +03:00
if [ " $OLD_HASH " = " $NEW_HASH " ]
then
2018-03-15 08:19:40 +03:00
error_exit "Hashes equal; no update necessary"
2018-02-25 07:34:22 +03:00
fi
2018-03-15 08:19:40 +03:00
sed -i " s/ $OLD_HASH / $NEW_HASH /g " " $DERIVATION_FILE " || error_exit "Could not replace OLD_HASH with NEW_HASH."
2018-02-25 07:34:22 +03:00
2018-03-16 04:45:10 +03:00
rm -f result*
2018-03-04 23:58:44 +03:00
2018-03-29 16:39:34 +03:00
nix build -f . " $ATTR_PATH " || error_exit " nix build failed.
$( nix log -f . " $ATTR_PATH " | tail -n 30) "
2018-03-16 04:41:52 +03:00
RESULT = $( readlink ./result || readlink ./result-bin || error_exit "Couldn't find result link." )
2018-02-25 08:22:10 +03:00
2018-03-17 17:57:57 +03:00
CHECK_RESULT = " $( " $SCRIPT_DIR " /check-result.sh " $RESULT " " $NEW_VERSION " ) "
2018-02-25 07:34:22 +03:00
2018-02-26 10:14:27 +03:00
MAINTAINERS =
2018-03-17 02:06:12 +03:00
if nix eval " (let pkgs = import ./. {}; in pkgs. $ATTR_PATH .meta.maintainers) " > /dev/null 2>& 1
2018-02-26 10:14:27 +03:00
then
2018-03-18 08:04:34 +03:00
maintainers = $( nix eval --raw '(let pkgs = import ./. {}; gh = m : m.github or ""; nonempty = s: s != ""; addat = s: "@"+s; in builtins.concatStringsSep " " (map addat (builtins.filter nonempty (map gh pkgs.' " ${ ATTR_PATH } " '.meta.maintainers))))' )
2018-02-26 10:14:27 +03:00
if [ -n " $maintainers " ]
then
MAINTAINERS = "
2018-03-10 01:59:38 +03:00
cc $maintainers for review"
2018-02-26 10:14:27 +03:00
fi
fi
2018-02-25 07:34:22 +03:00
git diff
2018-03-18 16:55:13 +03:00
COMMIT_MESSAGE = " $ATTR_PATH : $OLD_VERSION -> $NEW_VERSION
2018-02-25 07:34:22 +03:00
2018-03-23 07:17:36 +03:00
Semi-automatic update generated by https://github.com/ryantm/nix-update tools.
This update was made based on information from https://repology.org/metapackage/$PACKAGE_NAME /versions.
These checks were done :
2018-02-25 07:34:22 +03:00
2018-02-26 04:17:42 +03:00
- built on NixOS
2018-03-04 17:58:53 +03:00
$CHECK_RESULT "
2018-03-04 22:06:43 +03:00
git commit -am " $COMMIT_MESSAGE "
2018-03-04 17:58:53 +03:00
# Try to push it three times
function push( ) {
2018-03-04 22:06:43 +03:00
if [ [ -v DRY_RUN ] ]
2018-03-04 17:58:53 +03:00
then
2018-03-04 22:06:43 +03:00
return 0
else
2018-03-04 17:58:53 +03:00
git push --set-upstream origin " $BRANCH_NAME " --force
fi
}
push || push || push
2018-02-25 07:34:22 +03:00
2018-03-23 03:19:22 +03:00
BROKEN_WARNING =
if [ " $( nix eval -f . '(let pkgs = import ./. {}; in pkgs.' " ${ ATTR_PATH } " '.meta.broken or false)' ) " = = "true" ]
then
BROKEN_WARNING = "- WARNING: Package has meta.broken=true; Please manually test this package update and remove the broken attribute."
fi
PR_MESSAGE = " $COMMIT_MESSAGE $BROKEN_WARNING $MAINTAINERS "
2018-03-04 22:06:43 +03:00
if [ [ -v DRY_RUN ] ]
then
true
else
2018-03-20 08:37:51 +03:00
CURRENT = $( date +%s)
if ( ( CURRENT < OK_TO_PR_AT ) )
then
SLEEP_SECONDS = $(( OK_TO_PR_AT - CURRENT ))
echo " Sleeping $SLEEP_SECONDS seconds. "
sleep " $SLEEP_SECONDS "
fi
2018-03-18 08:04:34 +03:00
hub pull-request -m " $PR_MESSAGE "
2018-03-04 22:06:43 +03:00
fi
2018-03-15 08:19:40 +03:00
git reset --hard
2018-03-22 21:14:04 +03:00
git clean -fd
2018-02-25 07:34:22 +03:00
git checkout master
2018-03-04 22:06:43 +03:00
git reset --hard
2018-03-22 21:14:04 +03:00
git clean -fd
2018-02-26 04:17:42 +03:00
exit 0