Upload
boyan-borisov
View
218
Download
3
Embed Size (px)
Citation preview
Putting "Phings" together - how to automate your life
Table of contents
• About me• Introduction to Phing• Basics• What Phing can do for you• Phing and Drupal• How Phing is helping us/Demo• Conclusions• Q/A
About me
• Boyan Borisov• Team Leader @
Propeople• [email protected]• @boyan_borisov• Skype: boian.borisov• http://linkedin.com/in/
boyanborisov
What is Phing?• (PH)ing (I)s (N)ot (G)NU make• Project build tool• Platform-independent: works
on UNIX, Windows, Mac OSX• Based on Apache Ant• Provides a simple OO model
for extending• Uses XML build files• No required external
dependencies• Open source – written on
PHP5
Why?
• Improves work quality• Eliminates repeatable
tasks• Minimises errors• Saves time and money• More code, less
configuration• Forces universal way of
automation• Tons of built-in tasks and
features
Let’s install it
• Pear install$> pear channel-discover pear.phing.info $> pear install [--alldeps] phing/phing• Non pear install$> apt-get install pear$> pear channel-discover pear.phing.info $> pear install [--alldeps] phing/phing
Using Phing
• phing -v• phing -f mybuildfile.xml• phing -f mybuildfile.xml mytarget• phing• phing mytarget• phing -l• phing -debug• phing -Dproperty.name=value
Basics
• Build.xml• Project• Target• Task• Properties• Built-In Properties
Build.xml
<project name="example" default="hello">
<target name="hello" > <echo>Hello world!</echo> </target> <target name= "bye"> <echo>Bye!</echo> </target></project>
Project
<project name="example" default="world” description="Phing example">
<target name="world" description="Say world" depends="hello">
<echo>world!</echo> </target> <target name="hello" description="Say hello">
<echo>Hello</echo> </target></project>
Target
<project name="example" default="world” description="Phing example">
<target name="world" description="Say world" depends="hello">
<echo>world!</echo> </target> <target name="hello" description="Say hello">
<echo>Hello</echo> </target></project>
Task
<project name="example" default="world” description="Phing example">
<target name="world" description="Say world" depends="hello">
<echo>world!</echo> </target> <target name="hello" description="Say hello">
<echo>Hello</echo> </target></project>
Properties
• Built-in properties• Custom properties• Declaration– Inline– External file– Input
Properties
<project name="Example" default="default"> <property name="var1" value="value1"/> <property file="build.properties"/> <input propertyName="var3">Enter var3</input> <target name="default"> <echo>Variables: ${var1}, ${var2} and
${var3}</echo> </target></project>
Build properties file
Drupal.site_name = “Test site”Drupal.profile = “standard”#commentProject.env = “dev”Project.git.url = “httpp://…”
Tasks
• Core: – Copy, Delete, Echo, Exec, Move, Foreach, PhpEvalTask and more
• Optional: – FtpDeploy, GitPush, PDOSQL Exec, Scp, Zip, and more
FileSet
<fileset dir="./application" includes="**" />
<fileset dir="./application" id="files">
<include name="**/*.php"/> <exclude name="**/*Test.php"/></fileset><fileset refid="files" />
FileSet selectors
<fileset dir="${dist}"> <and> <filename name="**/*.log"/>
<date datetime="01/01/2013" when="before"/>
</and></fileset>
Mappers
• Mappers are like filters for files and directories – Flatten – Glob– RegExp
<mapper type="mappername" from="frompattern" to="topattern" />
FlattenMapper
<copy todir="/tmp"> <mapper type="flatten" /> <fileset refid="someid" />
</copy>
GlobMapper
<copy todir="/tmp"> <mapper type="glob" from="*.php" to="*.php.bak"/>
<fileset refid="someid"/></copy>
RegexpMapper
<mapper type="regexp" from="^(.*)\.conf\.xml" to="\1.php"/>
Filters
• Filters Transform data/file contents within a task – Tidy – ExpandProperty– StripPhpComments– ReplaceRegexp– StripWhitespace
TidyFilter
<filterchain><tidyfilter encoding="utf8"> <config name="indent" value="true" />
<config name="output-xhtml" value="true" />
</tidyfilter></filterchain>
ExpandProperty<target name="config"> <property name="config.template" value="config.php-
dist" /> <property name="config.file" value="config.php" /> <property file="config.properties"
override="true" /> <copy file="${config.template}" tofile="$
{config.file}"> <filterchain> <expandproperties /> </filterchain> </copy></target>
Extending Phing
• Tasks • Types • Selectors • Filters • Mappers • Loggers ...
Sample task
SampleTask extends Task { private $var; public function setVar($v) { $this->var = $v; }
public function main() { print('value: ' . $this->var); }}
Hey, is this a DrupalCamp or what?!
Phing Drush Task
https://drupal.org/project/phingdrushtask
drush site-install --yes --locale=uk --site-name =${sitename} expert
<drush command="site-install" assume="yes""> <option name="locale">uk</option> <option name="site-name" value="${sitename}"/>
<param>expert</param></drush>
How Phing is helping us
• Company is growing – from 30 to 75+ people in about a year
• Bigger projects – from 300 to 2000+ hours• Bigger teams – from 2 to 10+ team members • Many new employees• Many developers, many ways to manage a
project
Thank you, Phing!
What’s next
• http://phing.info• Adopt Phing for your
needs• Create new tasks• Contribute• Jenkins• https://github.com/relo
ad/phing-drupal-template
Questions?