Merge pull request #192265 from Milo123459/milo/auto-update-bun

bun: Add auto-updater script
This commit is contained in:
Anderson Torres 2022-09-23 06:53:10 -03:00 committed by GitHub
commit 866431777b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,40 +1,21 @@
{ stdenvNoCC, callPackage, fetchurl, autoPatchelfHook, unzip, openssl, lib }: { lib
let , stdenvNoCC
dists = { , callPackage
aarch64-darwin = { , fetchurl
arch = "aarch64"; , autoPatchelfHook
shortName = "darwin"; , unzip
sha256 = "sha256-R17Ga4C6PSxfL1bz6IBjx0dYFmX93i0y8uqxG1eZKd4="; , openssl
}; , writeShellScript
, curl
, jq
, common-updater-scripts
}:
aarch64-linux = {
arch = "aarch64";
shortName = "linux";
sha256 = "sha256-KSC4gdsJZJoPjMEs+VigVuqlUDhg4sL054WRlAbB+eA=";
};
x86_64-darwin = {
arch = "x64";
shortName = "darwin";
sha256 = "sha256-CVqFPvZScNTudE2wgUctwGDgTyaMeN8dUNmLatcKo5M=";
};
x86_64-linux = {
arch = "x64";
shortName = "linux";
sha256 = "sha256-N3hGPyp9wvb7jjpaFLJcdNIRyLvegjAe+MiV2aMS1nE=";
};
};
dist = dists.${stdenvNoCC.hostPlatform.system} or (throw "Unsupported system: ${stdenvNoCC.hostPlatform.system}");
in
stdenvNoCC.mkDerivation rec { stdenvNoCC.mkDerivation rec {
version = "0.1.11"; version = "0.1.13";
pname = "bun"; pname = "bun";
src = fetchurl { src = passthru.sources.${stdenvNoCC.hostPlatform.system} or (throw "Unsupported system: ${stdenvNoCC.hostPlatform.system}");
url = "https://github.com/Jarred-Sumner/bun-releases-for-updater/releases/download/bun-v${version}/bun-${dist.shortName}-${dist.arch}.zip";
sha256 = dist.sha256;
};
strictDeps = true; strictDeps = true;
nativeBuildInputs = [ unzip ] ++ lib.optionals stdenvNoCC.isLinux [ autoPatchelfHook ]; nativeBuildInputs = [ unzip ] ++ lib.optionals stdenvNoCC.isLinux [ autoPatchelfHook ];
@ -48,7 +29,39 @@ stdenvNoCC.mkDerivation rec {
install -Dm 755 ./bun $out/bin/bun install -Dm 755 ./bun $out/bin/bun
runHook postInstall runHook postInstall
''; '';
passthru = {
sources = {
"aarch64-darwin" = fetchurl {
url = "https://github.com/oven-sh/bun/releases/download/bun-v${version}/bun-darwin-aarch64.zip";
sha256 = "RYTRcc8xccRmxuKOXwX3bBWJSXLI2/XfH4/7ZdcUBdE=";
};
"aarch64-linux" = fetchurl {
url = "https://github.com/oven-sh/bun/releases/download/bun-v${version}/bun-linux-aarch64.zip";
sha256 = "LixLrzSsgbXyfpFKiksM4zNS5iDU3tXOrr7fP8yJknM=";
};
"x86_64-darwin" = fetchurl {
url = "https://github.com/oven-sh/bun/releases/download/bun-v${version}/bun-darwin-x64.zip";
sha256 = "SGZcT2uVy6egr99FzyaykUWLuZBqDsvbCM/lsgy//g0=";
};
"x86_64-linux" = fetchurl {
url = "https://github.com/oven-sh/bun/releases/download/bun-v${version}/bun-linux-x64.zip";
sha256 = "ssZtJi+CEVn7MjPMqFkwv1lnwE7a7ttkmiuoT0Y6wao=";
};
};
updateScript = writeShellScript "update-bun" ''
set -o errexit
export PATH="${lib.makeBinPath [ curl jq common-updater-scripts ]}"
NEW_VERSION=$(curl --silent https://api.github.com/repos/oven-sh/bun/releases/latest | jq '.tag_name | ltrimstr("bun-v")' --raw-output)
if [[ "${version}" = "$NEW_VERSION" ]]; then
echo "The new version same as the old version."
exit 0
fi
for platform in ${lib.escapeShellArgs meta.platforms}; do
update-source-version "bun" "0" "${lib.fakeSha256}" --source-key="sources.$platform"
update-source-version "bun" "$NEW_VERSION" --source-key="sources.$platform"
done
'';
};
meta = with lib; { meta = with lib; {
homepage = "https://bun.sh"; homepage = "https://bun.sh";
changelog = "https://github.com/Jarred-Sumner/bun/releases/tag/bun-v${version}"; changelog = "https://github.com/Jarred-Sumner/bun/releases/tag/bun-v${version}";
@ -62,6 +75,6 @@ stdenvNoCC.mkDerivation rec {
lgpl21Only # javascriptcore and webkit lgpl21Only # javascriptcore and webkit
]; ];
maintainers = with maintainers; [ DAlperin jk ]; maintainers = with maintainers; [ DAlperin jk ];
platforms = builtins.attrNames dists; platforms = builtins.attrNames passthru.sources;
}; };
} }