-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdeploy-wp.sh
executable file
·152 lines (129 loc) · 3.93 KB
/
deploy-wp.sh
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
146
147
148
149
150
151
152
#!/bin/bash
# Note that this does not use pipefail
# because if the grep later doesn't match any deleted files,
# which is likely the majority case,
# it does not exit with a 0, and I only care about the final exit.
# set -eo
help() {
echo "Usage: ./deploy-wp.sh [ -s | --slug ] Plugin slug.
[ -v | --version ] Plugin version.
[ -d | --dir ] Source files directory.
[ -u | --username ] WP.org username.
[ -p | --password ] WP.org password.
[ -m | --message ] Commit message.
[ -h | --help ]"
exit 2
}
while [ "$1" ]; do
case "$1" in
-s | --slug)
SLUG="$2"
shift 2
;;
-v | --version)
VERSION="$2"
shift 2
;;
-d | --dir)
SVN_SRC_DIR="$2"
shift 2
;;
-u | --username)
SVN_USERNAME="$2"
shift 2
;;
-p | --password)
SVN_PASSWORD="$2"
shift 2
;;
-m | --message)
COMMIT_MSG="$2"
shift 2
;;
-h | --help)
help
;;
--)
shift
break
;;
*)
echo "Unexpected option: $1"
help
;;
esac
done
while [[ -z "$SLUG" ]]; do
read -p 'Plugin slug: ' SLUG
done
while [[ -z "$VERSION" ]]; do
read -p 'Plugin version: ' VERSION
done
while [ -z "$SVN_SRC_DIR" ] || [ ! -d "$SVN_SRC_DIR" ]; do
read -p 'Source directory: ' SVN_SRC_DIR
if [ -d "$SVN_SRC_DIR" ]; then
SVN_SRC_DIR=$(cd "$SVN_SRC_DIR"; pwd)
fi
done
while [[ -z "$SVN_USERNAME" ]]; do
read -p 'SVN username: ' SVN_USERNAME
done
while [[ -z "$SVN_PASSWORD" ]]; do
read -s -p 'SVN password: ' SVN_PASSWORD
echo
done
while [[ -z "$COMMIT_MSG" ]]; do
read -e -p "Commit message: " -i "Update to version $VERSION" COMMIT_MSG
done
SVN_URL="https://plugins.svn.wordpress.org/${SLUG}/"
SVN_LOCAL_DIR="${HOME}/.deploy-wp/plugins/${SLUG}"
echo "Plugin slug: $SLUG"
echo "Plugin version: $VERSION"
echo "SVN Source directory: $SVN_SRC_DIR"
echo "SVN username: $SVN_USERNAME"
echo "SVN password: *****"
echo "SVN URL: $SVN_URL"
echo "SVN local directory: $SVN_LOCAL_DIR"
echo "Commit message: $COMMIT_MSG"
# Checkout just trunk and assets for efficiency
# Tagging will be handled on the SVN level
echo "➤ Checking out .org repository..."
svn checkout --depth immediates "$SVN_URL" "$SVN_LOCAL_DIR"
cd "$SVN_LOCAL_DIR" || exit
svn update --set-depth infinity tags
svn update --set-depth infinity trunk
if [ -d "$SVN_LOCAL_DIR/tags/$VERSION" ]; then
while true; do
read -p "Tags version $VERSION is already exists. Do you want to override? " yn
case $yn in
[Yy]*) break ;;
[Nn]*) exit ;;
*) echo "Please answer yes or no." ;;
esac
done
fi
echo "➤ Copying files from source directory..."
# Copy from source directory to /trunk
# The --delete flag will delete anything in destination that no longer exists in source
rsync -rc "$SVN_SRC_DIR/" "$SVN_LOCAL_DIR/trunk/" --delete --delete-excluded
# Copy tag locally to make this a single commit
echo "➤ Copying tag..."
rsync -rc "$SVN_LOCAL_DIR/trunk/" "$SVN_LOCAL_DIR/tags/$VERSION/" --delete --delete-excluded
# Add everything and commit to SVN
# The force flag ensures we recurse into subdirectories even if they are already added
# Suppress stdout in favor of svn status later for readability
echo "➤ Staging changes..."
svn add . --force >/dev/null
# SVN delete all deleted files
# Also suppress stdout here
svn status | grep '^\!' | sed 's/! *//' | xargs -I% svn rm %@ >/dev/null
if [ -z "$(svn status)" ]; then
echo "✗ Nothing to commit, working tree clean"
exit 1
fi
if [[ -z "$COMMIT_MSG" ]]; then
COMMIT_MSG="Update to version $VERSION"
fi
echo "➤ Committing changes..."
svn commit -m "$COMMIT_MSG" --no-auth-cache --non-interactive --username "$SVN_USERNAME" --password "$SVN_PASSWORD"
echo "✓ Plugin deployed!"