Skip to content

Instantly share code, notes, and snippets.

@yellowcrescent
Created February 18, 2015 00:48
Show Gist options
  • Save yellowcrescent/238e200dc0244c8e0bb1 to your computer and use it in GitHub Desktop.
Save yellowcrescent/238e200dc0244c8e0bb1 to your computer and use it in GitHub Desktop.
Commit validation for ycplay
#!/bin/bash
###############################################################################
#
# ycplay.tv - Commit validation script
# jacob@ycnrg.org
# https://ycnrg.org/
# https://ycplay.tv/
#
###############################################################################
COMMIT_MSG="$1"
cfNORM="\e[0m"
cfBLK="\e[30m"
cfBLU="\e[34m"
cfCYN="\e[36m"
cfGRN="\e[32m"
cfMAG="\e[35m"
cfNORM="\e[39m"
cfRED="\e[31m"
cfWHT="\e[37m"
cfYEL="\e[33m"
# List of PHP scripts to
WASHLIST="*.php enc/yc_xbake enc/yc_xbake.mscan.php enc/xbake_qrunner"
# Check for commit msg
if [ "$COMMIT_MSG" == "" ]; then
echo -en "No commit message specified. Please provide a commit message and try again. kthxbai.\n\n"
exit
fi
# SASS compilation
echo -en "${cfCYN}[sass]${cfWHT}\t ycplay.scss -> ycplay.css${cfNORM} "
sass --scss --sourcemap=none --style=expanded scss/ycplay.scss css/ycplay.css
if [ $? != 0 ]; then
echo -en "\n${cfRED}Error compiling SCSS, check output. Aborting.${cfNORM}\n"
exit
else
echo -en "[ ${cfGRN}OK${cfNORM} ]\n"
fi
# PHP Linting (check for syntax errors)
echo -en "${cfCYN}[php]${cfWHT}\t Linting PHP scripts ${cfNORM}\n"
for i in $WASHLIST; do
echo -en "\t\t${cfYEL}$i${cfWHT}: "
php -l $i
if [ $? != 0 ]; then
echo -en "\n${cRED}PHP Lint check failed. Aborting.${cfNORM}\n"
exit
fi
done
echo -en "${cfCYN}[php]${cfWHT}\t Linting PHP scripts complete ${cfNORM}"
echo -en "[ ${cfGRN}OK${cfNORM} ]\n"
# Git: add files, commit, then push
echo -en "${cfCYN}[git]${cfWHT}\t Preparing files ${cfNORM}\n"
git add -A
git status
echo -en "${cfCYN}[git]${cfWHT}\t Pushing commit ${cfNORM}\n"
git commit -m "$COMMIT_MSG"
git push origin
if [ $? != 0 ]; then
echo -en "\n${cfRED}Error pushing commit. Please check errors and try again.${cfNORM}\n\n"
fi
# Sync to remote hosts
echo -en "${cfCYN}[sync]${cfWHT}\t Syncing commit to ${cfYEL}ikumi${cfNORM}\n"
ssh ikumi -- "git -C /home/jacob/ycplay pull origin"
if [ $? != 0 ]; then
echo -en "\n${cfRED}Error syncing to remote host.${cfNORM}\n"
else
echo -en "${cfCYN}[sync]${cfWHT}\t Sync to ${cfYEL}ikumi${cfNORM} [ ${cfGRN}OK${cfNORM} ]\n"
fi
# Complete!
echo -en "\n\n*** Complete. ${cfGRN}Great Success!${cfNORM}\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment