Files
oddmuse/scripts/alexine/run-tests
2015-09-07 05:00:20 +03:00

77 lines
3.0 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Copyright (C) 2015 Alex-Daniel Jakimenko <alex.jakimenko@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -e
TEST_LOCK='../testlock'
TEST_LOG='../log'
ODDMUSE_TEST_LOCATION='../oddmuse-for-tests/'
LAST_COMMIT_FILE='../last_commit'
FIRST_TESTABLE_COMMIT='1c0801bd6ca23de71c7c360a18a648c2b953f1da'
RESULT_FILE='../output'
WIKIPUT='../oddmuse/scripts/cli/wikiput'
STATUS_PAGE='Test Status'
OUT_PAGE='https://github.com/AlexDaniel/oddmuse-alexine/blob/master/output'
WIKI_LOCATION='https://oddmuse.org/wiki/'
USER_NAME='Alexine'
clean() {
while popd &> /dev/null; do :; done # change directory back
rmdir -- "$TEST_LOCK"
}
[[ -d $ODDMUSE_TEST_LOCATION ]] || git clone -- 'https://github.com/kensanata/oddmuse.git' "$ODDMUSE_TEST_LOCATION"
if mkdir -- "$TEST_LOCK"; then # only one instance running
trap clean EXIT
else
exit 0
fi
git=('git' '--git-dir' "$ODDMUSE_TEST_LOCATION/.git" '--work-tree' "$ODDMUSE_TEST_LOCATION")
while :; do
"${git[@]}" fetch # get latest changes
"${git[@]}" reset --hard origin/master # starting our search from the last commit
[[ -f $LAST_COMMIT_FILE ]] || echo "$FIRST_TESTABLE_COMMIT" > "$LAST_COMMIT_FILE"
lastCommit=$(< "$LAST_COMMIT_FILE")
logOutput=$("${git[@]}" log --topo-order --pretty=oneline | grep --before 1 -m 1 "^$lastCommit")
(($(wc -l <<< "$logOutput") < 2)) && exit 0 # No more commits to process, good!
read -r currentCommit _ <<< "$logOutput"
"${git[@]}" checkout "$currentCommit"
# ((startTime = SECONDS)) ||:
pushd -- "$ODDMUSE_TEST_LOCATION" || exit 1
output=$(make test 2>&1) &&:
status=$?
popd
# ((duration = SECONDS - startTime)) ||:
printf "%s\n" "$output" > "$RESULT_FILE"
# echo "Duration: $((duration/60))m$((duration%60))s Status: $status" >> "$RESULT_FILE"
printf "%s\n" "$currentCommit" > "$LAST_COMMIT_FILE"
git add -- "$RESULT_FILE" "$LAST_COMMIT_FILE" # other git repo, therefore just 'git'
git commit -m "Test status at $currentCommit (automated commit)"
git push
if (( status == 0 )); then
"$WIKIPUT" -m -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]]"
else
"$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]]"
fi
done