This repository has no description
0

Configure Feed

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

superconfig / pkgs / kokoro / update.sh
3.7 kB 93 lines
1#!/usr/bin/env bash 2set -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. 8attr=kokoro 9owner=hexgrad 10repo=kokoro 11branch=main 12 13# Run by update-pkgs from the flake root ($0 is a read-only store copy). 14pkg=pkgs/kokoro/package.nix 15system=$(nix eval --raw --impure --expr 'builtins.currentSystem') 16build_attr=".#packages.$system.$attr" 17 18# Line number of the n-th line matching an ERE. 19line_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. 23set_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} 30value_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. 35kokoro_version_line=$(line_of '^[[:space:]]*version = "0-unstable-') 36kokoro_rev_line=$(line_of '^[[:space:]]*rev = "') 37kokoro_hash_line=$(line_of '^[[:space:]]*hash = "' 1) 38model_version_line=$(line_of '^[[:space:]]*version = "[0-9]+\.[0-9]+\.[0-9]+"') 39model_hash_line=$(line_of '^[[:space:]]*hash = "' 2) 40 41old_rev=$(value_at "$kokoro_rev_line") 42old_model=$(value_at "$model_version_line") 43 44new_rev=$(curl -fsSL "https://api.github.com/repos/$owner/$repo/commits/$branch" | jq -r .sha) 45 46spacy_version=$(nix eval --raw "$build_attr.pythonModule.pkgs.spacy.version") 47spacy_mm=$(echo "$spacy_version" | cut -d. -f1-2) 48new_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') 53if [ -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 56fi 57 58if [ "$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 61fi 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. 65if [ "$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" "" 70fi 71if [ "$old_model" != "$new_model" ]; then 72 set_value "$model_version_line" "$new_model" 73 set_value "$model_hash_line" "" 74fi 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. 79for _ 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 90done 91 92echo "$attr: updated to $new_rev, en_core_web_sm $new_model" 93nix build --no-link "$build_attr"