33
Putting "Phings" together - how to automate your life

Putting "Phings" together - how to automate your life

Embed Size (px)

Citation preview

Page 1: Putting "Phings" together - how to automate your life

Putting "Phings" together - how to automate your life

Page 2: 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

Page 3: Putting "Phings" together - how to automate your life

About me

• Boyan Borisov• Team Leader @

Propeople• [email protected]• @boyan_borisov• Skype: boian.borisov• http://linkedin.com/in/

boyanborisov

Page 4: Putting "Phings" together - how to automate your life

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

Page 5: Putting "Phings" together - how to automate your life

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

Page 6: Putting "Phings" together - how to automate your life

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

Page 7: Putting "Phings" together - how to automate your life

Using Phing

• phing -v• phing -f mybuildfile.xml• phing -f mybuildfile.xml mytarget• phing• phing mytarget• phing -l• phing -debug• phing -Dproperty.name=value

Page 8: Putting "Phings" together - how to automate your life

Basics

• Build.xml• Project• Target• Task• Properties• Built-In Properties

Page 9: Putting "Phings" together - how to automate your life

Build.xml

<project name="example" default="hello">

<target name="hello" > <echo>Hello world!</echo> </target> <target name= "bye"> <echo>Bye!</echo> </target></project>

Page 10: Putting "Phings" together - how to automate your life

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>

Page 11: Putting "Phings" together - how to automate your life

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>

Page 12: Putting "Phings" together - how to automate your life

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>

Page 13: Putting "Phings" together - how to automate your life

Properties

• Built-in properties• Custom properties• Declaration– Inline– External file– Input

Page 14: Putting "Phings" together - how to automate your life

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>

Page 15: Putting "Phings" together - how to automate your life

Build properties file

Drupal.site_name = “Test site”Drupal.profile = “standard”#commentProject.env = “dev”Project.git.url = “httpp://…”

Page 16: Putting "Phings" together - how to automate your life

Tasks

• Core: – Copy, Delete, Echo, Exec, Move, Foreach, PhpEvalTask and more

• Optional: – FtpDeploy, GitPush, PDOSQL Exec, Scp, Zip, and more

Page 17: Putting "Phings" together - how to automate your life

FileSet

<fileset dir="./application" includes="**" />

<fileset dir="./application" id="files">

<include name="**/*.php"/> <exclude name="**/*Test.php"/></fileset><fileset refid="files" />

Page 18: Putting "Phings" together - how to automate your life

FileSet selectors

<fileset dir="${dist}"> <and> <filename name="**/*.log"/>

<date datetime="01/01/2013" when="before"/>

</and></fileset>

Page 19: Putting "Phings" together - how to automate your life

Mappers

• Mappers are like filters for files and directories – Flatten – Glob– RegExp

<mapper type="mappername" from="frompattern" to="topattern" />

Page 20: Putting "Phings" together - how to automate your life

FlattenMapper

<copy todir="/tmp"> <mapper type="flatten" /> <fileset refid="someid" />

</copy>

Page 21: Putting "Phings" together - how to automate your life

GlobMapper

<copy todir="/tmp"> <mapper type="glob" from="*.php" to="*.php.bak"/>

<fileset refid="someid"/></copy>

Page 22: Putting "Phings" together - how to automate your life

RegexpMapper

<mapper type="regexp" from="^(.*)\.conf\.xml" to="\1.php"/>

Page 23: Putting "Phings" together - how to automate your life

Filters

• Filters Transform data/file contents within a task – Tidy – ExpandProperty– StripPhpComments– ReplaceRegexp– StripWhitespace

Page 24: Putting "Phings" together - how to automate your life

TidyFilter

<filterchain><tidyfilter encoding="utf8"> <config name="indent" value="true" />

<config name="output-xhtml" value="true" />

</tidyfilter></filterchain>

Page 25: Putting "Phings" together - how to automate your life

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>

Page 26: Putting "Phings" together - how to automate your life

Extending Phing

• Tasks • Types • Selectors • Filters • Mappers • Loggers ...

Page 27: Putting "Phings" together - how to automate your life

Sample task

SampleTask extends Task { private $var; public function setVar($v) { $this->var = $v; }

public function main() { print('value: ' . $this->var); }}

Page 28: Putting "Phings" together - how to automate your life

Hey, is this a DrupalCamp or what?!

Page 29: Putting "Phings" together - how to automate your life

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>

Page 30: Putting "Phings" together - how to automate your life

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

Page 31: Putting "Phings" together - how to automate your life

Thank you, Phing!

Page 32: Putting "Phings" together - how to automate your life

What’s next

• http://phing.info• Adopt Phing for your

needs• Create new tasks• Contribute• Jenkins• https://github.com/relo

ad/phing-drupal-template

Page 33: Putting "Phings" together - how to automate your life

Questions?