Unverified Commit dc1bc7ac authored by Sandro Jäckel's avatar Sandro Jäckel Committed by GitHub
Browse files

Merge pull request #273307 from katexochen/sonobuoy/refactor

sonobuoy: update metadata, add update script and version test
parents 3f5f020d c461d39b
Loading
Loading
Loading
Loading
+15 −6
Original line number Diff line number Diff line
{ lib, buildGoModule, fetchFromGitHub }:
{ lib, buildGoModule, fetchFromGitHub, testers, sonobuoy }:

# SHA of ${version} for the tool's help output. Unfortunately this is needed in build flags.
let rev = "6f9e27f1795f10475c9f6f5decdff692e1e228da";
# The update script can update this automatically, the comment is used to find the line.
let rev = "6f9e27f1795f10475c9f6f5decdff692e1e228da"; # update-commit-sha
in
buildGoModule rec {
  pname = "sonobuoy";
@@ -27,11 +28,17 @@ buildGoModule rec {

  subPackages = [ "." ];

  passthru = {
    updateScript = ./update.sh;
    tests.version = testers.testVersion {
      package = sonobuoy;
      command = "sonobuoy version";
      version = "v${version}";
    };
  };

  meta = with lib; {
    description = ''
      Diagnostic tool that makes it easier to understand the
      state of a Kubernetes cluster.
    '';
    description = "Diagnostic tool that makes it easier to understand the state of a Kubernetes cluster";
    longDescription = ''
      Sonobuoy is a diagnostic tool that makes it easier to understand the state of
      a Kubernetes cluster by running a set of Kubernetes conformance tests in an
@@ -39,7 +46,9 @@ buildGoModule rec {
    '';

    homepage = "https://sonobuoy.io";
    changelog = "https://github.com/vmware-tanzu/sonobuoy/releases/tag/v${version}";
    license = licenses.asl20;
    mainProgram = "sonobuoy";
    maintainers = with maintainers; [ carlosdagos saschagrunert wilsonehusin ];
  };
}
+50 −0
Original line number Diff line number Diff line
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p nix-update curl jq gnused

set -euo pipefail

# Do the actual update.
nix-update "${UPDATE_NIX_ATTR_PATH}"

# Get the src metadata.
src=$(
    nix-instantiate --json --eval --strict --expr '
        with import ./. {};
        {
            owner = '"${UPDATE_NIX_ATTR_PATH}"'.src.owner;
            repo = '"${UPDATE_NIX_ATTR_PATH}"'.src.repo;
            tag = '"${UPDATE_NIX_ATTR_PATH}"'.src.rev;
        }'
)
owner=$(jq -r '.owner' <<< "${src}")
repo=$(jq -r '.repo' <<< "${src}")
tag=$(jq -r '.tag' <<< "${src}")

# Curl the release to get the commit sha.
curlFlags=("-fsSL")
curlFlags+=(${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"})

read -r type tag_sha < <(
    curl "${curlFlags[@]}" "https://api.github.com/repos/${owner}/${repo}/git/ref/tags/${tag}" |
    jq -j '.object.type, " ", .object.sha, "\n"'
)

if [[ "${type}" == "commit" ]]; then
    sha="${tag_sha}"
else
    sha=$(
        curl "${curlFlags[@]}" "https://api.github.com/repos/${owner}/${repo}/git/tags/${tag_sha}" |
        jq '.object.sha'
    )
fi

if [[ -z "${sha}" ]]; then
    echo "failed to get commit sha of ${owner}/${repo} @ ${tag}" >&2
    exit 1
fi

echo "updating commit hash of ${owner}/${repo} @ ${tag} to ${sha}" >&2

cd "$(dirname "$(readlink -f "$0")")"

sed -i "s|\".*\"; # update-commit-sha|${sha}; # update-commit-sha|" default.nix