Skip to content

Instantly share code, notes, and snippets.

@matthiasbeyer
Created April 12, 2016 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthiasbeyer/6f7b08729c35cd86265feba0ea577205 to your computer and use it in GitHub Desktop.
Save matthiasbeyer/6f7b08729c35cd86265feba0ea577205 to your computer and use it in GitHub Desktop.
nix package update apply helper
#!/usr/bin/env bash
EXEC=$(dirname ${BASH_SOURCE[0]})/nixpkgs-update-pkg.sh
if [[ ! -e $1 ]]; then
echo "Does not exist: $1"
echo "Exit."
exit 1
fi
while read remote pr pkg update_branch; do
$EXEC $remote $pr $pkg $update_branch
if [[ ! $? ]]; then
echo ""
echo "Failed at: $remote $pr $pkg $update_branch"
echo "Exiting"
fi
done < $1
#!/usr/bin/env bash
Color_Off='\e[0m'
Red='\e[0;31m'
Yellow='\e[0;33m'
Green='\e[0;32m'
#
# Print on stderr, in red
#
stderr() {
echo -e "${Red}[$(basename $0)]: ${*}${Color_Off}" >&2
}
#
# Print debugging output on stderr, in green
#
dbg() {
[[ $DEBUG -eq 1 ]] && \
echo -e "${Green}[DEBUG][$(basename $0)]: ${*}${Color_Off}" >&2
}
#
# Print on stdout, if verbosity is enabled, prefix in green
#
stdout() {
echo -e "${Green}[$(basename $0)]:${Color_Off} $*"
}
#
# Explain the next command
#
explain() {
stdout "$*"
$*
}
REMOTE=$1
PR=$2
PKG=$3
UPDATE_BRANCH=$4
CORES=$(if [[ -z "$NIX_CORES" ]]; then echo ""; else echo "--cores $NIX_CORES"; fi)
JOBS=$(if [[ -z "$NIX_JOBS" ]]; then echo ""; else echo "-j $NIX_JOBS"; fi)
dbg "Running with cores: '$CORES'"
dbg "Running with jobs: '$JOBS'"
dbg "checking out $REMOTE/pr/$PR"
git checkout $REMOTE/pr/$PR
dbg "Building..."
explain nix-build -A $PKG $CORES $JOBS
success=$?
dbg "Building done"
if [[ $success ]]
then
stdout "Success building $PKG"
dbg "Getting revisions between the merge-base and master"
revisions=$(git log --pretty=%H master..HEAD)
dbg "Checking out '$UPDATE_BRANCH'"
git checkout $UPDATE_BRANCH || \
(stderr "$UPDATE_BRANCH is not a git branch"; exit 1)
dbg "for each revision, try to apply on $UPDATE_BRANCH"
for revision in $revisions; do
dbg "Applying $revision"
git cherry-pick $revision
if [[ ! $? ]]; then
stderr "Apply failed. Exiting"
exit 1
fi
done
stdout "Applied changes to update branch"
else
stderr "No success building..."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment