This repository was archived by the owner on Mar 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 394
/
Copy pathdeploy.xml
145 lines (118 loc) · 6.79 KB
/
deploy.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<project name="deploy" default="deploy">
<target name="deploy" description="Builds separate artifact and pushes to git.remotes defined project.yml.">
<!-- Check necessary runtime parameters. -->
<if>
<or>
<not><isset property="deploy.commitMsg"/></not>
<not><isset property="deploy.branch"/></not>
</or>
<then>
<echo message="You must pass deploy.commitMsg and deploy.branch as runtime parameters."/>
<echo message="Command should match syntax:"/>
<echo message="./blt.sh deploy -Ddeploy.commitMsg='BLT-123: The commit message.' -Ddeploy.branch='master-build'"/>
<fail message="Missing required parameters."/>
</then>
</if>
<!-- Delete the existing deploy directory and re-initialize as an empty git repository. -->
<phingcall target="deploy:prepare-dir"/>
<!-- Add remotes and fetch upstream refs. Checkout local branch tracking
tracking upstream branch, if it exists. Otherwise create new branch
locally. -->
<phingcall target="deploy:add-remotes"/>
<!-- Build artifact and commit locally. -->
<phingcall target="deploy:build"/>
<!--Allow custom commands to be run before commit.-->
<phingcall target="task:execute">
<property name="task-name" value="deploy"/>
</phingcall>
<!--Commit artifact. -->
<phingcall target="deploy:commit"/>
<!-- Push up changes to remotes if this is not a dry run.-->
<if>
<not><isset property="deploy.dryRun"/></not>
<then>
<phingcall target="deploy:push-all"/>
</then>
</if>
</target>
<target name="deploy:remote:add" description="Adds a git remote and checks out deploy branch from upstream.">
<echo message="Fetching from git remote ${deploy.remote}"/>
<!-- Generate an md5 sum of the remote URL to use as remote name. -->
<exec command="echo ${deploy.remote} | openssl md5 | cut -d' ' -f 2" outputProperty="remoteName" checkreturn="true"/>
<exec command="git remote add ${remoteName} ${deploy.remote}" dir="${deploy.dir}" logoutput="true" passthru="true" checkreturn="true"/>
<!-- @todo Only call this for the first remote. -->
<phingcall target="deploy:remote:pull" />
</target>
<target name="deploy:remote:pull" description="Checks out deploy branch from upstream remote.">
<exec command="git fetch ${remoteName} ${deploy.branch}" dir="${deploy.dir}" logoutput="true" passthru="true"/>
<!-- Create the new branch, "[source-branch-name]-build". -->
<exec command="git checkout -b ${deploy.branch}" dir="${deploy.dir}" logoutput="true" passthru="true" checkreturn="true"/>
<!-- Pull the latest updates (if available). -->
<exec command="git merge ${remoteName}/${deploy.branch}" dir="${deploy.dir}" logoutput="true" passthru="true"/>
</target>
<target name="deploy:add-remotes" description="Add remotes and fetch upstream refs.">
<foreach list="${git.remotes}" param="deploy.remote" target="deploy:remote:add"/>
</target>
<target name="deploy:build" description="Generates a deploy-ready build in deploy.dir."
depends="frontend:build, deploy:copy, deploy:composer:install, deploy:sanitize">
<!-- If we are using ACSF, run the ACSF Deploy command. -->
<if>
<equals arg1="${hosting}" arg2="acsf"/>
<then>
<phingcall target="deploy:acsf:init"/>
</then>
</if>
</target>
<target name="deploy:commit">
<!-- We make these commands quiet because they can cause the output to be so long that Travis CI stops logging. -->
<exec command="git add -A" dir="${deploy.dir}" logoutput="true" passthru="true" checkreturn="true"/>
<exec command="git commit -m '${deploy.commitMsg}' --quiet" dir="${deploy.dir}" logoutput="true" passthru="true" checkreturn="true"/>
</target>
<target name="deploy:composer:install" description="Downloads core and contrib to deploy folder.">
<delete dir="${deploy.dir}/vendor"/>
<copy todir="${deploy.dir}" overwrite="true">
<fileset dir="${repo.root}">
<include name="composer.json"/>
<include name="composer.lock"/>
</fileset>
</copy>
<exec dir="${deploy.dir}" command="export COMPOSER_EXIT_ON_PATCH_FAILURE=1; composer install --no-dev --prefer-dist --no-interaction" passthru="true" logoutput="true" checkreturn="true"/>
</target>
<target name="deploy:copy" description="Copy required files from /docroot/sites to /deploy/docroot/sites.">
<!-- Make sites/default writable so that we can copy files. -->
<!-- @todo Support multisite. -->
<chmod file="${docroot}/sites/default" mode="0777" />
<exec dir="${repo.root}" command="rsync -a --no-g --no-p --delete --delete-excluded --exclude-from=${deploy.exclude_file} ${repo.root}/ ${deploy.dir}/ --filter 'protect /.git/'" logoutput="true" checkreturn="true"/>
<!-- Use our own .gitignore -->
<copy file="${repo.root}/build/core/files/.gitignore" tofile="${deploy.dir}/.gitignore" overwrite="true"/>
<!-- Set sites/default back to 755 permissions. -->
<!-- @todo Support multisite. -->
<chmod file="${docroot}/sites/default" mode="0755" />
</target>
<target name="deploy:prepare-dir" description="Delete the existing deploy directory and re-initialize as an empty git repository.">
<delete dir="${deploy.dir}" failonerror="false" quiet="true" />
<exec command="git init ${deploy.dir}" logoutput="true" checkreturn="true"/>
</target>
<target name="deploy:push-all">
<foreach list="${git.remotes}" param="deploy.remote" target="deploy:push-remote"/>
</target>
<target name="deploy:push-remote" 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" outputProperty="deploy.push.output" checkreturn="true"/>
<exec command="export DEPLOY_UPTODATE=$(echo '${deploy.push.output}' | grep --quiet 'Everything up-to-date')"/>
</target>
<target name="deploy:sanitize" description="Removes sensitive files from the deploy docroot.">
<exec command="find . -type d | grep .git | xargs rm -rf" dir="${deploy.dir}/docroot"/>
<exec command="find . -type d | grep .git | xargs rm -rf" dir="${deploy.dir}/vendor"/>
<delete>
<fileset dir="${deploy.dir}/docroot">
<include name="core/*.txt"/>
<include name="**/CHANGELOG.txt"/>
</fileset>
</delete>
</target>
<target name="deploy:acsf:init" description="Re-initialize ACSF with the settings.php changes required for artifact.">
<chmod file="${deploy.dir}/docroot/sites/default/settings.php" mode="0755" />
<exec dir="${deploy.dir}/docroot" command="${drush.bin} --include=${deploy.dir}/docroot/modules/contrib/acsf/acsf_init acsf-init -r ${deploy.dir}/docroot -y" logoutput="true" checkreturn="true"/>
</target>
</project>