Skip to content

Commit

Permalink
feat(scripts): bash scripts
Browse files Browse the repository at this point in the history
Bash scripts for running processes
  • Loading branch information
BrianLusina committed May 31, 2020
1 parent 6d681bd commit ed141d4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
10 changes: 10 additions & 0 deletions scripts/run_or_fail.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# helper method for providing error messages for a command
run_or_fail() {
local explanation=$1
shift 1
"$@"
if [ $? != 0 ]; then
echo $explanation 1>&2
exit 1
fi
}
10 changes: 10 additions & 0 deletions scripts/test_runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
REPO=$1
COMMIT=$2

source ./scripts/run_or_fail.sh

run_or_fail "Repository folder not found" pushd "$REPO" 1> /dev/null
run_or_fail "Could not clean repository" git clean -d -f -x
run_or_fail "Could not call git pull" git pull
run_or_fail "Could not update to given commit hash" git reset --hard "$COMMIT"
37 changes: 37 additions & 0 deletions scripts/update_repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

source ./scripts/run_or_fail.sh

# delete previous id
rm -f files/.commit_id

# go to repo and update it to given commit
run_or_fail "Repository folder not found!" pushd $1 1> /dev/null
run_or_fail "Could not reset git" git reset --hard HEAD

# get the most recent commit
COMMIT=$(run_or_fail "Could not call 'git log' on repository" git log -n1)
if [ $? != 0 ]; then
echo "Could not call 'git log' on repository"
exit 1
fi
# get its id
COMMIT_ID=`echo $COMMIT | awk '{ print $2 }'`

# update the repo
run_or_fail "Could not pull from repository" git pull

# get the most recent commit
COMMIT=$(run_or_fail "Could not call 'git log' on repository" git log -n1)
if [ $? != 0 ]; then
echo "Could not call 'git log' on repository"
exit 1
fi
# get its id
NEW_COMMIT_ID=`echo $COMMIT | awk '{ print $2 }'`

# if the id changed, then write it to a file
if [ $NEW_COMMIT_ID != $COMMIT_ID ]; then
popd 1> /dev/null
echo $NEW_COMMIT_ID > .commit_id
fi

0 comments on commit ed141d4

Please sign in to comment.