Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 75 lines 2.4 kB view raw
1if [[ -z "${UPDATE_NIX_ATTR_PATH:-}" ]]; then 2 echo "Missing UPDATE_NIX_ATTR_PATH - make sure you use mainters/scripts/update.nix to run this script!" 1>&2 3 exit 1 4fi 5 6attrPath="$UPDATE_NIX_ATTR_PATH" 7 8nixFilePath="$(pwd)/pkgs/games/openra/engines/$build/default.nix" 9if [[ ! -f "$nixFilePath" ]]; then 10 echo "$nixFilePath does not exist!" 1>&2 11 exit 1 12fi 13 14depsFilePath="$(pwd)/pkgs/games/openra/engines/$build/deps.json" 15if [[ ! -f "$depsFilePath" ]]; then 16 echo "$depsFilePath does not exist!" 1>&2 17 exit 1 18fi 19 20# if on bleed, update to the latest commit from the bleed branch 21# otherwise, check Github releases for releases with a matching prefix 22declare newVersion 23declare newHash 24if [[ "$build" == "bleed" ]]; then 25 prefetchResult=$(nix-prefetch-github OpenRA OpenRA --json --rev "$build") 26 27 newRev=$(echo "$prefetchResult" | jq -e -r '.rev') 28 if [[ "$currentRev" == "$newRev" ]]; then 29 echo "Already up to date!" 1>&2 30 echo "[]" 31 exit 0 32 fi 33 34 # update rev 35 sed -i -E 's#(rev = ").*(";)#\1'"$newRev"'\2#' "$nixFilePath" 36 37 # get new version based on commit date from github 38 newVersion=$(curl -s "https://api.github.com/repos/OpenRA/OpenRA/commits/$newRev" |\ 39 jq -r '.commit.committer.date' |\ 40 xargs -I{} date -d {} +%Y%m%d) 41 42 newHash=$(echo "$prefetchResult" | jq -e -r '.hash') 43else 44 newVersion=$(curl -s "https://api.github.com/repos/OpenRA/OpenRA/releases" |\ 45 jq -r --arg prefix "$build" \ 46 'first(.[] | select(.tag_name | startswith($prefix)) | .tag_name) | split("-")[1]') 47 48 if [[ "$currentVersion" == "$newVersion" ]]; then 49 echo "Already up to date!" 1>&2 50 echo "[]" 51 exit 0 52 fi 53 54 newHash=$(nix-prefetch-github OpenRA OpenRA --json --rev "$build-$newVersion" | jq -r '.hash') 55fi 56 57# update version 58sed -i -E 's#(version = ").*(";)#\1'"$newVersion"'\2#' "$nixFilePath" 59 60# update hash 61sed -i -E 's#(hash = ").*(";)#\1'"$newHash"'\2#' "$nixFilePath" 62 63# update deps.json by running the fetch-deps script 64# shellcheck disable=SC2091 65$(nix-build -A "$attrPath".fetch-deps --no-out-link) 1>&2 66 67# echo commit info, according to what maintainers/scripts/update.nix needs 68cat <<-EOF 69[{ 70 "attrPath": "$attrPath", 71 "oldVersion": "$currentVersion", 72 "newVersion": "$newVersion", 73 "files": ["$nixFilePath", "$depsFilePath"] 74}] 75EOF