-
-
Save punkstar/9df01c26e5c5b8e2ef90 to your computer and use it in GitHub Desktop.
Example Buildfile
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="project-magento" default="test"> | |
<property name="bin.dir" value="${project.basedir}/vendor/bin/" /> | |
<property name="src.dir" value="${project.basedir}/src/" /> | |
<property name="build.dir" value="${project.basedir}/build/" /> | |
<property name="etc.dir" value="${project.basedir}/etc/" /> | |
<property name="database.dir" value="${project.basedir}/database/" /> | |
<property name="vhost.dir" value="/var/www/magento/" /> | |
<property name="theme_skin.dir" value="${src.dir}/skin/frontend/client_name/default/" /> | |
<property name="wget" value="wget" /> | |
<property name="php" value="php" /> | |
<property name="npm" value="npm" /> | |
<property name="gem" value="gem" /> | |
<property name="bundler" value="bundle" /> | |
<property name="vagrant" value="vagrant" /> | |
<property name="baseurl" value="http://clientname.localhost/" /> | |
<property name="db.name" value="magento" /> | |
<property name="db.user" value="magento" /> | |
<property name="db.pass" value="magento" /> | |
<property name="db.test.name" value="magento-test " /> | |
<property name="db.test.user" value="magento" /> | |
<property name="db.test.pass" value="magento" /> | |
<property name="composer" value="${php} ${project.basedir}/composer.phar" /> | |
<property name="phpunit" value="${php} ${bin.dir}/phpunit" /> | |
<property name="phpmd" value="${php} ${bin.dir}/phpmd" /> | |
<property name="phpcs" value="${php} ${bin.dir}/phpcs" /> | |
<property name="ecomdev-helper" value="${php} ${src.dir}/shell/ecomdev-phpunit.php" /> | |
<property name="rocketeer" value="${php} ${bin.dir}/rocketeer" /> | |
<property name="rocketeer.params" value="" /> | |
<property name="vagrant-run" value="${vagrant} ssh -c" /> | |
<target name="test" depends="test:unit" description="Run all tests" /> | |
<target name="analyse" depends="analyse:phpmd,analyse:phpcs" description="Run all static analysis" /> | |
<target name="prepare:deps" depends="check:running_in_vagrant,prepare:deps:composer,prepare:deps:npm" description="Install project dependencies" /> | |
<target name="dev:vm:build" depends="dev:vm:start,dev:vm:provision,prepare:deps:composer" description="Start VM and ensure it's provisioned" /> | |
<!-- ===================================================== --> | |
<!-- Get the entire machine up and running --> | |
<!-- ===================================================== --> | |
<target name="dev:vm:initial-setup" depends="dev:vm:build"> | |
<exec command="${vagrant-run} 'cd ${vhost.dir}; vendor/bin/phing prepare:install-magento prepare:deps:npm prepare:deps:ruby'" passthru="true" /> | |
<phingcall target="dev:db:restore" /> | |
</target> | |
<!-- ===================================================== --> | |
<!-- Run frontend dev tools --> | |
<!-- ===================================================== --> | |
<target name="dev:frontend" depends="check:not_running_in_vagrant" description="Run frontend tools"> | |
<exec command="${vagrant-run} 'cd ${vhost.dir}; cd src/skin/frontend/turnbull/default; ./node_modules/.bin/gulp'" passthru="true" /> | |
</target> | |
<!-- ===================================================== --> | |
<!-- Install required composer dependencies --> | |
<!-- ===================================================== --> | |
<target name="prepare:deps:composer" description="Install all project composer dependencies"> | |
<available file="${project.basedir}/composer.phar" type="file" property="composer_downloaded" /> | |
<if> | |
<equals arg1="${composer_downloaded}" arg2="true" /> | |
<then> | |
<echo message="Composer already exists, no need to download" /> | |
</then> | |
<else> | |
<echo message="Downloading composer.." /> | |
<exec command="${wget} https://getcomposer.org/composer.phar -O ${project.basedir}/composer.phar" passthru="true" /> | |
</else> | |
</if> | |
<echo message="Installing composer dependencies.." /> | |
<exec | |
command="${composer} install --dev" | |
dir="${project.basedir}" | |
checkreturn="true" | |
passthru="true" | |
/> | |
</target> | |
<!-- ===================================================== --> | |
<!-- Install required NPM dependencies --> | |
<!-- ===================================================== --> | |
<target name="prepare:deps:npm" depends="check:running_in_vagrant" description="Install all project npm dependencies"> | |
<exec command="${npm} install" dir="${theme_skin.dir}" checkreturn="true" passthru="true" /> | |
</target> | |
<!-- ===================================================== --> | |
<!-- Install required Ruby dependencies --> | |
<!-- ===================================================== --> | |
<target name="prepare:deps:ruby" depends="check:running_in_vagrant" description="Install all project ruby dependencies"> | |
<exec command="sudo ${gem} install bundler" dir="${theme_skin.dir}" checkreturn="true" passthru="true" /> | |
<exec command="${bundler} install" dir="${theme_skin.dir}" checkreturn="true" passthru="true" /> | |
</target> | |
<!-- ===================================================== --> | |
<!-- Install Magento on the VM --> | |
<!-- ===================================================== --> | |
<target name="prepare:install-magento" depends="check:running_in_vagrant" description="Install Magento using default settings"> | |
<available file="${src.dir}/app/etc/local.xml" type="file" property="local_xml_exists" /> | |
<if> | |
<equals arg1="${local_xml_exists}" arg2="true" /> | |
<then> | |
<echo message="Magento already installed, to reinstall delete the app/etc/local.xml file." /> | |
</then> | |
<else> | |
<echo message="Installing Magento" /> | |
<exec | |
command=' | |
${php} -f install.php -- \ | |
--license_agreement_accepted "yes" \ | |
--locale "en_GB" \ | |
--timezone "Europe/London" \ | |
--default_currency "GBP" \ | |
--db_host "localhost" \ | |
--db_name "${db.name}" \ | |
--db_user "${db.user}" \ | |
--db_pass "${db.pass}" \ | |
--url "${baseurl}" \ | |
--use_rewrites "yes" \ | |
--use_secure "no" \ | |
--secure_base_url "${baseurl}" \ | |
--use_secure_admin "no" \ | |
--skip_url_validation "yes" \ | |
--admin_firstname "Store" \ | |
--admin_lastname "Owner" \ | |
--admin_email "test@test.com" \ | |
--admin_username "admin" \ | |
--admin_password "password1" | |
' | |
dir="${src.dir}" | |
checkreturn="true" | |
passthru="true" | |
/> | |
</else> | |
</if> | |
</target> | |
<!-- ===================================================== --> | |
<!-- Ensure VM is running --> | |
<!-- ===================================================== --> | |
<target name="dev:vm:start" depends="check:not_running_in_vagrant,check:environment" description="Start VM"> | |
<echo message="Ensuring VM is started.." /> | |
<exec command="${vagrant} up" passthru="true" /> | |
</target> | |
<!-- ===================================================== --> | |
<!-- Ensure VM is fully provisioned --> | |
<!-- ===================================================== --> | |
<target name="dev:vm:provision" depends="check:not_running_in_vagrant" description="Provision VM"> | |
<echo message="Ensuring VM is provisioned.." /> | |
<exec command="${vagrant} provision" passthru="true" /> | |
</target> | |
<!-- ===================================================== --> | |
<!-- Create a database dump --> | |
<!-- ===================================================== --> | |
<target name="dev:db:dump" depends="check:not_running_in_vagrant" description="Create a database dump"> | |
<exec command="${vagrant-run} 'cd ${vhost.dir}; php vendor/bin/n98-magerun --root-dir=${vhost.dir}/src/ db:dump --strip=@development --human-readable --stdout' > ${database.dir}/database.sql" passthru="true" /> | |
<echo message="Dump has been output to ${database.dir}/database.sql, commit and push submodule to publish changes" /> | |
</target> | |
<!-- ===================================================== --> | |
<!-- Restores a database dump --> | |
<!-- ===================================================== --> | |
<target name="dev:db:restore" depends="check:not_running_in_vagrant" description="Restores a database dump"> | |
<echo message="Fetching latest database" /> | |
<exec command="git submodule init" dir="${project.basedir}" passthru="true" /> | |
<exec command="git submodule update" dir="${project.basedir}" passthru="true" /> | |
<exec command="git pull origin master" dir="${database.dir}" passthru="true" /> | |
<echo message="Importing database" /> | |
<exec command="cat database.sql | ${vagrant-run} 'mysql -D${db.name} -u ${db.user} -p${db.pass}'" dir="${database.dir}" passthru="true" /> | |
</target> | |
<!-- ===================================================== --> | |
<!-- Run PHPUnit tests --> | |
<!-- ===================================================== --> | |
<target name="test:unit" depends="test:unit:configure" description="Run phpunit"> | |
<exec command="${phpunit}" dir="${src.dir}" passthru="true" /> | |
</target> | |
<!-- ===================================================== --> | |
<!-- Configure Ecomdev_PHPUnit to run --> | |
<!-- ===================================================== --> | |
<target name="test:unit:configure" description="Configure ecomdev to run phpunit"> | |
<exec command="${ecomdev-helper} --action install" dir="${src.dir}" passthru="true" /> | |
<exec command="${ecomdev-helper} --action magento-config --db-name ${db.test.name} --db-user ${db.test.user} --db-pass ${db.test.pass} --base-url ${baseurl}" dir="${src.dir}" passthru="true" /> | |
</target> | |
<!-- ===================================================== --> | |
<!-- Run phpmd --> | |
<!-- ===================================================== --> | |
<target name="analyse:phpmd" description="Run phpmd"> | |
<mkdir dir="${build.dir}" /> | |
<touch file="${build.dir}/phpmd-results.xml" /> | |
<exec command="${phpmd} ${src.dir}/app/code/local xml ${etc.dir}/phpmd.xml --reportfile ${build.dir}/phpmd-results.xml" dir="${src.dir}" passthru="true" /> | |
</target> | |
<!-- ===================================================== --> | |
<!-- Run phpcs --> | |
<!-- ===================================================== --> | |
<target name="analyse:phpcs" description="Run phpcs"> | |
<mkdir dir="${build.dir}" /> | |
<touch file="${build.dir}/phpcs-results.xml" /> | |
<exec command="${phpcs} --report=checkstyle --report-file=${build.dir}/phpcs-results.xml --standard=${etc.dir}/phpcs.xml ${src.dir}/app/code/local" dir="${src.dir}" passthru="true" /> | |
</target> | |
<!-- ===================================================== --> | |
<!-- Deploy to staging --> | |
<!-- ===================================================== --> | |
<target name="deploy:staging" description="Deploy to staging"> | |
<exec command="${rocketeer} deploy --on=staging ${rocketeer.params}" dir="${project.basedir}" passthru="true" /> | |
</target> | |
<!-- ===================================================== --> | |
<!-- Check that a command is being run in a vagrant --> | |
<!-- ===================================================== --> | |
<target name="check:running_in_vagrant" description="Errors if the task *is not* running in Vagrant"> | |
<exec command="test $USER = 'vagrant'" returnProperty="vagrant_user_check" /> | |
<if> | |
<equals arg1="${vagrant_user_check}" arg2="1" /> | |
<then> | |
<echo message="You need to run this command INSIDE of the vagrant box" /> | |
</then> | |
</if> | |
</target> | |
<!-- ===================================================== --> | |
<!-- Check that a command is not being run in a vagrant --> | |
<!-- ===================================================== --> | |
<target name="check:not_running_in_vagrant" description="Errors if task *is* running in Vagrant"> | |
<exec command="test $USER != 'vagrant'" returnProperty="vagrant_user_check" /> | |
<if> | |
<equals arg1="${vagrant_user_check}" arg2="1" /> | |
<then> | |
<echo message="You need to run this command OUTSIDE of the vagrant box" /> | |
</then> | |
</if> | |
</target> | |
<!-- ===================================================== --> | |
<!-- Perform checks on the environment --> | |
<!-- ===================================================== --> | |
<target name="check:environment" description="Confirms that the environment is correctly configured"> | |
<!-- Check that the hosts file has correct mapping --> | |
<exec command="grep -RE '\s*192.168.10.10\s\s*clientname.localhost\s*' /etc/hosts" returnProperty="hosts_file_check" /> | |
<if> | |
<equals arg1="${hosts_file_check}" arg2="1" /> | |
<then> | |
<echo message="You need to add '192.168.10.10 clientname.localhost' to the end of your /etc/hosts file" /> | |
</then> | |
</if> | |
</target> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment