Skip to content

Commit bb19ea6

Browse files
committed
lemminx: fix update script
1 parent 341c3b7 commit bb19ea6

File tree

1 file changed

+41
-19
lines changed

1 file changed

+41
-19
lines changed

pkgs/by-name/le/lemminx/package.nix

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
jdk_headless,
66
jre_minimal,
77
maven,
8-
writeScript,
9-
lemminx,
8+
writeShellApplication,
9+
curl,
10+
pcre,
11+
common-updater-scripts,
12+
jq,
13+
gnused,
1014
}:
1115

1216
let
@@ -79,26 +83,44 @@ maven.buildMavenPackage rec {
7983

8084
nativeBuildInputs = [ makeWrapper ];
8185

82-
passthru.updateScript = writeScript "update-lemminx" ''
83-
#!/usr/bin/env nix-shell
84-
#!nix-shell -i bash -p curl pcre common-updater-scripts jq gnused
85-
set -eu -o pipefail
86+
passthru = {
87+
updateScript =
88+
let
89+
pkgFile = builtins.toString ./package.nix;
90+
in
91+
lib.getExe (writeShellApplication {
92+
name = "update-${pname}";
93+
runtimeInputs = [
94+
curl
95+
pcre
96+
common-updater-scripts
97+
jq
98+
gnused
99+
];
100+
text = ''
101+
if [ -z "''${GITHUB_TOKEN:-}" ]; then
102+
echo "no GITHUB_TOKEN provided - you could meet API request limiting" >&2
103+
fi
86104
87-
LATEST_TAG=$(curl https://api.github.com/repos/eclipse/lemminx/tags | \
88-
jq -r '[.[] | select(.name | test("^[0-9]"))] | sort_by(.name | split(".") |
89-
map(tonumber)) | reverse | .[0].name')
90-
update-source-version lemminx "$LATEST_TAG"
91-
sed -i '0,/mvnHash *= *"[^"]*"/{s/mvnHash = "[^"]*"/mvnHash = ""/}' ${lemminx}
105+
LATEST_TAG=$(curl -H "Accept: application/vnd.github+json" \
106+
''${GITHUB_TOKEN:+-H "Authorization: bearer $GITHUB_TOKEN"} \
107+
-Lsf https://api.github.com/repos/${src.owner}/${src.repo}/tags | \
108+
jq -r '[.[] | select(.name | test("^[0-9]"))] | sort_by(.name | split(".") |
109+
map(tonumber)) | reverse | .[0].name')
110+
update-source-version ${pname} "$LATEST_TAG"
111+
sed -i '0,/mvnHash *= *"[^"]*"/{s/mvnHash = "[^"]*"/mvnHash = ""/}' ${pkgFile}
92112
93-
echo -e "\nFetching all mvn dependencies to calculate the mvnHash. This may take a while ..."
94-
nix-build -A lemminx.fetchedMavenDeps 2> lemminx-stderr.log || true
113+
echo -e "\nFetching all mvn dependencies to calculate the mvnHash. This may take a while ..."
114+
nix-build -A ${pname}.fetchedMavenDeps 2> ${pname}-stderr.log || true
95115
96-
NEW_MVN_HASH=$(cat lemminx-stderr.log | grep "got:" | awk '{print ''$2}')
97-
rm lemminx-stderr.log
98-
# escaping double quotes looks ugly but is needed for variable substitution
99-
# use # instead of / as separator because the sha256 might contain the / character
100-
sed -i "0,/mvnHash *= *\"[^\"]*\"/{s#mvnHash = \"[^\"]*\"#mvnHash = \"$NEW_MVN_HASH\"#}" ${lemminx}
101-
'';
116+
NEW_MVN_HASH=$(grep "got:" ${pname}-stderr.log | awk '{print ''$2}')
117+
rm ${pname}-stderr.log
118+
# escaping double quotes looks ugly but is needed for variable substitution
119+
# use # instead of / as separator because the sha256 might contain the / character
120+
sed -i "0,/mvnHash *= *\"[^\"]*\"/{s#mvnHash = \"[^\"]*\"#mvnHash = \"$NEW_MVN_HASH\"#}" ${pkgFile}
121+
'';
122+
});
123+
};
102124

103125
meta = with lib; {
104126
description = "XML Language Server";

0 commit comments

Comments
 (0)