Skip to content

Commit 23cb3d2

Browse files
committed
Added deploy script to deploy github releases to wordpress.org plugin repo.
1 parent b266ae5 commit 23cb3d2

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

.circleci/deploy.sh

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/bash
2+
3+
set -eo
4+
5+
# SVN_USERNAME and SVN_PASSWORD should be saved as a private environment variables in CircleCI.
6+
# See https://circleci.com/docs/2.0/env-vars/#setting-an-environment-variable-in-a-project
7+
# See https://circleci.com/blog/keep-environment-variables-private-with-secret-masking/
8+
if [[ -z "$SVN_USERNAME" ]]; then
9+
echo "Missing SVN_USERNAME environment variable!"
10+
exit 1
11+
fi
12+
13+
if [[ -z "$SVN_PASSWORD" ]]; then
14+
echo "Missing SVN_PASSWORD environment variable!"
15+
exit 1
16+
fi
17+
18+
if [[ -z "$SVN_URL" ]]; then
19+
echo "Missing SVN_URL environment variable!"
20+
exit 1
21+
fi
22+
23+
# Extra check to ensure CircleCI provided the CIRCLE_TAG environment variable.
24+
# See https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables
25+
if [[ -z "$CIRCLE_TAG" ]]; then
26+
echo "Missing CIRCLE_TAG environment variable!"
27+
exit 1
28+
fi
29+
30+
VERSION="$CIRCLE_TAG"
31+
SVN_DIR="/tmp/svn/${CIRCLE_PROJECT_REPONAME}"
32+
33+
echo "Preparing for version $VERSION release..."
34+
35+
if [[ ! -d "$SVN_DIR" ]]; then
36+
mkdir -p "$SVN_DIR"
37+
echo "SVN directory $SVN_DIR created."
38+
fi
39+
40+
# Checkout just trunk and assets for efficiency.
41+
# Tagging will be handled on the SVN level.
42+
echo "Checking out svn repository..."
43+
svn checkout --depth immediates "$SVN_URL" "$SVN_DIR"
44+
cd "$SVN_DIR"
45+
svn update --set-depth infinity assets
46+
svn update --set-depth infinity trunk
47+
48+
echo "Copying files..."
49+
50+
if [[ -f "$CIRCLE_WORKING_DIRECTORY/.distignore" ]]; then
51+
# Copy from current branch to /trunk, excluding assets.
52+
# The --delete flag will delete anything in destination that no longer exists in source.
53+
rsync -rc --exclude-from="$CIRCLE_WORKING_DIRECTORY/.distignore" "$CIRCLE_WORKING_DIRECTORY/" trunk/ --delete --delete-excluded
54+
fi
55+
56+
# Copy assets to /assets as this was skipped in the previous step.
57+
if [[ -d "$CIRCLE_WORKING_DIRECTORY/assets/" ]]; then
58+
rsync -rc "$CIRCLE_WORKING_DIRECTORY/assets/" assets/ --delete
59+
fi
60+
61+
# Add everything and commit to SVN.
62+
# The force flag ensures we recurse into subdirectories even if they are already added.
63+
# Suppress stdout in favor of svn status later for readability.
64+
echo "Preparing files..."
65+
svn add . --force > /dev/null
66+
67+
# SVN delete all deleted files and suppress stdout.
68+
svn status | grep '^\!' | sed 's/! *//' | xargs -I% svn rm %@ > /dev/null
69+
70+
# Copy tag locally from trunk.
71+
echo "Copying tag..."
72+
svn cp "trunk" "tags/$VERSION"
73+
74+
svn status
75+
76+
echo "Committing files..."
77+
svn commit -m "Release version $VERSION." --no-auth-cache --non-interactive --username "$SVN_USERNAME" --password "$SVN_PASSWORD"
78+
79+
echo "Plugin release $VERSION deployed to $SVN_URL"

0 commit comments

Comments
 (0)