-
Notifications
You must be signed in to change notification settings - Fork 4
/
release-wporg.sh
executable file
·49 lines (37 loc) · 1.66 KB
/
release-wporg.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
#!/usr/bin/env bash
# Release the latest version on wordpress.org plugin repository.
# To be run as part of CI workflow.
# Assumptions:
# - repository name matches the wordpress.org plugin name or WP_ORG_PLUGIN_NAME is set,
# - there is a `release` directory with the folder containing the files and named as the plugin in it
# Partially adapted from https://carlalexander.ca/continuous-deployment-wordpress-directory-circleci/
SVN_PLUGINS_URL="https://plugins.svn.wordpress.org"
SVN_REPO_LOCAL_PATH="release/svn"
WP_ORG_PLUGIN_NAME="${WP_ORG_PLUGIN_NAME:=$CIRCLE_PROJECT_REPONAME}"
SVN_REPO_URL="$SVN_PLUGINS_URL/$WP_ORG_PLUGIN_NAME"
LATEST_GIT_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
# Remove the "v" at the beginning of the git tag
LATEST_SVN_TAG=${LATEST_GIT_TAG:1}
mkdir -p $SVN_REPO_LOCAL_PATH && cd $SVN_REPO_LOCAL_PATH
sudo apt-get update
sudo apt-get install subversion
# Check if the latest SVN tag exists already
TAG=$(svn ls "$SVN_REPO_URL/tags/$LATEST_SVN_TAG")
error=$?
if [ $error == 0 ]; then
# Tag exists, don't deploy
echo "Latest tag ($LATEST_SVN_TAG) already exists on the WordPress directory. No deployment needed!"
exit 0
fi
# Wait a moment to avoid a 429 by WPORG's server.
sleep 3
svn checkout -q "$SVN_REPO_URL" .
rm -rf trunk
cp -r "../$CIRCLE_PROJECT_REPONAME" ./trunk
cp -r ./trunk "./tags/$LATEST_SVN_TAG"
# Add new files to SVN
svn stat | grep '^?' | awk '{print $2}' | xargs -I x svn add x@
# Remove deleted files from SVN
svn stat | grep '^!' | awk '{print $2}' | xargs -I x svn rm --force x@
# Commit to SVN
svn ci --no-auth-cache --username $WP_ORG_USERNAME --password $WP_ORG_PASSWORD -m "Deploy version $LATEST_SVN_TAG"