This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

pkgs.kokoro: add updateScript

+97
+4
pkgs/kokoro/package.nix
··· 20 20 patches = (old.patches or [ ]) ++ [ 21 21 ./stdout-support.patch 22 22 ]; 23 + passthru = (old.passthru or { }) // { 24 + # Bumps kokoro (main branch) and the spacy model wheel together. 25 + updateScript = ./update.sh; 26 + }; 23 27 }); 24 28 # Spacy model - downloaded and packaged as a python package 25 29 spacy-en-core-web-sm = final.buildPythonPackage rec {
+93
pkgs/kokoro/update.sh
··· 1 + #!/usr/bin/env bash 2 + set -euo pipefail 3 + 4 + # Bumps two sources together: hexgrad/kokoro (main branch, 0-unstable-DATE) 5 + # and the en_core_web_sm wheel misaki needs. The spacy model only loads with a 6 + # matching spacy major.minor, so it follows the newest model release for the 7 + # spacy version in our nixpkgs. 8 + attr=kokoro 9 + owner=hexgrad 10 + repo=kokoro 11 + branch=main 12 + 13 + # Run by update-pkgs from the flake root ($0 is a read-only store copy). 14 + pkg=pkgs/kokoro/package.nix 15 + system=$(nix eval --raw --impure --expr 'builtins.currentSystem') 16 + build_attr=".#packages.$system.$attr" 17 + 18 + # Line number of the n-th line matching an ERE. 19 + line_of() { 20 + grep -nE "$1" "$pkg" | awk -F: -v n="${2:-1}" 'NR == n { print $1 }' 21 + } 22 + # Replace the quoted value on line $1. 23 + set_value() { 24 + local tmp 25 + tmp=$(mktemp) 26 + awk -v l="$1" -v v="$2" 'NR == l { sub(/"[^"]*"/, "\"" v "\"") } { print }' "$pkg" >"$tmp" 27 + cat "$tmp" >"$pkg" 28 + rm -f "$tmp" 29 + } 30 + value_at() { 31 + awk -v l="$1" 'NR == l { match($0, /"[^"]*"/); print substr($0, RSTART + 1, RLENGTH - 2) }' "$pkg" 32 + } 33 + 34 + # Field locations: kokoro block first, spacy model block second. 35 + kokoro_version_line=$(line_of '^[[:space:]]*version = "0-unstable-') 36 + kokoro_rev_line=$(line_of '^[[:space:]]*rev = "') 37 + kokoro_hash_line=$(line_of '^[[:space:]]*hash = "' 1) 38 + model_version_line=$(line_of '^[[:space:]]*version = "[0-9]+\.[0-9]+\.[0-9]+"') 39 + model_hash_line=$(line_of '^[[:space:]]*hash = "' 2) 40 + 41 + old_rev=$(value_at "$kokoro_rev_line") 42 + old_model=$(value_at "$model_version_line") 43 + 44 + new_rev=$(curl -fsSL "https://api.github.com/repos/$owner/$repo/commits/$branch" | jq -r .sha) 45 + 46 + spacy_version=$(nix eval --raw "$build_attr.pythonModule.pkgs.spacy.version") 47 + spacy_mm=$(echo "$spacy_version" | cut -d. -f1-2) 48 + new_model=$(curl -fsSL "https://api.github.com/repos/explosion/spacy-models/releases?per_page=100" | 49 + jq -r --arg p "en_core_web_sm-$spacy_mm." ' 50 + [.[] | select(.prerelease | not) | .tag_name | select(startswith($p)) 51 + | ltrimstr("en_core_web_sm-")] 52 + | sort_by(split(".") | map(tonumber)) | last // empty') 53 + if [ -z "$new_model" ]; then 54 + echo "$attr: no en_core_web_sm release for spacy $spacy_mm, keeping $old_model" >&2 55 + new_model=$old_model 56 + fi 57 + 58 + if [ "$old_rev" = "$new_rev" ] && [ "$old_model" = "$new_model" ]; then 59 + echo "$attr: already up to date ($new_rev, en_core_web_sm $new_model)" 60 + exit 0 61 + fi 62 + 63 + # Blank the hashes of whatever changed: with the old ones in place nix reuses 64 + # the cached FODs and the build "succeeds" on stale sources. 65 + if [ "$old_rev" != "$new_rev" ]; then 66 + new_date=$(curl -fsSL "https://api.github.com/repos/$owner/$repo/commits/$new_rev" | jq -r .commit.committer.date | cut -d T -f1) 67 + set_value "$kokoro_rev_line" "$new_rev" 68 + set_value "$kokoro_version_line" "0-unstable-$new_date" 69 + set_value "$kokoro_hash_line" "" 70 + fi 71 + if [ "$old_model" != "$new_model" ]; then 72 + set_value "$model_version_line" "$new_model" 73 + set_value "$model_hash_line" "" 74 + fi 75 + 76 + # Probe builds are *expected* to fail (hash mismatch); `|| true` keeps 77 + # errexit from aborting. One FOD fails per build; the two fetches are 78 + # independent, so match the reported derivation name to pick the field. 79 + for _ in 1 2; do 80 + out=$({ nix build --no-link "$build_attr" 2>&1 || true; } | tee /dev/stderr) 81 + got=$(echo "$out" | awk '/got:/ && !seen { print $2; seen = 1 }') 82 + [ -n "$got" ] || break 83 + if echo "$out" | grep -q 'hash mismatch in fixed-output derivation.*en_core_web_sm'; then 84 + set_value "$model_hash_line" "$got" 85 + echo "$attr: en_core_web_sm hash → $got" 86 + else 87 + set_value "$kokoro_hash_line" "$got" 88 + echo "$attr: src hash → $got" 89 + fi 90 + done 91 + 92 + echo "$attr: updated to $new_rev, en_core_web_sm $new_model" 93 + nix build --no-link "$build_attr"