Unverified Commit 4e9d2c30 authored by Sebastián Mancilla's avatar Sebastián Mancilla Committed by GitHub
Browse files

tektoncd-cli: general maintenance (#445561)

parents 2f691955 86809512
Loading
Loading
Loading
Loading
+46 −24
Original line number Diff line number Diff line
@@ -3,16 +3,23 @@
  buildGoModule,
  fetchFromGitHub,
  installShellFiles,

  writableTmpDirAsHomeHook,

  stdenv,
  buildPackages,

  versionCheckHook,
}:

buildGoModule rec {
buildGoModule (finalAttrs: {
  pname = "tektoncd-cli";
  version = "0.42.0";

  src = fetchFromGitHub {
    owner = "tektoncd";
    repo = "cli";
    rev = "v${version}";
    tag = "v${finalAttrs.version}";
    sha256 = "sha256-WB3XsXT8bXo2GpHC6hGKilRwloy31y18JD09cQklsV0=";
  };

@@ -21,47 +28,62 @@ buildGoModule rec {
  ldflags = [
    "-s"
    "-w"
    "-X github.com/tektoncd/cli/pkg/cmd/version.clientVersion=${version}"
    "-X github.com/tektoncd/cli/pkg/cmd/version.clientVersion=${finalAttrs.version}"
  ];

  # tests bind to ::1
  __darwinAllowLocalNetworking = true;

  nativeBuildInputs = [ installShellFiles ];

  subPackages = [ "cmd/tkn" ];
  subPackages = [
    "cmd/tkn"
  ];

  preCheck = ''
    # some tests try to write to the home dir
    export HOME="$TMPDIR"
  excludedPackages = [
    "test/e2e"
  ];

  nativeCheckInputs = [
    writableTmpDirAsHomeHook
  ];

  preCheck = ''
    # run all tests
    unset subPackages

    # the tests expect the clientVersion ldflag not to be set
    unset ldflags

    # remove tests with networking
    rm pkg/cmd/version/version_test.go
  '';

  postInstall = ''
    installManPage docs/man/man1/*
  ''
  + (
    let
      exe =
        if stdenv.buildPlatform.canExecute stdenv.hostPlatform then
          "${placeholder "out"}/bin/${finalAttrs.meta.mainProgram}"
        else
          lib.getExe buildPackages.tektoncd-cli;
    in
    ''
      installShellCompletion --cmd ${finalAttrs.meta.mainProgram} \
        --bash <(${exe} completion bash) \
        --fish <(${exe} completion fish) \
        --zsh <(${exe} completion zsh)
    ''
  );

    installShellCompletion --cmd tkn \
      --bash <($out/bin/tkn completion bash) \
      --fish <($out/bin/tkn completion fish) \
      --zsh <($out/bin/tkn completion zsh)
  '';

  nativeInstallCheckInputs = [
    versionCheckHook
  ];
  doInstallCheck = true;
  installCheckPhase = ''
    runHook preInstallCheck
    $out/bin/tkn --help
    $out/bin/tkn version | grep "Client version: ${version}"
    runHook postInstallCheck
  '';
  versionCheckProgramArg = "version";

  meta = {
    homepage = "https://tekton.dev";
    changelog = "https://github.com/tektoncd/cli/releases/tag/v${version}";
    changelog = "https://github.com/tektoncd/cli/releases/tag/${finalAttrs.src.tag}";
    description = "Provides a CLI for interacting with Tekton - tkn";
    longDescription = ''
      The Tekton Pipelines cli project provides a CLI for interacting with
@@ -77,4 +99,4 @@ buildGoModule rec {
    ];
    mainProgram = "tkn";
  };
}
})