details-check-run.sh 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #!/bin/bash
  2. # Runs the details check for each shortname given, in one shared LinuxGSM directory.
  3. # Modules, default configs and data come from the checkout, so the code under test is used and nothing is downloaded per server.
  4. # Usage: details-check-run.sh <shortname>...
  5. src="${GITHUB_WORKSPACE:-${PWD}}"
  6. workdir="${DETAILS_CHECK_DIR:-${HOME}/details-check}"
  7. summary="${GITHUB_STEP_SUMMARY:-/dev/null}"
  8. export LGSM_GITHUBBRANCH="${LGSM_REF:?LGSM_REF must be set}"
  9. testservername="LinuxGSM Test = Server: 1, ok"
  10. testpassword="abc123=="
  11. declare -A roundtripallow=(
  12. ["cmwserver:adminpassword"]="AdminPassword in the config is not parsed"
  13. ["codwawserver:adminpassword"]="parser reads rcon_password, stock config sets rconpassword"
  14. ["ecoserver:ports"]="jq prints null when RconServerPort is missing from the stock config"
  15. ["hfserver:config"]="serverconfig_default.txt ships with the game, not Game-Server-Configs"
  16. ["ohdserver:servername"]="ServerName in Game.ini is not parsed"
  17. ["wetserver:adminpassword"]="parser reads zmq_rcon_password, stock config sets rconpassword"
  18. )
  19. rm -rf "${workdir}"
  20. mkdir -p "${workdir}/lgsm" "${workdir}/serverfiles"
  21. cp "${src}/linuxgsm.sh" "${workdir}/"
  22. cp -r "${src}/lgsm/modules" "${src}/lgsm/config-default" "${src}/lgsm/data" "${workdir}/lgsm/"
  23. cd "${workdir}" || exit 1
  24. date '+%s' > .dev-debug
  25. result() {
  26. if [ "${1}" -eq 0 ]; then echo "✅ pass"; else echo "❌ fail"; fi
  27. }
  28. fn_parse_details() {
  29. ./"${gameserver}" parse-game-details > "${1}" 2>&1
  30. local exitcode=$?
  31. cat "${1}"
  32. sed -n '/Available Gameserver Details/,/Missing or unsupported Gameserver Details/p' "${1}" | sed 's/\x1b\[[0-9;]*m//g' > "${1}.values"
  33. return "${exitcode}"
  34. }
  35. fn_detail_value() {
  36. sed -n "s/^${2}: //p" "${1}.values" | head -n 1
  37. }
  38. fn_allowed() {
  39. if [ -n "${roundtripallow[${gameserver}:${1}]}" ]; then
  40. [[ " ${roundtripskipped[*]} " == *" ${1} "* ]] || roundtripskipped+=("${1}")
  41. return 0
  42. fi
  43. return 1
  44. }
  45. fn_check_values() {
  46. local label="${1}" file="${2}" line key value
  47. if grep -q $'\r' "${file}.values" && ! fn_allowed carriagereturn; then
  48. roundtriperrors+=("${label}: carriage return in $(grep $'\r' "${file}.values" | cut -d: -f1 | paste -sd, -)")
  49. fi
  50. fn_allowed ports && return
  51. while IFS= read -r line; do
  52. key="${line%%: *}"
  53. value="${line#*: }"
  54. if [[ ! "${value}" =~ ^[0-9]+$ ]]; then
  55. roundtriperrors+=("${label}: ${key} is not numeric (${value%$'\r'})")
  56. fi
  57. done < <(grep -E '^[^:]*Port[^:]*: ' "${file}.values")
  58. }
  59. fn_roundtrip_check() {
  60. local check="${1}" expected="${2}"
  61. shift 2
  62. local key value
  63. fn_allowed "${check}" && return
  64. for key in "$@"; do
  65. value=$(fn_detail_value parse-test "${key}")
  66. [ "${value}" == "${expected}" ] && return
  67. done
  68. value=$(fn_detail_value parse-test "${1}")
  69. roundtriperrors+=("${check}: expected '${expected}', got '${value%$'\r'}'")
  70. }
  71. failed=()
  72. {
  73. echo "| Server | Config | Details | Parse game details | Query raw | Round trip |"
  74. echo "|--------|--------|---------|--------------------|-----------|------------|"
  75. } >> "${summary}"
  76. for shortname in "$@"; do
  77. gameserver="${shortname}server"
  78. roundtriperrors=()
  79. roundtripskipped=()
  80. rm -f config config-stock parse-stock parse-stock.values parse-test parse-test.values
  81. echo "::group::${gameserver}"
  82. ./linuxgsm.sh "${gameserver}"
  83. servercfg=$(sed -n "/^\<servercfgdefault\>/ { s/.*= *\"\?\([^\"']*\)\"\?/\1/p;q }" "lgsm/config-default/config-lgsm/${gameserver}/_default.cfg")
  84. if [ -n "${servercfg}" ]; then
  85. cfgpath="${servercfg}"
  86. [[ "${cfgpath}" == \$\{*\}/* ]] && cfgpath="${cfgpath#*\}/}"
  87. curl -fsS -o config-stock "https://raw.githubusercontent.com/GameServerManagers/Game-Server-Configs/main/${shortname}/${cfgpath}"
  88. config=$?
  89. if [ "${config}" -eq 0 ]; then
  90. cat config-stock
  91. cp config-stock config
  92. configresult=$(result "${config}")
  93. elif fn_allowed config; then
  94. rm -f config-stock
  95. config=0
  96. configresult="➖ none (allowed)"
  97. else
  98. configresult=$(result "${config}")
  99. fi
  100. else
  101. echo "This game server has no config file."
  102. config=0
  103. configresult="➖ none"
  104. fi
  105. grep "startparameters" "lgsm/config-default/config-lgsm/${gameserver}/_default.cfg"
  106. ./"${gameserver}" details
  107. details=$?
  108. fn_parse_details parse-stock
  109. parse=$?
  110. fn_check_values stock parse-stock
  111. if [ -f config-stock ]; then
  112. sed -e "s|SERVERNAME|${testservername}|g" -e "s|ADMINPASSWORD|${testpassword}|g" config-stock > config
  113. echo "Round trip: SERVERNAME=${testservername} ADMINPASSWORD=${testpassword}"
  114. fn_parse_details parse-test
  115. fn_check_values test parse-test
  116. if grep -q SERVERNAME config-stock; then
  117. fn_roundtrip_check servername "${testservername}" "Server Name"
  118. fi
  119. if grep -q ADMINPASSWORD config-stock; then
  120. fn_roundtrip_check adminpassword "${testpassword}" "Admin Password" "RCON Password"
  121. fi
  122. cp config-stock config
  123. fi
  124. ./"${gameserver}" query-raw
  125. query=$?
  126. echo "::endgroup::"
  127. if [ "${#roundtriperrors[@]}" -gt 0 ]; then
  128. roundtrip=1
  129. roundtripresult="❌ fail: $(printf '%s; ' "${roundtriperrors[@]}" | sed 's/; $//; s/|/\\|/g')"
  130. echo "::error title=${gameserver} round trip::$(printf '%s; ' "${roundtriperrors[@]}" | sed 's/; $//')"
  131. else
  132. roundtrip=0
  133. if [ -f config-stock ]; then
  134. roundtripresult="✅ pass"
  135. else
  136. roundtripresult="➖ none"
  137. fi
  138. [ "${#roundtripskipped[@]}" -gt 0 ] && roundtripresult+=" (allowed: ${roundtripskipped[*]})"
  139. fi
  140. if [ "${config}" -ne 0 ] || [ "${details}" -ne 0 ] || [ "${parse}" -ne 0 ] || [ "${query}" -ne 0 ] || [ "${roundtrip}" -ne 0 ]; then
  141. failed+=("${gameserver}")
  142. echo "::error title=${gameserver}::config=${config} details=${details} parse-game-details=${parse} query-raw=${query} round-trip=${roundtrip}"
  143. fi
  144. echo "| ${gameserver} | ${configresult} | $(result "${details}") | $(result "${parse}") | $(result "${query}") | ${roundtripresult} |" >> "${summary}"
  145. done
  146. if [ "${#failed[@]}" -gt 0 ]; then
  147. echo -e "\n**Failed:** ${failed[*]}" >> "${summary}"
  148. exit 1
  149. fi