Rumperuu
0a34e96450
This commit adds a release helper script, amongst other workflow improvements. See `README.md` for instructions, and `_tools/release.sh` for the script itself. This script: 1. sanity-checks the various version tags; 2. triggers a Plugin build; 3. flags the new version as pre-release; 4. tags the version in Git; 5. creates a local working copy of the SVN repo; 6. copies the new release to the local `trunk/` (whilst keeping the ‘Stable Tag’ field in `readme.txt` pointing to the previous stable version); 7. copies the commit message from the changelog in `readme.txt`; and 8. (if a flag is set) commits the changes to the remote `trunk/`. Pushing out a new release must still be done manually, once `trunk/` is tested and working. To do so, check out a local copy of `trunk/` and: 1. update the ‘Stable Tag’ field in `trunk/readme.txt` to the new version; 2. update the ‘Version’ field in the comment header of `trunk/footnotes.php` to the new version; 3. remove the ‘p’ from the end of the ‘version’ tag in the `getInfo()` function at the bottom of `js/wsiwyg-editor.js`; 4. copy a new tag for the release from `trunk/` (`svn cp trunk tags/<version number>`); and 5. commit your changes (`svn ci -m "Release version <version number>"`). The WP Plugin Directory will automatically parse the ‘Stable Tag’ field in `trunk/readme.txt`, and inform users that a new version is available. At various stages user input is required to validate information. This is not ready for automation with GitHub Actions, but is a useful step on the way — see [this piece](https://blog.danslimmon.com/2019/07/15/do-nothing-scripting-the-key-to-gradual-automation/) for more info. Unless a `-c` flag is passed (e.g., by running `composer run release:commit`) no changes will take place on the remote SVN repo. If you want to test this out on a branch other than `main`, uncomment lines 31 & 52 of the script. Version checking enforces the versioning rules stated [here](https://github.com/markcheret/footnotes/wiki/Versioning). **NB: I have not tested the `-c` mode yet, as I wanted people will more familiarity with the SVN to have a look at it before I risked making any changes and blowing everything up.** Co-authored-by: pewgeuges <73141620+pewgeuges@users.noreply.github.com>
246 lines
8.7 KiB
Bash
Executable file
246 lines
8.7 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# This is a release helper script aimed at walking maintainers through the
|
|
# process of issuing new releases of the Plugin, both to reduce the risk of
|
|
# procedural errors and to provide a framework for future incremental
|
|
# automation.
|
|
#
|
|
# Step 1: Ensure the local copy has checked out the `main` branch
|
|
# Step 2: Ensure local copy of `main` is up-to-date with remote
|
|
# Step 3: Check versioning
|
|
# Step 3(a): Get all version declarations
|
|
# Step 3(b): Check that all version declarations exists
|
|
# Step 3(c)(1): Check that all development versions match
|
|
# Step 3(c)(2): Check that all stable versions match
|
|
# Step 3(d): Check that the development version is correctly flagged as such
|
|
# Step 3(e): Check that the 'Stable Tag' field is set to a stable version
|
|
# Step 3(f): Check that the 'Stable Tag' field points to a real tag on the SVN repo.
|
|
# Step 3(g): Check that the changelog is up-to-date
|
|
# Step 4: Build the Plugin
|
|
# Step 5: Update the version to pre-release
|
|
# Step 6: Tag the release
|
|
|
|
echo "Welcome to the footnotes release helper!"
|
|
echo "========================================"
|
|
|
|
if [[ $1 == "-c" ]]; then
|
|
read -p "You have passed the \`commit\` flag (\`-c\`). Did you mean to do this? (Y/N): " CONFIRM && [[ $CONFIRM == [yY] || $CONFIRM == [yY][eE][sS] ]] || exit 1
|
|
fi
|
|
|
|
# NB: To run on a branch other than `main`, uncomment this line:
|
|
#if false; then
|
|
|
|
# Step 1: Ensure the local copy has checked out the `main` branch
|
|
|
|
if [[ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]]; then
|
|
echo "ERR: You are not on the \`main\` branch, please check it out and re-run this command."
|
|
exit 1
|
|
else
|
|
echo "- \`main\` branch is checked out."
|
|
fi
|
|
|
|
# Step 2: Ensure local copy of `main` is up-to-date with remote
|
|
|
|
if [[ "$(git status | grep -c 'Your branch is up to date')" != 1 ]]; then
|
|
echo "ERR: Your local copy is not up-to-date with the remote, please update it and re-run this command."
|
|
exit 1
|
|
else
|
|
echo "- Local copy of \`main\` is up-to-date with remote."
|
|
fi
|
|
|
|
# NB: To run on a branch other than `main`, uncomment this line:
|
|
#fi
|
|
|
|
# Step 3: Check versioning
|
|
|
|
# Step 3(a): Get all version declarations
|
|
|
|
# NOTE: I'm not sure why, but if you try to get the root header
|
|
# version without piping it through the second `grep` command,
|
|
# you'll end up with a list of files before the version
|
|
# declaration.
|
|
|
|
echo "- Checking versions..."
|
|
|
|
STABLE_TAG="$(grep "Stable Tag:" readme.txt)"
|
|
ROOT_HEADER_VERSION="$(grep " Version:" footnotes.php | grep -Po " Version: \d+\.\d+(\.\d+)?[a-z]?$")"
|
|
JS_VERSION="$(grep "version :" js/wysiwyg-editor.js)"
|
|
|
|
# Step 3(b): Check that all version declarations exists
|
|
|
|
if [[ -z $STABLE_TAG ]]; then
|
|
echo "ERR: No 'Stable Tag' field found in \`readme.txt\`!"
|
|
exit 1
|
|
else echo "- 'Stable Tag' field set in \`readme.txt\`."
|
|
fi
|
|
if [[ -z $ROOT_HEADER_VERSION ]]; then
|
|
echo "ERR: No 'Version' field found in \`footnotes.php\` file header!"
|
|
exit 1
|
|
else echo "- 'Version' field set in \`footnotes.php\` file header."
|
|
fi
|
|
if [[ -z $JS_VERSION ]]; then
|
|
echo "ERR: No \`version\` variable found in \`js/wysiwyg-editor.js\`!"
|
|
exit 1
|
|
else echo "- \`version\` variable set in \`js/wysiwyg-editor.js\`."
|
|
fi
|
|
|
|
# Step 3(c)(1): Check that all development versions match
|
|
# NB: This doesn't currently do anything as there is only one place where the
|
|
# development version is listed.
|
|
|
|
if [[ "$(echo $JS_VERSION | grep -Poc '\d+\.\d+(\.\d+)?')" != 1 ]]; then
|
|
echo "ERR: Development version mismatch!"
|
|
echo -e "The following versions were found:\n"
|
|
echo -e '\t' $JS_VERSION '\n'
|
|
echo "Please ensure that all development versions match and re-run this command."
|
|
exit 1
|
|
else echo "- Development versions match."
|
|
fi
|
|
|
|
# Step 3(c)(2): Check that all stable versions match
|
|
|
|
if [[ "$(echo $ROOT_HEADER_VERSION $STABLE_TAG | grep -Poc '\d+\.\d+(\.\d+)?')" != 1 ]]; then
|
|
echo "ERR: Stable version mismatch!"
|
|
echo -e "The following versions were found:\n"
|
|
echo -e '\t' $ROOT_HEADER_VERSION
|
|
echo -e '\t' $STABLE_TAG '\n'
|
|
echo "Please ensure that all stable versions match and re-run this command."
|
|
exit 1
|
|
else echo "- Stable versions match."
|
|
fi
|
|
|
|
# Step 3(d): Check that the development version is correctly flagged as such
|
|
|
|
if [[ "$(echo $JS_VERSION | grep -Poc '\d+d')" != 1 ]]; then
|
|
echo "ERR: Development version flag not set!"
|
|
echo -e "The following version was found:\n"
|
|
echo -e '\t' $JS_VERSION '\n'
|
|
echo "Please ensure that the development flag ('d') is set and re-run this command."
|
|
exit 1
|
|
else echo "- Development version flag is set."
|
|
fi
|
|
|
|
DEVELOPMENT_VERSION="$(echo $JS_VERSION | grep -Po '\d+\.\d+(\.\d+)?')"
|
|
|
|
echo -e "- Development version:" $DEVELOPMENT_VERSION
|
|
|
|
# Step 3(e): Check that the 'Stable Tag' field is set to a stable version
|
|
|
|
if [[ "$(echo $STABLE_TAG | grep -Poc '\d+\.\d+(\.\d+)?$')" != 1 ]]; then
|
|
echo "ERR: 'Stable Tag' not set to a stable version!"
|
|
echo -e "The 'Stable Tag' field is set to the following:\n"
|
|
echo -e '\t' $STABLE_TAG '\n'
|
|
echo "Please ensure that the 'Stable Tag' field is set to a stable version and re-run this command."
|
|
exit 1
|
|
else echo "- 'Stable Tag' field set to stable version."
|
|
fi
|
|
|
|
STABLE_VERSION="$(echo $STABLE_TAG | grep -Po '\d+\.\d+(\.\d+)?$')"
|
|
|
|
echo "- Stable version:" $STABLE_VERSION
|
|
|
|
# Step 3(f): Check that the 'Stable Tag' field points to a real tag on the SVN repo.
|
|
|
|
echo "- Checking stable tag exists..."
|
|
git svn tag --dry-run $STABLE_VERSION &>/dev/null
|
|
|
|
if [ $? -ne 1 ]; then
|
|
echo "ERR: 'Stable Tag' does not point to an existing tag!"
|
|
echo "Please ensure that the 'Stable Tag' field points to an existing stable version and re-run this command."
|
|
exit 1
|
|
else echo "- 'Stable Tag' field is set to existing tag."
|
|
fi
|
|
|
|
# Step 3(g): Check that the changelog is up-to-date
|
|
|
|
CHANGELOG_LATEST="$(awk -e '/== Changelog ==/,/= [0-9]+\.[0-9]+(\.[0-9]+)? =/' readme.txt | grep -Po '\d+\.\d+(\.\d+)?')"
|
|
if [[ $CHANGELOG_LATEST != $DEVELOPMENT_VERSION ]]; then
|
|
echo "ERR: Changelog is not up-to-date!"
|
|
echo "Current version is $DEVELOPMENT_VERSION"
|
|
echo "Latest version in changelog is $CHANGELOG_LATEST"
|
|
echo "Please ensure that the changelog is up-to-date and re-run this command."
|
|
exit 1
|
|
else echo "- Changelog is up-to-date."
|
|
fi
|
|
|
|
echo -e "- Version check complete.\n"
|
|
|
|
# Step 4: Build the Plugin
|
|
|
|
echo "- Building Plugin..."
|
|
composer run build
|
|
if [ $? != 0 ]; then echo "Build failed!"; exit 1; fi
|
|
echo -e "- Build complete.\n"
|
|
|
|
# Step 5: Update the version to pre-release
|
|
|
|
echo "- Setting pre-release version flags..."
|
|
PRERELEASE_VERSION=$DEVELOPMENT_VERSION'p'
|
|
sed -i "s/$JS_VERSION/version : \"$PRERELEASE_VERSION\"/g" dist/js/wysiwyg-editor.js
|
|
echo "- Pre-release flags set."
|
|
|
|
# Step 6: Tag the release
|
|
|
|
echo "- Tagging release..."
|
|
git tag -a $DEVELOPMENT_VERSION -m "Pre-release of version $DEVELOPMENT_VERSION"
|
|
git push --tags
|
|
echo "- Release tagged."
|
|
|
|
# Step 7: Push release to SVN repo.
|
|
|
|
# Step 7(a): Create a new local copy of the SVN repo.
|
|
|
|
echo -e "\nThe helper will now guide you through the steps to push the new release to the WordPress Plugin Directory SVN repository."
|
|
echo "For the time being, this part of the process shall remain (mostly) manual."
|
|
read -p "Are you ready to continue? (Y/N): " CONFIRM && [[ $CONFIRM == [yY] || $CONFIRM == [yY][eE][sS] ]] || exit 1
|
|
|
|
echo "Creating local copy of SVN repo..."
|
|
svn checkout https://plugins.svn.wordpress.org/footnotes tmp --depth immediates
|
|
svn update --quiet tmp/trunk --set-depth infinity
|
|
svn update --quiet tmp/tags/$PRERELEASE_VERSION --set-depth infinity
|
|
echo -e "Local copy created.\n"
|
|
|
|
# Step 7(b): Update `trunk/`
|
|
echo -e "Copying files from \`dist/\` to SVN \`trunk/\`...\n"
|
|
rsync -avhic dist/ tmp/trunk/ --delete | grep -v "^\."
|
|
read -p "Does the above list of changes look correct? (Y/N): " CONFIRM && [[ $CONFIRM == [yY] || $CONFIRM == [yY][eE][sS] ]] || exit 1
|
|
echo -e "Copying complete.\n"
|
|
|
|
# Step 7(c): Set a release message
|
|
|
|
echo "Getting commit message from changelog..."
|
|
CHANGELOG_MESSAGE="$(awk -e "/= $DEVELOPMENT_VERSION =/,/= $STABLE_VERSION =/" readme.txt | grep '^-')"
|
|
echo -e "The changelog message for this version is:\n"
|
|
echo -e "$CHANGELOG_MESSAGE\n"
|
|
read -p "Is this correct? (Y/N): " CONFIRM && [[ $CONFIRM == [yY] || $CONFIRM == [yY][eE][sS] ]] || exit 1
|
|
echo -e "Commit message set.\n"
|
|
|
|
# Step 7(d): Review
|
|
|
|
clear
|
|
echo "Let's review before pushing to the SVN..."
|
|
echo -e "Here is my current state:\n"
|
|
echo "Current version:"
|
|
echo -e '\t' $PRERELEASE_VERSION
|
|
echo "Stable version:"
|
|
echo -e '\t' $STABLE_VERSION '\n'
|
|
echo "Commit message:\n"
|
|
echo -e "$CHANGELOG_MESSAGE" '\n'
|
|
echo -e "Changes made to local \`trunk/\`:\n"
|
|
svn stat tmp/trunk/
|
|
echo ""
|
|
echo -e "\`readme.txt\` header:\n"
|
|
head tmp/trunk/readme.txt
|
|
echo ""
|
|
read -p "Is this all correct? (Y/N): " CONFIRM && [[ $CONFIRM == [yY] || $CONFIRM == [yY][eE][sS] ]] || exit 1
|
|
|
|
# Step 7(d): Push to remote `trunk/` (provided the flag is set)
|
|
|
|
if [[ $1 == "-c" ]]; then
|
|
svn ci -m "$CHANGELOG_MESSAGE"
|
|
else echo "- Commit flag not set, skipping commit step."
|
|
fi
|
|
|
|
# Step 8: Cleanup
|
|
|
|
rm -rf {dist/,tmp/}
|