Drafting a release with a script

Continuing the discussion from Link to latest plugin release:

This is the script I use to create the zip file and draft a release on GitHub.
Don’t consider it good, safe or anything else, it’s just something working good for me…

#!/usr/bin/env bash
set -e


slug=`basename $dir`


version=`wp --allow-root eval '$v = get_plugin_data( "'${phpfile}'" ); echo $v["Version"];'`

readmeversion=`wp --allow-root eval '$v = get_plugin_data( "readme.txt" ); echo $v["Version"];'`

downloadlink=`cat readme.txt | grep -E '^Download link:' | \
	grep -oE 'download/[^/]+/' | \
	grep -oE '/[^/]+/'`


echo "Download link version : ${downloadversion}"
echo "Readme.txt version    : v${readmeversion}"
echo "Going to release      : v${version}"

read -n 1 -s -r -p "If OK, press any key to continue (CTRL-C to exit)."

git archive -o "../${slug}.zip" HEAD

hub release create -d -a "../${slug}.zip" -m "v${version}" "v${version}"

rm "../${slug}.zip"

If you don’t want some files to go in the zip file (GitHub things,…) you can create a file named .gitattributes.
Example content:

.github export-ignore
.gitattributes export-ignore

You’ll want to add something like this to the beginning of the script:

cd "$(dirname "$0")"

Or if your script lives inside a subfolder of your plugin, like bin/build-plugin.sh:

cd "$(dirname "$0")"
cd ..

This will ensure that the script can be run from any directory without causing errors.

The next thing you will probably want to do is check, at the beginning of the script, for any required programs. This will avoid aborted script runs with unhelpful error messages later on in the process:

for p in wp git hub; do
    if ! type -t $p > /dev/null; then
        echo "Program/function \`$p\` not found, make sure it is installed!" >&2
        exit 1

Finally I would recommend not trying to make scripts like this generic for any plugin. It usually ends up a lot simpler if you just write the script specifically for your current plugin. As one example of why, it looks like this script requires the plugin’s folder to be part of a live site, but this probably shouldn’t be required in order to build a plugin.

Here’s the script we use to release new versions of the migration plugin: https://github.com/ClassicPress/ClassicPress-Migration-Plugin/blob/f1b0f23b3f55401299e2ef11ed697bca98995b01/bin/build-plugin-zip.sh

It is very simple. Using hub to create the release automatically would be a good addition, and also making sure the zip program exists beforehand would be a good idea.

I did not know about this! I wonder if it also works when you let GitHub build your zip files for you…


Thanks @james for your suggestions… I’ll work them out!

I know it is not the better way to do those things, but for now I’m developing plugins on a “live” (or better call it a test) site and so the environment is always inside a running ClassicPress on the same VPS.

.gitattributes is a nice piece of git that can do (but I’ve not deeply studied this) many nice things, like fixing linefeeds and others. When you “download ZIP” from GitHub it works.


This is totally fine, it just shouldn’t be required in order to build the plugin!