Skip to content

Commit

Permalink
common-updater: support for github updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic92 committed Nov 13, 2017
1 parent fd0c613 commit 9a12f24
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkgs/common-updater/scripts.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, makeWrapper, coreutils, gawk, gnused, diffutils, nix }:
{ stdenv, makeWrapper, coreutils, gawk, gnused, diffutils, nix, curl, jq }:

stdenv.mkDerivation {
name = "common-updater-scripts";
Expand All @@ -12,7 +12,7 @@ stdenv.mkDerivation {
cp ${./scripts}/* $out/bin
for f in $out/bin/*; do
wrapProgram $f --prefix PATH : ${stdenv.lib.makeBinPath [ coreutils gawk gnused nix diffutils ]}
wrapProgram $f --prefix PATH : ${stdenv.lib.makeBinPath [ coreutils gawk gnused nix diffutils curl jq ]}
done
'';
}
18 changes: 16 additions & 2 deletions pkgs/common-updater/scripts/update-source-version
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env bash
set -e
set -e -o pipefail

die() {
echo "$0: error: $1" >&2
exit 1
}

# Usage: update-source-hash <attr> <version> [<new-source-hash>]
# Usage: update-source-hash <attr> [<version>] [<new-source-hash>]
attr=$1
newVersion=$2
newHash=$3
Expand Down Expand Up @@ -34,6 +34,20 @@ if [ -z "$drvName" -o -z "$oldVersion" ]; then
die "Couldn't evaluate name and version from '$attr.name'!"
fi

if [ -z "$newVersion" ]; then
# works for fetchFromGitHub & fetchgit
url=$(nix-instantiate --eval --strict --expr "with import ./. {}; if $attr ? src.meta.homepage then $attr.src.meta.homepage else $attr.src.url")
if [[ -z "$url" ]] || ! [[ "$url" =~ \"https://github.com/([^\)]+)/([^\)/]+)\" ]]; then
die "we can only automatically check for new versions for github-based projects, got '$url'"
fi
owner=${BASH_REMATCH[1]}
repo=${BASH_REMATCH[2]%.git}
newVersion=$(curl -s "https://api.github.com/repos/${owner}/${repo}/tags" | jq -r '.[0]?.name | gsub("^v"; "")')
if [[ $newVersion == "" ]]; then
die "no tags found for $url"
fi
fi

if [ "$oldVersion" = "$newVersion" ]; then
echo "$0: New version same as old version, nothing to do." >&2
exit 0
Expand Down

0 comments on commit 9a12f24

Please sign in to comment.