details-check-generate-matrix.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/bash
  2. # Splits the servers to check into shards (one job each) and a list of legacy servers.
  3. # Legacy servers need an older glibc than the hosted runners have, so they run in an ubuntu:20.04 container.
  4. # Writes shards.json (matrix) and legacy.txt (space-separated shortnames).
  5. ref="${LGSM_REF:-${GITHUB_REF#refs/heads/}}"
  6. maxshards="${DETAILS_CHECK_SHARDS:-12}"
  7. legacyservers="bfv bf1942 btl onset"
  8. if [ -f lgsm/data/serverlist.csv ]; then
  9. serverlist="lgsm/data/serverlist.csv"
  10. else
  11. curl -fsS "https://raw.githubusercontent.com/GameServerManagers/LinuxGSM/${ref}/lgsm/data/serverlist.csv" -o serverlist.csv
  12. serverlist="serverlist.csv"
  13. fi
  14. shortnames=()
  15. legacy=()
  16. while IFS=, read -r shortname _; do
  17. [ -z "${shortname}" ] && continue
  18. if [ -n "${TARGETED_SHORTNAMES:-}" ] && ! echo "${TARGETED_SHORTNAMES}" | grep -qw "${shortname}"; then
  19. continue
  20. fi
  21. if echo "${legacyservers}" | grep -qw "${shortname}"; then
  22. legacy+=("${shortname}")
  23. else
  24. shortnames+=("${shortname}")
  25. fi
  26. done < <(tail -n +2 "${serverlist}" | grep -v '^[[:blank:]]*$')
  27. count="${#shortnames[@]}"
  28. shards=$((count < maxshards ? count : maxshards))
  29. declare -a shard
  30. for i in "${!shortnames[@]}"; do
  31. shard[i % shards]+="${shortnames[i]} "
  32. done
  33. {
  34. echo -n '{"include":['
  35. for ((i = 0; i < shards; i++)); do
  36. [ "${i}" -gt 0 ] && echo -n ','
  37. echo -n "{\"shard\":\"$((i + 1))/${shards}\",\"shortnames\":\"${shard[i]% }\"}"
  38. done
  39. echo -n ']}'
  40. } > shards.json
  41. echo -n "${legacy[*]}" > legacy.txt
  42. [ "${serverlist}" == "serverlist.csv" ] && rm serverlist.csv
  43. echo "Servers: ${count} in ${shards} shard(s), legacy: ${legacy[*]:-none}"