forked from hypothesis/wp-hypothesis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·98 lines (78 loc) · 2.61 KB
/
deploy.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
#!/usr/bin/env bash
if [[ -z "$TRAVIS" ]]; then
echo "Script is only to be run by Travis CI" 1>&2
exit 1
fi
if [[ -z "$WP_ORG_USERNAME" ]]; then
echo "WordPress.org username not set" 1>&2
exit 1
fi
if [[ -z "$WP_ORG_PASSWORD" ]]; then
echo "WordPress.org password not set" 1>&2
exit 1
fi
if [[ -z "$TRAVIS_TAG" ]]; then
echo "Build tag is required" 1>&2
exit 0
fi
PLUGIN="hypothesis"
PROJECT_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
PLUGIN_BUILDS_PATH="$PROJECT_ROOT/builds"
VERSION=$(php -f "$PROJECT_ROOT/bin/get_plugin_version.php" "$PROJECT_ROOT" "$PLUGIN")
BUILD_DIRECTORY="$PLUGIN_BUILDS_PATH/$PLUGIN-$VERSION"
# Ensure the current version has been built
if [ ! -d "$BUILD_DIRECTORY" ]; then
echo "Built plugin directory $BUILD_DIRECTORY does not exist" 1>&2
exit 1
fi
# Check if the tag exists for the version we are building
TAG=$(svn ls "https://plugins.svn.wordpress.org/$PLUGIN/tags/$VERSION")
error=$?
if [ $error == 0 ]; then
# Tag exists, don't deploy
echo "Tag already exists for version $VERSION, skipping deployment"
exit 1
fi
cd "$PLUGIN_BUILDS_PATH"
# Clean up any previous svn dir
rm -fR svn
# Checkout the SVN repo
svn co -q "http://[email protected]/$PLUGIN" svn
# Move out the trunk directory to a temp location
mv svn/trunk ./svn-trunk
# Create trunk directory
mkdir svn/trunk
# Copy our new version of the plugin into trunk
rsync -r -p $BUILD_DIRECTORY/* svn/trunk
# Copy all the .svn folders from the checked out copy of trunk to the new trunk.
# This is necessary as the Travis container runs Subversion 1.6 which has .svn dirs in every sub dir
cd svn/trunk/
TARGET=$(pwd)
cd ../../svn-trunk/
# Find all .svn dirs in sub dirs
SVN_DIRS=`find . -type d -iname .svn`
for SVN_DIR in $SVN_DIRS; do
SOURCE_DIR=${SVN_DIR/.}
TARGET_DIR=$TARGET${SOURCE_DIR/.svn}
TARGET_SVN_DIR=$TARGET${SVN_DIR/.}
if [ -d "$TARGET_DIR" ]; then
# Copy the .svn directory to trunk dir
cp -r $SVN_DIR $TARGET_SVN_DIR
fi
done
# Back to builds dir
cd ../
# Remove checked out dir
rm -fR svn-trunk
# Add new version tag
mkdir svn/tags/$VERSION
rsync -r -p $BUILD_DIRECTORY/* svn/tags/$VERSION
# Add new files to SVN
svn stat svn | grep '^?' | awk '{print $2}' | xargs -I x svn add x@
# Remove deleted files from SVN
svn stat svn | grep '^!' | awk '{print $2}' | xargs -I x svn rm --force x@
svn stat svn
# Commit to SVN
cd svn && svn commit -m "Deploy version $VERSION" --no-auth-cache --non-interactive --username "$WP_ORG_USERNAME" --password "$WP_ORG_PASSWORD"
# Remove SVN temp dir
cd "$PLUGIN_BUILDS_PATH" && rm -fR svn