#!/usr/bin/env bash # Fetch `.mul` files other people wrote, which is the only corpus that says # whether this repository's reader survives contact with the format as it is # actually used. # # ./scripts/fetch-mul-corpus.sh # ./scripts/fetch-mul-corpus.sh /somewhere/else # # Prints the corpus path on stdout, so it composes: # # HELM_MUL_CORPUS="$(./scripts/fetch-mul-corpus.sh)" \ # cargo test -p helm-unitfile --test corpus -- --ignored --nocapture # # A MegaMek install ships 28 `.mul` files and they are all MegaMek's own, # written by one writer for one purpose. These are forces people saved: some # from MegaMek, some from MekHQ, some from tools that are neither, over # several years of the format. That is the population a file arriving from a # player is drawn from. # # Nothing fetched here is committed and nothing is redistributed, the same # posture this repository takes to a MegaMek install. The repositories below # are public and pinned by commit, and their licences are their own - one is # GPL-2.0, two say nothing at all - which is a reason to read them and not a # reason to ship them. # # A repository that moves does not change what is tested: the pin is the # corpus. Repointing one is a commit, so a figure that moves has something # that says why. # # One writer is not fetchable and has to be generated: MekBay, MegaMek's own # web client, writes `.mul` files that exist nowhere in public code. Generate # some into `/mekbay-generated/` by driving https://mekbay.com in a # browser - Force Generator, REROLL, CREATE, then Share Force and the MUL # button - capturing what the page hands to the download. It writes a `` # element where MegaMek writes ``, and finding that took eight files. set -euo pipefail # owner/repo commit REPOS=( "MegaMek/mm-data 5e630eab38ce3dbfb032343fa9504d94043c2d67" "nx78/shackclient 557953c0b727059c1c8ca60d3fa8e724d00f9299" "mothmind/clusterstrike-crew-game df96e911b382ebc52f279ebb858fd105ac492305" "Eudicods/let-the-bots-fight ef4ee58a86df72c6af1b3b7f99d94dd6887fdc96" "maldun/UltraMekCore 8d4d8484311e1552eeb929fcdef1e061be544943" ) out="${1:-$HOME/.cache/helm/mul-corpus}" mkdir -p "$out" work="$(mktemp -d)" trap 'rm -rf "$work"' EXIT for entry in "${REPOS[@]}"; do read -r repo sha <<<"$entry" slug="${repo//\//-}" dest="$out/$slug" # A pin that is already unpacked is the same bytes it was: nothing to do. if [[ -f "$dest/.commit" ]] && [[ "$(cat "$dest/.commit")" == "$sha" ]]; then echo "have $repo@${sha:0:8}" >&2 continue fi echo "fetching $repo@${sha:0:8}" >&2 tarball="$work/$slug.tar.gz" curl -fsSL "https://codeload.github.com/$repo/tar.gz/$sha" -o "$tarball" rm -rf "$dest" mkdir -p "$dest" # Only the `.mul` files, and flattened: a name that keeps its path is a name # a failing test can be traced back to the file it came from. unpacked="$work/$slug" mkdir -p "$unpacked" tar -xzf "$tarball" -C "$unpacked" --strip-components=1 --wildcards '*.mul' 2>/dev/null || true found=0 while IFS= read -r -d '' file; do rel="${file#"$unpacked"/}" cp "$file" "$dest/${rel//\//_}" found=$((found + 1)) done < <(find "$unpacked" -name '*.mul' -print0) echo "$sha" >"$dest/.commit" echo " $found files" >&2 done echo "$out"