diff --git a/pkgs/development/tools/gauge/plugins/default.nix b/pkgs/development/tools/gauge/plugins/default.nix index 92ee2fca77d0..b68d48ba4767 100644 --- a/pkgs/development/tools/gauge/plugins/default.nix +++ b/pkgs/development/tools/gauge/plugins/default.nix @@ -3,6 +3,7 @@ lib.makeScope pkgs.newScope (final: let inherit (final) callPackage; in { makeGaugePlugin = callPackage ./make-gauge-plugin.nix { }; + testGaugePlugins = callPackage ./test-gauge-plugins.nix { }; dotnet = callPackage ./dotnet { }; html-report = callPackage ./html-report { }; java = callPackage ./java { }; diff --git a/pkgs/development/tools/gauge/plugins/make-gauge-plugin.nix b/pkgs/development/tools/gauge/plugins/make-gauge-plugin.nix index b9a4b1441632..f88a236d7068 100644 --- a/pkgs/development/tools/gauge/plugins/make-gauge-plugin.nix +++ b/pkgs/development/tools/gauge/plugins/make-gauge-plugin.nix @@ -3,6 +3,7 @@ , lib , writeScript , autoPatchelfHook +, testGaugePlugins }: { pname @@ -41,57 +42,60 @@ stdenvNoCC.mkDerivation (finalAttrs: (lib.recursiveUpdate { cp -r . "$out/share/gauge-plugins/${pname}/${finalAttrs.version}" ''; - passthru.updateScript = writeScript "update-${finalAttrs.pname}" '' - #!/usr/bin/env nix-shell - #!nix-shell -i bash -p curl nix-prefetch yq-go + passthru = { + tests.loadPlugin = testGaugePlugins { plugins = [ finalAttrs.finalPackage ]; }; + updateScript = writeScript "update-${finalAttrs.pname}" '' + #!/usr/bin/env nix-shell + #!nix-shell -i bash -p curl nix-prefetch yq-go - set -e + set -e - dirname="pkgs/development/tools/gauge/plugins/${pname}" + dirname="pkgs/development/tools/gauge/plugins/${pname}" - currentVersion=$(nix eval --raw -f default.nix gaugePlugins.${pname}.version) + currentVersion=$(nix eval --raw -f default.nix gaugePlugins.${pname}.version) - latestTag=$(curl -s ''${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} https://api.github.com/repos/${repo}/releases/latest | yq ".tag_name") - latestVersion="$(expr $latestTag : 'v\(.*\)')" + latestTag=$(curl -s ''${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} https://api.github.com/repos/${repo}/releases/latest | yq ".tag_name") + latestVersion="$(expr $latestTag : 'v\(.*\)')" - tempfile=$(mktemp) + tempfile=$(mktemp) - if [[ "$FORCE_UPDATE" != "true" && "$currentVersion" == "$latestVersion" ]]; then - echo "gauge-${pname} is up-to-date: ''${currentVersion}" - exit 0 - fi + if [[ "$FORCE_UPDATE" != "true" && "$currentVersion" == "$latestVersion" ]]; then + echo "gauge-${pname} is up-to-date: ''${currentVersion}" + exit 0 + fi - yq -iPoj "{ \"version\": \"$latestVersion\" }" "$tempfile" + yq -iPoj "{ \"version\": \"$latestVersion\" }" "$tempfile" - updateSystem() { - system=$1 - url=$2 + updateSystem() { + system=$1 + url=$2 - echo "Fetching hash for $system" - hash=$(nix-prefetch-url --type sha256 $url --unpack) - sriHash="$(nix hash to-sri --type sha256 $hash)" + echo "Fetching hash for $system" + hash=$(nix-prefetch-url --type sha256 $url --unpack) + sriHash="$(nix hash to-sri --type sha256 $hash)" - yq -iPoj ". + { \"$system\": { \"url\": \"$url\", \"hash\": \"$sriHash\" } }" "$tempfile" - } + yq -iPoj ". + { \"$system\": { \"url\": \"$url\", \"hash\": \"$sriHash\" } }" "$tempfile" + } - updateSingle() { - url=$1 + updateSingle() { + url=$1 - echo "Fetching hash" - hash=$(nix-prefetch-url --type sha256 $url --unpack) - sriHash="$(nix hash to-sri --type sha256 $hash)" + echo "Fetching hash" + hash=$(nix-prefetch-url --type sha256 $url --unpack) + sriHash="$(nix hash to-sri --type sha256 $hash)" - yq -iPoj ". + { \"url\": \"$url\", \"hash\": \"$sriHash\" }" "$tempfile" - } + yq -iPoj ". + { \"url\": \"$url\", \"hash\": \"$sriHash\" }" "$tempfile" + } - baseUrl="https://github.com/${repo}/releases/download/$latestTag/${releasePrefix}$latestVersion" + baseUrl="https://github.com/${repo}/releases/download/$latestTag/${releasePrefix}$latestVersion" - ${if isCrossArch then - "updateSingle \${baseUrl}.zip" - else - lib.concatStringsSep "\n" (map (platform: ''updateSystem "${platform}" "''${baseUrl}-${systemMap.${platform}}.zip"'') meta.platforms) - } + ${if isCrossArch then + "updateSingle \${baseUrl}.zip" + else + lib.concatStringsSep "\n" (map (platform: ''updateSystem "${platform}" "''${baseUrl}-${systemMap.${platform}}.zip"'') meta.platforms) + } - mv "$tempfile" "$dirname/data.json" - ''; + mv "$tempfile" "$dirname/data.json" + ''; + }; } otherArgs)) diff --git a/pkgs/development/tools/gauge/plugins/test-gauge-plugins.nix b/pkgs/development/tools/gauge/plugins/test-gauge-plugins.nix new file mode 100644 index 000000000000..3648e87f7b91 --- /dev/null +++ b/pkgs/development/tools/gauge/plugins/test-gauge-plugins.nix @@ -0,0 +1,35 @@ +{ + runCommand, + gauge, + lib, +}: + +/** + Creates a gauge install with all given plugins and makes sure every plugin is loaded. +*/ +{ plugins }: + +let + gaugeWithPlugins = gauge.withPlugins (_: plugins); +in + +runCommand "gauge-test" { nativeBuildInputs = [ gaugeWithPlugins ]; } '' + mkdir $out + echo $(gauge install || true) > $out/output.txt + + function checkPlugin() { + plugin="$1" + version="$2" + + echo Checking for plugin $plugin version $version + if ! grep "$plugin ($version)" $out/output.txt + then + echo "Couldn't find plugin $plugin version $version" + exit 1 + fi + } + + ${lib.concatMapStringsSep "\n" ( + p: "checkPlugin '${lib.removePrefix "gauge-plugin-" p.pname}' '${p.version}'" + ) plugins} +'' diff --git a/pkgs/development/tools/gauge/wrapper.nix b/pkgs/development/tools/gauge/wrapper.nix index 67b1a8ddc52b..8f4ceca25e9e 100644 --- a/pkgs/development/tools/gauge/wrapper.nix +++ b/pkgs/development/tools/gauge/wrapper.nix @@ -6,6 +6,7 @@ , xorg , gaugePlugins , plugins ? [] +, runCommand }: stdenvNoCC.mkDerivation { @@ -53,6 +54,8 @@ stdenvNoCC.mkDerivation { requiredPlugins = with manifest; [ Language ] ++ Plugins; manifestPlugins = plugins: map (name: plugins.${name} or (throw "Gauge plugin ${name} is not available!")) requiredPlugins; in gauge.withPlugins manifestPlugins; + # Builds gauge with all plugins and checks for successful installation + tests.allPlugins = gaugePlugins.testGaugePlugins { plugins = lib.filter lib.isDerivation (lib.attrValues gaugePlugins); }; }; inherit (gauge-unwrapped) meta;