Unverified Commit 0d0b65d0 authored by Arne Keller's avatar Arne Keller Committed by GitHub
Browse files

copywrite: add `passthru.updateScript`, 0.19.0 -> 0.21.0 (#377649)

parents a8ea00c0 59c8fdeb
Loading
Loading
Loading
Loading
+21 −4
Original line number Diff line number Diff line
@@ -5,24 +5,25 @@
  fetchFromGitHub,
  installShellFiles,
  versionCheckHook,
  writeScript,
}:

let
  commitHash = "6ed520a710166c6094098b786c63f212604654a4"; # matches tag release
  commitHash = "9d021bf61a094a5eac6ae3084ceed2dda4700a73"; # matches tag release
  shortCommitHash = builtins.substring 0 7 commitHash;
in
buildGoModule rec {
  pname = "copywrite";
  version = "0.19.0";
  version = "0.21.0";

  src = fetchFromGitHub {
    owner = "hashicorp";
    repo = "copywrite";
    tag = "v${version}";
    hash = "sha256-DmlPioaw/wMk8GoBYNG24P4J1C6h0bjVjjOuMYW6Tgo=";
    hash = "sha256-TGis7rreRen+vk3tUDehRkyas4xrBBxKlA70+VqoGWY=";
  };

  vendorHash = "sha256-ZIu0/fue3xi+YVE9GFsVjCNs8t3c3TWH8O0xUzJdim8=";
  vendorHash = "sha256-Qxp6BwN/Y6Xb1BwFGT/T8WYsXGPgN27mzoTE0i6cS1Q=";

  ldflags = [
    "-s"
@@ -44,6 +45,22 @@ buildGoModule rec {
  nativeInstallCheckInputs = [ versionCheckHook ];
  doInstallCheck = true;

  passthru.updateScript = writeScript "update-copywrite" ''
    #!/usr/bin/env nix-shell
    #!nix-shell -i bash -p curl jq nix-update

    set -eu -o pipefail

    gh_metadata="$(curl -sS https://api.github.com/repos/hashicorp/copywrite/tags)"
    version="$(echo "$gh_metadata" | jq -r '.[] | .name' | sort --version-sort | tail -1)"
    commit_hash="$(echo "$gh_metadata" | jq -r --arg ver "$version" '.[] | select(.name == $ver).commit.sha')"

    filename="$(nix-instantiate --eval -E "with import ./. {}; (builtins.unsafeGetAttrPos \"version\" copywrite).file" | tr -d '"')"
    sed -i "s/commitHash = \"[^\"]*\"/commitHash = \"$commit_hash\"/" $filename

    nix-update copywrite
  '';

  meta = {
    description = "Automate copyright headers and license files at scale";
    mainProgram = "copywrite";