This repository was archived by the owner on Jul 19, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathdeploy.sh
More file actions
140 lines (113 loc) · 4.07 KB
/
Copy pathdeploy.sh
File metadata and controls
140 lines (113 loc) · 4.07 KB
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
#!/bin/bash
# If any commands fail (exit code other than 0) entire script exits
set -e
# Check for required environment variables and make sure they are setup
: ${PROJECT_TYPE?"PROJECT_TYPE Missing"} # theme|plugin
: ${WPE_INSTALL?"WPE_INSTALL Missing"} # subdomain for wpengine install (Legacy single environment setup)
: ${REPO_NAME?"REPO_NAME Missing"} # repo name (Typically the folder name of the project)
# Set repo based on current branch, by default master=production, develop=staging
# @todo support custom branches
# This is considered legacy wpengine setup and should be deprecated. We'll keep this workflow in place for backwards compatibility.
target_wpe_install=${WPE_INSTALL}
if [[ "$CI_BRANCH" == "master" && -n "$WPE_INSTALL" ]]
then
repo=production
else
if [[ "$CI_BRANCH" == "develop" && -n "$WPE_INSTALL" ]]
then
repo=staging
fi
fi
# In WP Engine's multi-environment setup, we'll target each instance based on branch with variables to designate them individually.
if [[ "$CI_BRANCH" == "master" && -n "$WPE_INSTALL_PROD" ]]
then
target_wpe_install=${WPE_INSTALL_PROD}
repo=production
fi
if [[ "$CI_BRANCH" == "staging" && -n "$WPE_INSTALL_STAGE" ]]
then
target_wpe_install=${WPE_INSTALL_STAGE}
repo=production
fi
if [[ "$CI_BRANCH" == "develop" && -n "$WPE_INSTALL_DEV" ]]
then
target_wpe_install=${WPE_INSTALL_DEV}
repo=production
fi
echo -e "Install: ${WPE_INSTALL_PROD} or ${WPE_INSTALL}"
echo -e "Repo: ${repo}"
# Begin from the ~/clone directory
# this directory is the default your git project is checked out into by Codeship.
cd ~/clone
# Get official list of files/folders that are not meant to be on production if $EXCLUDE_LIST is not set.
if [[ -z "${EXCLUDE_LIST}" ]]; then
wget https://raw.githubusercontent.com/linchpin/wpengine-codeship-continuous-deployment/master/exclude-list.txt
else
# @todo validate proper url?
wget ${EXCLUDE_LIST}
fi
# Loop over list of files/folders and remove them from deployment
ITEMS=`cat exclude-list.txt`
for ITEM in $ITEMS; do
if [[ "$ITEM" == *.* ]]
then
find . -depth -name "$ITEM" -type f -exec rm "{}" \;
else
find . -depth -name "$ITEM" -type d -exec rm -rf "{}" \;
fi
done
# Remove exclude-list file
rm exclude-list.txt
# go back home
cd ~
# Clone the WPEngine files to the deployment directory
# if we are not force pushing our changes
if [[ "$CI_MESSAGE" != *#force* ]]
then
force=''
git clone git@git.wpengine.com:${repo}/${target_wpe_install}.git ./deployment
else
force='-f'
fi
# If there was a problem cloning, exit
if [ "$?" != "0" ] ; then
echo "Unable to clone ${repo}"
kill -SIGINT $$
fi
cd ~ # go back home
# check to see if we have a deployment folder, if so change directory to it. If not make the directory an initialize a git repo
if [ ! -d ./deployment ]; then
mkdir ./deployment
cd ./deployment
git init
else
cd ./deployment
fi
# Move the gitignore file to the deployments folder
wget --output-document=.gitignore https://raw.githubusercontent.com/linchpin/wpengine-codeship-continuous-deployment/master/gitignore-template.txt
# Delete plugin/theme if it exists, and move cleaned version into deployment folder
rm -rf ./wp-content/${PROJECT_TYPE}s/${REPO_NAME}
# Check to see if the wp-content directory exists, if not create it
if [ ! -d ./wp-content ];
then
mkdir ./wp-content
fi
# Check to see if the plugins directory exists, if not create it
if [ ! -d ./wp-content/plugins ];
then
mkdir ./wp-content/plugins
fi
# Check to see if the themes directory exists, if not create it
if [ ! -d ./wp-content/themes ];
then
mkdir ./wp-content/themes
fi
rsync -a ../clone/* ./wp-content/${PROJECT_TYPE}s/${REPO_NAME}
# Stage, commit, and push to wpengine repo
git remote add ${repo} git@git.wpengine.com:${repo}/${target_wpe_install}.git
git config --global user.email CI_COMMITTER_EMAIL
git config --global user.name CI_COMMITTER_NAME
git config core.ignorecase false
git add --all
git commit -am "Deployment to ${target_wpe_install} $repo by $CI_COMMITTER_NAME from $CI_NAME"
git push ${force} ${repo} master