Skip to content

Commit ee86eb0

Browse files
authored
Merge pull request #265 from wpengine/ryanmeier/circleci-deployment
[PI-3517] Add Deployment Job and Script
2 parents ab7f3e8 + 3309dad commit ee86eb0

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

.circleci/config.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,22 @@ jobs:
132132
environment:
133133
CONTAINER_WP_VERSION: "latest"
134134
CONTAINER_PHP_VERSION: "7.3"
135+
deploy_job:
136+
docker:
137+
- image: circleci/buildpack-deps:latest
138+
steps:
139+
- checkout
140+
- run:
141+
name: Install dependencies
142+
command: sudo apt-get install rsync -qq
143+
- run:
144+
name: Create artifacts directory
145+
command: mkdir -p /tmp/artifacts
146+
- run:
147+
name: Deploy plugin to wordpress.org
148+
command: /bin/bash .circleci/deploy.sh
149+
- store_artifacts:
150+
path: /tmp/artifacts
135151

136152
workflows:
137153
version: 2

.circleci/deploy.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
3+
set -eo
4+
5+
# SVN_USERNAME, SVN_PASSWORD, and SVN_URL should be saved as a private environment variables.
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+
SVN_DIR="/tmp/artifacts"
31+
PROJECT_DIR=$(pwd)
32+
33+
echo "Preparing for version $CIRCLE_TAG release..."
34+
35+
# Checkout just trunk and assets for efficiency.
36+
# Tagging will be handled on the SVN level.
37+
echo "Checking out svn repository..."
38+
svn checkout --depth immediates "$SVN_URL" "$SVN_DIR"
39+
cd "$SVN_DIR"
40+
svn update --set-depth infinity assets
41+
svn update --set-depth infinity trunk
42+
43+
echo "Copying files..."
44+
45+
if [[ -f "$PROJECT_DIR/.distignore" ]]; then
46+
rsync -rc --exclude-from="$PROJECT_DIR/.distignore" "$PROJECT_DIR/" trunk/ --delete --delete-excluded
47+
fi
48+
49+
# Copy assets to /assets.
50+
if [[ -d "$PROJECT_DIR/assets/" ]]; then
51+
rsync -rc "$PROJECT_DIR/assets/" assets/ --delete
52+
fi
53+
54+
# Add everything and commit to SVN.
55+
# The force flag ensures we recurse into subdirectories even if they are already added.
56+
# Suppress stdout in favor of svn status later for readability.
57+
echo "Preparing files..."
58+
svn add . --force > /dev/null
59+
60+
# SVN delete all deleted files and suppress stdout.
61+
svn status | grep '^\!' | sed 's/! *//' | xargs -I% svn rm %@ > /dev/null
62+
63+
# Copy trunk into the current tag directory.
64+
echo "Copying tag..."
65+
svn cp "trunk" "tags/$CIRCLE_TAG"
66+
67+
svn status
68+
69+
echo "Committing files..."
70+
svn commit -m "Release version $CIRCLE_TAG." --no-auth-cache --non-interactive --username "$SVN_USERNAME" --password "$SVN_PASSWORD"
71+
72+
echo "Plugin version $CIRCLE_TAG deployed."

0 commit comments

Comments
 (0)