|
| 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