2015-08-19 08:46:16 +03:00
|
|
|
|
#!/bin/bash
|
2015-08-20 06:47:53 +03:00
|
|
|
|
# Copyright (C) 2015 Alex-Daniel Jakimenko <alex.jakimenko@gmail.com>
|
|
|
|
|
|
#
|
2015-09-07 05:00:20 +03:00
|
|
|
|
# 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.
|
2015-08-20 06:47:53 +03:00
|
|
|
|
#
|
2015-09-07 05:00:20 +03:00
|
|
|
|
# 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.
|
2015-08-20 06:47:53 +03:00
|
|
|
|
#
|
2015-09-07 05:00:20 +03:00
|
|
|
|
# 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/>.
|
2015-08-19 08:46:16 +03:00
|
|
|
|
set -e
|
|
|
|
|
|
|
2015-10-21 05:37:49 +03:00
|
|
|
|
WORKING_DIRECTORY='../data/'
|
|
|
|
|
|
TEST_LOCK="$WORKING_DIRECTORY/testlock"
|
|
|
|
|
|
TEST_LOG="$WORKING_DIRECTORY/log"
|
|
|
|
|
|
ODDMUSE_TEST_LOCATION="$WORKING_DIRECTORY/oddmuse-for-tests/"
|
|
|
|
|
|
GIT_LOCATION="$WORKING_DIRECTORY/"
|
|
|
|
|
|
LAST_COMMIT_FILE="$WORKING_DIRECTORY/last_commit"
|
2015-11-03 02:52:29 +02:00
|
|
|
|
LAST_STATUS_FILE="$WORKING_DIRECTORY/last_status"
|
2015-08-19 08:46:16 +03:00
|
|
|
|
FIRST_TESTABLE_COMMIT='1c0801bd6ca23de71c7c360a18a648c2b953f1da'
|
2015-10-21 05:37:49 +03:00
|
|
|
|
RESULT_FILE="$WORKING_DIRECTORY/output"
|
|
|
|
|
|
WIKIPUT='../config/oddmuse/scripts/cli/wikiput'
|
2015-08-19 08:46:16 +03:00
|
|
|
|
STATUS_PAGE='Test Status'
|
2015-10-21 06:00:57 +03:00
|
|
|
|
OUT_PAGE='https://github.com/AlexDaniel/oddmuse-alexine-data/blob/master/output'
|
2015-08-19 08:46:16 +03:00
|
|
|
|
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")
|
2015-10-21 05:37:49 +03:00
|
|
|
|
gitRepo=('git' '--git-dir' "$WORKING_DIRECTORY/.git" '--work-tree' "$WORKING_DIRECTORY") # our repo where we will make commits
|
2015-08-19 08:46:16 +03:00
|
|
|
|
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"
|
2015-11-03 02:52:29 +02:00
|
|
|
|
[[ -f $LAST_STATUS_FILE ]] || echo 0 > "$LAST_STATUS_FILE"
|
2015-08-19 08:46:16 +03:00
|
|
|
|
lastCommit=$(< "$LAST_COMMIT_FILE")
|
2015-11-03 02:52:29 +02:00
|
|
|
|
lastStatus=$(< "$LAST_STATUS_FILE")
|
2015-08-19 08:46:16 +03:00
|
|
|
|
|
|
|
|
|
|
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
|
2015-10-21 05:37:49 +03:00
|
|
|
|
output=$(make test jobs=8 2>&1) &&:
|
2015-08-19 08:46:16 +03:00
|
|
|
|
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"
|
2015-11-03 02:52:29 +02:00
|
|
|
|
printf "%s\n" "$status" > "$LAST_STATUS_FILE"
|
2015-08-19 08:46:16 +03:00
|
|
|
|
|
2015-11-03 02:52:29 +02:00
|
|
|
|
"${gitRepo[@]}" add -- "$(readlink -m -- "$RESULT_FILE")" "$(readlink -m -- "$LAST_COMMIT_FILE")" "$(readlink -m -- "$LAST_STATUS_FILE")"
|
2015-10-21 05:37:49 +03:00
|
|
|
|
"${gitRepo[@]}" commit -m "Test status at $currentCommit (automated commit)"
|
2015-08-19 08:46:16 +03:00
|
|
|
|
|
2015-10-21 05:37:49 +03:00
|
|
|
|
"${gitRepo[@]}" push
|
2015-08-19 08:46:16 +03:00
|
|
|
|
|
2015-08-19 10:47:49 +03:00
|
|
|
|
if (( status == 0 )); then
|
2015-11-03 02:52:29 +02:00
|
|
|
|
(( lastStatus == 0 )) && minor='-m' || minor='' # we will use unquoted variable on purpose
|
|
|
|
|
|
"$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]]"
|
2015-08-19 08:46:16 +03:00
|
|
|
|
else
|
2015-08-19 11:19:31 +03:00
|
|
|
|
"$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]]"
|
2015-08-19 08:46:16 +03:00
|
|
|
|
fi
|
|
|
|
|
|
done
|