openra: add updateScript

A generic updateScript that can support any openra release paths
This commit is contained in:
mdarocha 2025-03-31 07:39:09 +02:00
parent cd3f12cbec
commit 0233a69802
5 changed files with 139 additions and 21 deletions

View File

@ -7,28 +7,34 @@
freetype,
openal,
lua51Packages,
openRaUpdater
}:
engine:
buildDotnetModule rec {
let
pname = "openra-${engine.build}";
inherit (engine) version;
src =
if engine ? src then
engine.src
else
fetchFromGitHub {
owner = "OpenRA";
repo = "OpenRA";
rev = "${engine.build}-${engine.version}";
sha256 = engine.sha256;
};
nugetDeps = engine.deps;
version = engine.version;
dotnet-sdk = dotnetCorePackages.sdk_6_0-bin;
dotnet-runtime = dotnetCorePackages.runtime_6_0-bin;
in
buildDotnetModule {
inherit pname version dotnet-sdk dotnet-runtime;
src = fetchFromGitHub {
owner = "OpenRA";
repo = "OpenRA";
rev = "${engine.build}-${engine.version}";
inherit (engine) hash;
};
passthru = {
updateScript = {
command = openRaUpdater engine;
supportedFeatures = [ "commit" ];
};
};
nugetDeps = engine.deps;
useAppHost = false;
@ -84,11 +90,11 @@ buildDotnetModule rec {
done
'';
meta = with lib; {
meta = {
description = "Open Source real-time strategy game engine for early Westwood games such as Command & Conquer: Red Alert. ${engine.build} version";
homepage = "https://www.openra.net/";
license = licenses.gpl3;
maintainers = with maintainers; [ mdarocha ];
license = lib.licenses.gpl3;
maintainers = [ lib.maintainers.mdarocha ];
platforms = [ "x86_64-linux" ];
mainProgram = "openra-ra";
};

View File

@ -1,7 +1,8 @@
{ callPackage }:
let
buildOpenRAEngine = callPackage ./build-engine.nix { };
openRaUpdater = callPackage ./updater.nix { };
buildOpenRAEngine = callPackage ./build-engine.nix { inherit openRaUpdater; };
callPackage' = path: callPackage path { inherit buildOpenRAEngine; };
in
{

View File

@ -3,6 +3,6 @@
buildOpenRAEngine {
build = "release";
version = "20231010";
sha256 = "sha256-klJkRoDLTcU7j2iwo4yT9CaKy8QXWDkYw7ApkopSDNM=";
hash = "sha256-klJkRoDLTcU7j2iwo4yT9CaKy8QXWDkYw7ApkopSDNM=";
deps = ./deps.json;
}

View File

@ -0,0 +1,36 @@
{
lib,
writeShellApplication,
curl,
jq,
gnused,
nix,
nix-prefetch-github,
common-updater-scripts,
}:
engine:
lib.getExe (writeShellApplication {
name = "openra-updater";
runtimeInputs = [
curl
jq
gnused
nix
nix-prefetch-github
common-updater-scripts
];
runtimeEnv = {
build = engine.build;
currentVersion = engine.version;
currentRev = lib.optionalString (lib.hasAttr "rev" engine) engine.rev;
};
bashOptions = [
"errexit"
"errtrace"
"nounset"
"pipefail"
];
text = lib.readFile ./updater.sh;
})

View File

@ -0,0 +1,75 @@
if [[ -z "${UPDATE_NIX_ATTR_PATH:-}" ]]; then
echo "Missing UPDATE_NIX_ATTR_PATH - make sure you use mainters/scripts/update.nix to run this script!" 1>&2
exit 1
fi
attrPath="$UPDATE_NIX_ATTR_PATH"
nixFilePath="$(pwd)/pkgs/games/openra/engines/$build/default.nix"
if [[ ! -f "$nixFilePath" ]]; then
echo "$nixFilePath does not exist!" 1>&2
exit 1
fi
depsFilePath="$(pwd)/pkgs/games/openra/engines/$build/deps.json"
if [[ ! -f "$depsFilePath" ]]; then
echo "$depsFilePath does not exist!" 1>&2
exit 1
fi
# if on bleed, update to the latest commit from the bleed branch
# otherwise, check Github releases for releases with a matching prefix
declare newVersion
declare newHash
if [[ "$build" == "bleed" ]]; then
prefetchResult=$(nix-prefetch-github OpenRA OpenRA --json --rev "$build")
newRev=$(echo "$prefetchResult" | jq -e -r '.rev')
if [[ "$currentRev" == "$newRev" ]]; then
echo "Already up to date!" 1>&2
echo "[]"
exit 0
fi
# update rev
sed -i -E 's#(rev = ").*(";)#\1'"$newRev"'\2#' "$nixFilePath"
# get new version based on commit date from github
newVersion=$(curl -s "https://api.github.com/repos/OpenRA/OpenRA/commits/$newRev" |\
jq -r '.commit.committer.date' |\
xargs -I{} date -d {} +%Y%m%d)
newHash=$(echo "$prefetchResult" | jq -e -r '.hash')
else
newVersion=$(curl -s "https://api.github.com/repos/OpenRA/OpenRA/releases" |\
jq -r --arg prefix "$build" \
'first(.[] | select(.tag_name | startswith($prefix)) | .tag_name) | split("-")[1]')
if [[ "$currentVersion" == "$newVersion" ]]; then
echo "Already up to date!" 1>&2
echo "[]"
exit 0
fi
newHash=$(nix-prefetch-github OpenRA OpenRA --json --rev "$build-$newVersion" | jq -r '.hash')
fi
# update version
sed -i -E 's#(version = ").*(";)#\1'"$newVersion"'\2#' "$nixFilePath"
# update hash
sed -i -E 's#(hash = ").*(";)#\1'"$newHash"'\2#' "$nixFilePath"
# update deps.json by running the fetch-deps script
# shellcheck disable=SC2091
$(nix-build -A "$attrPath".fetch-deps --no-out-link) 1>&2
# echo commit info, according to what maintainers/scripts/update.nix needs
cat <<-EOF
[{
"attrPath": "$attrPath",
"oldVersion": "$currentVersion",
"newVersion": "$newVersion",
"files": ["$nixFilePath", "$depsFilePath"]
}]
EOF