Created
March 23, 2011 14:25
-
-
Save SeanJA/883168 to your computer and use it in GitHub Desktop.
precommit-hook to run ant tasks and store the results and then add them to the commit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<project name="Webads"> | |
<!--This target runs the phpcs--> | |
<target name="phpcs"> | |
<!--unix--> | |
<exec dir="${basedir}" executable="phpcs" failonerror="false" osfamily="unix"> | |
<arg line="--standard=Cake --extensions=php,module,inc ${basedir}"/> | |
</exec> | |
</target> | |
<!--This target runs phpmd. The failonerror attrib is yet inefficient, but | |
a small patch can fix the PHPMD's exit levels--> | |
<target name="phpmd"> | |
<!--unix--> | |
<exec dir="${basedir}" executable="phpmd" failonerror="false" osfamily="unix"> | |
<arg line=". text codesize,naming,unusedcode"/> | |
</exec> | |
</target> | |
<!--This target runs phpcpd. The failonerror attrib is inefficient. The | |
exit levels will be fixed in v phpcpd v. 0.2.5--> | |
<target name="phpcpd"> | |
<!--unix--> | |
<exec dir="${basedir}" executable="phpcpd" failonerror="false" osfamily="unix"> | |
<arg line="--min-tokens 10 ${basedir}"/> | |
</exec> | |
</target> | |
<!-- Change the following properties accordingly. --> | |
<property name="db.username" value="root"/> | |
<property name="db.password" value="toor"/> | |
<property name="db.name" value="database"/><!-- The name of the database to backup. --> | |
<property name="archive.dir" value="archive_db"/> | |
<tstamp> | |
<format property="DAY_TIME_NOW" pattern="yyyy-MM-dd_HH.mm.ss" /> | |
</tstamp> | |
<target name="backup_db"> | |
<mkdir dir="${archive.dir}"/><!-- Create the archive directory anyway. --> | |
<!-- Create a directory to dump the backup --> | |
<property name="backup.dir" value="${archive.dir}/${ant.project.name}_${DAY_TIME_NOW}"/> | |
<mkdir dir="${backup.dir}"/> | |
<!-- Command to dump the database to *.sql file.--> | |
<exec executable="mysqldump" output="${backup.dir}/${ant.project.name}_${DAY_TIME_NOW}.sql"> | |
<arg value="--hex-blob"/> | |
<arg value="--extended-insert=false"/> | |
<arg value="--complete-insert=true"/> | |
<arg value="--user=${db.username}"/> | |
<arg value="--password=${db.password}"/> | |
<arg value="${db.name}"/> | |
</exec> | |
<!-- Compress the dumped file(*.sql) --> | |
<tar destfile="${backup.dir}/${ant.project.name}_${DAY_TIME_NOW}.sql.tar.gz" | |
compression="gzip"> | |
<tarfileset dir="${backup.dir}"> | |
<include name="${ant.project.name}_${DAY_TIME_NOW}.sql"/> | |
</tarfileset> | |
</tar> | |
<!-- Delete the dumped file(*.sql) --> | |
<delete file="${backup.dir}/${ant.project.name}_${DAY_TIME_NOW}.sql"/> | |
</target> | |
<target name="js.minify.clean"> | |
<delete> | |
<fileset dir="${basedir}/public/js" includes="*.min.js"/> | |
</delete> | |
</target> | |
<target name="js.minify" depends="js.minify.clean"> | |
<apply executable="nodejs" parallel="false" failonerror="true"> | |
<fileset dir="${basedir}/public/js" includes="*.js" /> | |
<arg line="${basedir}/build/uglify.js" /> | |
<arg line="--unsafe" /> | |
<arg line="--output" /> | |
<mapper type="glob" from="*.js" to="${basedir}/public/js/*.min.js"/> | |
<targetfile/> | |
<srcfile/> | |
</apply> | |
</target> | |
<target name="css.minify.clean"> | |
<delete> | |
<fileset dir="${basedir}/public/css" includes="*.min.css"/> | |
</delete> | |
</target> | |
<target name="css.minify" depends="css.minify.clean"> | |
<apply executable="java" parallel="false" failonerror="true"> | |
<fileset dir="${basedir}/public/css" includes="*.css" /> | |
<arg line="-jar"/> | |
<arg path="${basedir}/build/yuicompressor.jar"/> | |
<arg line="--line-break 0"/> | |
<srcfile/> | |
<arg line="-o"/> | |
<mapper type="glob" from="*.css" to="${basedir}/public/css/*.min.css"/> | |
<targetfile/> | |
</apply> | |
</target> | |
<target name="minify" depends="css.minify,js.minify"/> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#check the code, and dump the results to the file | |
#none of these will actually halt the commit | |
ant phpcpd > ./reports/phpcpd.txt | |
ant phpcs > ./reports/phpcs.txt | |
ant phpmd > ./reports/phpmd.txt | |
ant minify | |
#backup the database | |
ant backup_db | |
#add the files to the commit to keep a log of it | |
git add archive_db/* | |
git add reports/* | |
#add the compressed css and js files to the commit | |
git add public/js/*.min.js | |
git add public/css/*.min.css |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment