|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +set -e |
| 4 | +clear |
| 5 | + |
| 6 | +# ASK INFO |
| 7 | +echo "---------------------------------------------------------------------" |
| 8 | +echo " GitHub to WordPress.org RELEASER " |
| 9 | +echo "---------------------------------------------------------------------" |
| 10 | +read -p "Enter the ROOT PATH of the plugin you want to release: " ROOT_PATH |
| 11 | +echo "---------------------------------------------------------------------" |
| 12 | +read -p "Tag and Release Version: " VERSION |
| 13 | +echo "---------------------------------------------------------------------" |
| 14 | +echo "" |
| 15 | +echo "Before continuing, confirm that you have done the following :" |
| 16 | +echo "" |
| 17 | +read -p " - Added a changelog for v"${VERSION}"?" |
| 18 | +read -p " - Set version in the readme.txt and main file to v"${VERSION}"?" |
| 19 | +read -p " - Set stable tag in the readme.txt file to v"${VERSION}"?" |
| 20 | +read -p " - Updated the POT file?" |
| 21 | +read -p " - Committed all changes up to GitHub?" |
| 22 | +echo "" |
| 23 | +read -p "Press [ENTER] to begin releasing v"${VERSION} |
| 24 | +clear |
| 25 | + |
| 26 | +# Check if version is already released. |
| 27 | +if $ROOT_PATH git show-ref --tags | egrep -q "refs/tags/v${VERSION}" |
| 28 | +then |
| 29 | + echo "Version already tagged and released."; |
| 30 | + echo "" |
| 31 | + echo "Run sh release.sh again and enter another version."; |
| 32 | + exit 1; |
| 33 | +else |
| 34 | + echo "" |
| 35 | + echo "v${VERSION} has not been found released."; |
| 36 | +fi |
| 37 | + |
| 38 | +read -p "Enter the WordPress plugin slug: " SVN_REPO_SLUG |
| 39 | +clear |
| 40 | + |
| 41 | +echo "Now processing..." |
| 42 | + |
| 43 | +SVN_REPO_URL="https://plugins.svn.wordpress.org" |
| 44 | + |
| 45 | +# Set WordPress.org Plugin URL |
| 46 | +SVN_REPO=$SVN_REPO_URL"/"$SVN_REPO_SLUG"/" |
| 47 | + |
| 48 | +# Set temporary SVN folder for WordPress release. |
| 49 | +TEMP_SVN_REPO=${SVN_REPO_SLUG}"-svn" |
| 50 | + |
| 51 | +# Delete old SVN cache just incase it was not cleaned before after the last release. |
| 52 | +rm -Rf $ROOT_PATH$TEMP_SVN_REPO |
| 53 | + |
| 54 | +# CHECKOUT SVN DIR IF NOT EXISTS |
| 55 | +if [[ ! -d $TEMP_SVN_REPO ]]; |
| 56 | +then |
| 57 | + echo "Checking out WordPress.org plugin repository." |
| 58 | + svn checkout $SVN_REPO $TEMP_SVN_REPO || { echo "Unable to checkout repo."; exit 1; } |
| 59 | +fi |
| 60 | + |
| 61 | +read -p "Enter your GitHub username: " GITHUB_USER |
| 62 | +clear |
| 63 | + |
| 64 | +read -p "Now enter the repository slug: " GITHUB_REPO_NAME |
| 65 | +clear |
| 66 | + |
| 67 | +# Set temporary folder for GitHub release. |
| 68 | +TEMP_GITHUB_REPO=${GITHUB_REPO_NAME}"-git" |
| 69 | + |
| 70 | +# Delete old GitHub cache just incase it was not cleaned before after the last release. |
| 71 | +rm -Rf $ROOT_PATH$TEMP_GITHUB_REPO |
| 72 | + |
| 73 | +# Set GitHub Repository URL |
| 74 | +GIT_REPO="https://github.com/"${GITHUB_USER}"/"${GITHUB_REPO_NAME}".git" |
| 75 | + |
| 76 | +# CLONE GIT DIR |
| 77 | +echo "Cloning GIT repository from GitHub" |
| 78 | +git clone --progress $GIT_REPO $TEMP_GITHUB_REPO || { echo "Unable to clone repo."; exit 1; } |
| 79 | + |
| 80 | +# MOVE INTO GIT DIR |
| 81 | +cd $ROOT_PATH$TEMP_GITHUB_REPO |
| 82 | + |
| 83 | +# LIST BRANCHES |
| 84 | +clear |
| 85 | +git fetch origin |
| 86 | +echo "Which branch do you wish to release?" |
| 87 | +git branch -r || { echo "Unable to list branches."; exit 1; } |
| 88 | +echo "" |
| 89 | +read -p "origin/" BRANCH |
| 90 | + |
| 91 | +# Switch Branch |
| 92 | +echo "Switching to branch" |
| 93 | +git checkout ${BRANCH} || { echo "Unable to checkout branch."; exit 1; } |
| 94 | + |
| 95 | +echo "" |
| 96 | +read -p "Press [ENTER] to deploy branch "${BRANCH} |
| 97 | + |
| 98 | +# REMOVE UNWANTED FILES & FOLDERS |
| 99 | +echo "Removing unwanted files" |
| 100 | +rm -Rf .git |
| 101 | +rm -Rf .github |
| 102 | +rm -Rf tests |
| 103 | +rm -Rf apigen |
| 104 | +rm -f .gitattributes |
| 105 | +rm -f .gitignore |
| 106 | +rm -f .gitmodules |
| 107 | +rm -f .travis.yml |
| 108 | +rm -f Gruntfile.js |
| 109 | +rm -f package.json |
| 110 | +rm -f .jscrsrc |
| 111 | +rm -f .jshintrc |
| 112 | +rm -f composer.json |
| 113 | +rm -f phpunit.xml |
| 114 | +rm -f phpunit.xml.dist |
| 115 | +rm -f README.md |
| 116 | +rm -f .coveralls.yml |
| 117 | +rm -f .editorconfig |
| 118 | +rm -f .scrutinizer.yml |
| 119 | +rm -f apigen.neon |
| 120 | +rm -f CHANGELOG.md |
| 121 | +rm -f CONTRIBUTING.md |
| 122 | +rm -f Theme-Presets.md |
| 123 | +rm -f screenshot-*.png |
| 124 | +rm -f release.sh |
| 125 | + |
| 126 | +# MOVE INTO SVN DIR |
| 127 | +cd "../"$TEMP_SVN_REPO |
| 128 | + |
| 129 | +# UPDATE SVN |
| 130 | +echo "Updating SVN" |
| 131 | +svn update || { echo "Unable to update SVN."; exit 1; } |
| 132 | + |
| 133 | +# DELETE TRUNK |
| 134 | +echo "Replacing trunk" |
| 135 | +rm -Rf trunk/ |
| 136 | + |
| 137 | +# COPY GIT DIR TO TRUNK |
| 138 | +cp -R "../"$TEMP_GITHUB_REPO trunk/ |
| 139 | + |
| 140 | +# DO THE ADD ALL NOT KNOWN FILES UNIX COMMAND |
| 141 | +svn add --force * --auto-props --parents --depth infinity -q |
| 142 | + |
| 143 | +# DO THE REMOVE ALL DELETED FILES UNIX COMMAND |
| 144 | +MISSING_PATHS=$( svn status | sed -e '/^!/!d' -e 's/^!//' ) |
| 145 | + |
| 146 | +# iterate over filepaths |
| 147 | +for MISSING_PATH in $MISSING_PATHS; do |
| 148 | + svn rm --force "$MISSING_PATH" |
| 149 | +done |
| 150 | + |
| 151 | +# COPY TRUNK TO TAGS/$VERSION |
| 152 | +echo "Copying trunk to new tag" |
| 153 | +svn copy trunk tags/${VERSION} || { echo "Unable to create tag."; exit 1; } |
| 154 | + |
| 155 | +# DO SVN COMMIT |
| 156 | +clear |
| 157 | +echo "Showing SVN status" |
| 158 | +svn status |
| 159 | + |
| 160 | +# PROMPT USER |
| 161 | +echo "" |
| 162 | +read -p "Press [ENTER] to commit release "${VERSION}" to WordPress.org AND GitHub" |
| 163 | +echo "" |
| 164 | + |
| 165 | +# CREATE THE GITHUB RELEASE |
| 166 | +echo "Creating release on GitHub repository." |
| 167 | +cd "$GITPATH" |
| 168 | + |
| 169 | +echo "Tagging new version in git" |
| 170 | +git tag -a "v${VERSION}" -m "Tagging version v${VERSION}" |
| 171 | + |
| 172 | +echo "Pushing latest commit to origin, with tags" |
| 173 | +git push origin master |
| 174 | +git push origin master --tags |
| 175 | + |
| 176 | +# DEPLOY |
| 177 | +echo "" |
| 178 | +echo "Committing to WordPress.org... this may take a while..." |
| 179 | +svn commit -m "Releasing "${VERSION}"" || { echo "Unable to commit."; exit 1; } |
| 180 | + |
| 181 | +# REMOVE THE TEMP DIRS |
| 182 | +echo "Cleaning Up..." |
| 183 | +cd "../" |
| 184 | +rm -Rf $ROOT_PATH$TEMP_GITHUB_REPO |
| 185 | +rm -Rf $ROOT_PATH$TEMP_SVN_REPO |
| 186 | + |
| 187 | +# DONE |
| 188 | +echo "Release Done." |
| 189 | +echo "" |
| 190 | +read -p "Press [ENTER] to close program." |
| 191 | + |
| 192 | +clear |
0 commit comments