yamlfmt: correct commit reference in version flag and add versionCheckHook (#430598)

This commit is contained in:
Aleksana
2025-08-03 20:18:32 +08:00
committed by GitHub
+16 -7
View File
@@ -2,8 +2,7 @@
lib,
buildGoModule,
fetchFromGitHub,
testers,
yamlfmt,
versionCheckHook,
}:
buildGoModule (finalAttrs: {
@@ -14,7 +13,12 @@ buildGoModule (finalAttrs: {
owner = "google";
repo = "yamlfmt";
tag = "v${finalAttrs.version}";
hash = "sha256-EYOtxb2Xq4bQpWbITmPieVMqJz3/2chgNirZEjiyjAY=";
hash = "sha256-WSw4WhWNyvkCwRCQYFAKhtkvOSSCrSlX3+i6cMHRtOQ=";
leaveDotGit = true;
postFetch = ''
git -C "$out" rev-parse --short HEAD > "$out/.git_head"
rm -rf "$out/.git"
'';
};
vendorHash = "sha256-Cy1eBvKkQ90twxjRL2bHTk1qNFLQ22uFrOgHKmnoUIQ=";
@@ -23,16 +27,21 @@ buildGoModule (finalAttrs: {
"-s"
"-w"
"-X=main.version=${finalAttrs.version}"
"-X=main.commit=${finalAttrs.src.rev}"
];
preBuild = ''
ldflags+=" -X=main.commit=$(<.git_head)"
'';
# Test failure in vendored yaml package, see:
# https://github.com/google/yamlfmt/issues/256
checkFlags = [ "-run=!S/TestNodeRoundtrip" ];
passthru.tests.version = testers.testVersion {
package = yamlfmt;
};
nativeInstallCheckInputs = [
versionCheckHook
];
doInstallCheck = true;
versionCheckProgramArg = "--version";
meta = {
description = "Extensible command line tool or library to format yaml files";