run-tests 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. # Copyright (C) 2015 Alex-Daniel Jakimenko <alex.jakimenko@gmail.com>
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as
  6. # published by the Free Software Foundation, either version 3 of the
  7. # License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. set -e
  17. WORKING_DIRECTORY='../data/'
  18. TEST_LOCK="$WORKING_DIRECTORY/testlock"
  19. TEST_LOG="$WORKING_DIRECTORY/log"
  20. ODDMUSE_TEST_LOCATION="$WORKING_DIRECTORY/oddmuse-for-tests/"
  21. GIT_LOCATION="$WORKING_DIRECTORY/"
  22. LAST_COMMIT_FILE="$WORKING_DIRECTORY/last_commit"
  23. LAST_STATUS_FILE="$WORKING_DIRECTORY/last_status"
  24. FIRST_TESTABLE_COMMIT='1c0801bd6ca23de71c7c360a18a648c2b953f1da'
  25. RESULT_FILE="$WORKING_DIRECTORY/output"
  26. WIKIPUT='../config/oddmuse/scripts/cli/wikiput'
  27. STATUS_PAGE='Test Status'
  28. OUT_PAGE='https://github.com/AlexDaniel/oddmuse-alexine-data/blob/master/output'
  29. WIKI_LOCATION='https://oddmuse.org/wiki/'
  30. USER_NAME='Alexine'
  31. clean() {
  32. while popd &> /dev/null; do :; done # change directory back
  33. rmdir -- "$TEST_LOCK"
  34. }
  35. [[ -d $ODDMUSE_TEST_LOCATION ]] || git clone -- 'https://github.com/kensanata/oddmuse.git' "$ODDMUSE_TEST_LOCATION"
  36. if mkdir -- "$TEST_LOCK"; then # only one instance running
  37. trap clean EXIT
  38. else
  39. exit 0
  40. fi
  41. git=('git' '--git-dir' "$ODDMUSE_TEST_LOCATION/.git" '--work-tree' "$ODDMUSE_TEST_LOCATION")
  42. gitRepo=('git' '--git-dir' "$WORKING_DIRECTORY/.git" '--work-tree' "$WORKING_DIRECTORY") # our repo where we will make commits
  43. while :; do
  44. "${git[@]}" fetch # get latest changes
  45. "${git[@]}" reset --hard origin/master # starting our search from the last commit
  46. [[ -f $LAST_COMMIT_FILE ]] || echo "$FIRST_TESTABLE_COMMIT" > "$LAST_COMMIT_FILE"
  47. [[ -f $LAST_STATUS_FILE ]] || echo 0 > "$LAST_STATUS_FILE"
  48. lastCommit=$(< "$LAST_COMMIT_FILE")
  49. lastStatus=$(< "$LAST_STATUS_FILE")
  50. logOutput=$("${git[@]}" log --topo-order --pretty=oneline | grep --before 1 -m 1 "^$lastCommit")
  51. (($(wc -l <<< "$logOutput") < 2)) && exit 0 # No more commits to process, good!
  52. read -r currentCommit _ <<< "$logOutput"
  53. "${git[@]}" checkout "$currentCommit"
  54. # ((startTime = SECONDS)) ||:
  55. pushd -- "$ODDMUSE_TEST_LOCATION" || exit 1
  56. output=$(make test jobs=8 2>&1) &&:
  57. status=$?
  58. popd
  59. # ((duration = SECONDS - startTime)) ||:
  60. printf "%s\n" "$output" > "$RESULT_FILE"
  61. # echo "Duration: $((duration/60))m$((duration%60))s Status: $status" >> "$RESULT_FILE"
  62. printf "%s\n" "$currentCommit" > "$LAST_COMMIT_FILE"
  63. printf "%s\n" "$status" > "$LAST_STATUS_FILE"
  64. "${gitRepo[@]}" add -- "$(readlink -m -- "$RESULT_FILE")" "$(readlink -m -- "$LAST_COMMIT_FILE")" "$(readlink -m -- "$LAST_STATUS_FILE")"
  65. "${gitRepo[@]}" commit -m "Test status at $currentCommit (automated commit)"
  66. "${gitRepo[@]}" push
  67. if (( status == 0 )); then
  68. (( lastStatus == 0 )) && minor='-m' || minor='' # we will use unquoted variable on purpose
  69. "$WIKIPUT" $minor -u "$USER_NAME" -s 'Tests PASSED' -z 'ham' "$WIKI_LOCATION/$STATUS_PAGE" <<< $'TEST STATUS – **OK**\n\n'"Commit:${currentCommit:0:7} – see [[$OUT_PAGE|test log]]"
  70. else
  71. "$WIKIPUT" -u "$USER_NAME" -s 'Tests FAILED' -z 'ham' "$WIKI_LOCATION/$STATUS_PAGE" <<< $'TEST STATUS – **FAIL**\n\n'"Commit:${currentCommit:0:7} – see [[$OUT_PAGE|test log]]"
  72. fi
  73. done