Created
December 15, 2015 21:34
-
-
Save grasmash/e016017b9a5b3bba8288 to your computer and use it in GitHub Desktop.
Drupal 7 Deployment tasks
This file contains hidden or 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
| <project name="deploy" default="deploy:repo"> | |
| <target name="deploy:artifact" description="Builds separate artifact and pushes to git.remotes defined project.yml." depends="deploy:artifact:clean"> | |
| <!-- deploy.branch and deploy.commitMsg must be passed as params at runtime. --> | |
| <if> | |
| <or> | |
| <not><isset property="deploy.branch"/></not> | |
| <not><isset property="deploy.commitMsg"/></not> | |
| </or> | |
| <then> | |
| <fail>You must pass deploy.branch and deploy.commitMsg as runtime parameters.</fail> | |
| <echo message="Command should match syntax:"/> | |
| <echo message="./task.sh deploy:artifact -Ddeploy.branch=7.x-build -Ddeploy.commitMsg='BLT-123: The commit message.'"/> | |
| </then> | |
| </if> | |
| <exec command="git init ${deploy.dir}" logoutput="true"/> | |
| <!-- Add remotes and fetch upstream refs. Checkout local branch tracking | |
| tracking upstream branch, if it exists. Otherwise create new branch | |
| locally. --> | |
| <foreach list="${git.remotes}" param="deploy.remote" target="deploy:artifact:add-remote"/> | |
| <!-- Build artifact and commit locally. --> | |
| <phingcall target="deploy:artifact:build"/> | |
| <exec command="git add -A" dir="${deploy.dir}" logoutput="true" passthru="true"/> | |
| <exec command="git commit -m '${deploy.commitMsg}' --quiet" dir="${deploy.dir}" logoutput="true" passthru="true"/> | |
| <!-- Push up changes to remotes. --> | |
| <foreach list="${git.remotes}" param="deploy.remote" target="deploy:artifact:push"/> | |
| </target> | |
| <target name="deploy:artifact:add-remote" description="Adds a git remote and checks out deploy branch from upstream."> | |
| <!-- Generate and md5 sum of the remote URL to use as remote name. --> | |
| <exec command="echo ${deploy.remote} | openssl md5 | cut -d' ' -f 2" outputProperty="remoteName"/> | |
| <exec command="git remote add ${remoteName} ${deploy.remote}" dir="${deploy.dir}" logoutput="true" passthru="true"/> | |
| <exec command="git fetch ${remoteName}" dir="${deploy.dir}" logoutput="true" passthru="true"/> | |
| <!-- This will only be successful for the first remote, which is good. | |
| `git checkout -b` will work only when exactly one remote has a matching | |
| branch. --> | |
| <exec command="git checkout -b ${deploy.branch} ${remoteName}/${deploy.branch}" dir="${deploy.dir}" logoutput="true" passthru="true"/> | |
| </target> | |
| <target name="deploy:artifact:build" description="Generates a deploy-ready build in deploy.dir." | |
| depends="deploy:artifact:make, deploy:artifact:sanitize, frontend:build, deploy:artifact:copy"> | |
| </target> | |
| <!-- Clean the deploy directory. --> | |
| <target name="deploy:artifact:clean" description="Cleans the deploy directory."> | |
| <delete dir="${deploy.dir}/docroot" failonerror="false" quiet="true" /> | |
| <delete dir="${deploy.dir}/hooks" failonerror="false" quiet="true" /> | |
| </target> | |
| <target name="deploy:artifact:copy" description="Copy required files from /sites to /docroot/sites."> | |
| <!-- Copy modules and themes into deploy directory. --> | |
| <copy todir="${deploy.dir}/docroot/sites/all/modules/custom" overwrite="true"> | |
| <fileset dir="${repo.root}/sites/all/modules/custom"/> | |
| </copy> | |
| <copy todir="${deploy.dir}/docroot/sites/all/themes/custom" overwrite="true"> | |
| <fileset dir="${repo.root}/sites/all/themes/custom"> | |
| <include name="**"></include> | |
| <exclude name="**/node_modules/**"></exclude> | |
| <exclude name="**/bower_components/**"></exclude> | |
| </fileset> | |
| </copy> | |
| <copy todir="${deploy.dir}/docroot/profiles" overwrite="true"> | |
| <fileset dir="${repo.root}/profiles"/> | |
| </copy> | |
| <copy todir="${deploy.dir}/docroot/sites/default/settings" overwrite="true"> | |
| <fileset dir="${repo.root}/sites/default/settings"> | |
| <exclude name="**/local.settings.php"/> | |
| </fileset> | |
| </copy> | |
| <copy file="${repo.root}/sites/default/settings.php" tofile="${deploy.dir}/docroot/sites/default/settings.php" overwrite="true"/> | |
| <copy todir="${deploy.dir}/hooks" overwrite="true"> | |
| <fileset dir="${repo.root}/hooks"/> | |
| </copy> | |
| </target> | |
| <target name="deploy:artifact:make" description="Downloads core and contrib to deploy folder." depends="deploy:artifact:clean"> | |
| <drush command="make" assume="yes"> | |
| <param>"${repo.root}/${project.make_file}"</param> | |
| <param>"${deploy.dir}/docroot"</param> | |
| <option name="concurrency">8</option> | |
| <option name="no-gitinfofile"/> | |
| <option name="no-patch-txt"/> | |
| </drush> | |
| </target> | |
| <target name="deploy:artifact:push" description="Pushes to a git remote."> | |
| <exec command="echo ${deploy.remote} | openssl md5 | cut -d' ' -f 2" outputProperty="remoteName"/> | |
| <exec command="git push ${remoteName} ${deploy.branch}" dir="${deploy.dir}" logoutput="true" passthru="true" outputProperty="deploy.push.output"/> | |
| <exec command="export DEPLOY_UPTODATE=${echo '${deploy.push.output}' | grep --quiet 'Everything up-to-date'}"/> | |
| </target> | |
| <target name="deploy:artifact:sanitize" description="Removes sensitive files from the deploy docroot."> | |
| <delete> | |
| <fileset dir="${deploy.dir}/docroot"> | |
| <include name="CHANGELOG.txt"/> | |
| <include name="COPYRIGHT.txt"/> | |
| <include name="INSTALL.txt"/> | |
| <include name="INSTALL.*.txt"/> | |
| <include name="LICENSE.txt"/> | |
| <include name="PATCHES.txt"/> | |
| <include name="README.txt"/> | |
| <include name="UPGRADE.txt"/> | |
| </fileset> | |
| </delete> | |
| </target> | |
| </project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment