Skip to content

Commit

Permalink
Add release script
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpost authored Dec 30, 2024
1 parent 61a02d7 commit 289e775
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 11 deletions.
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,26 @@ Add Bluesky to your WordPress website. Automatically share new posts to Bluesky

1. Run `npm run plugin-zip` to create a zip file of the plugin.

## Development process

To create a new feature, make a fix, or change something else, create a new branch from `main`. Once the changes are ready, create a pull request to merge the changes back into `main`.

All pull requests should be properly reviewed and tested before merging. Any code merged into `main` can be included in the next release at any point.

If you are working on a new feature or a larger change, consider creating a feature branch from `main`. Once the feature is ready, create a pull request to merge the feature branch back into `main`.

## Release process

Autoblue uses the [10up/action-wordpress-plugin-deploy](https://github.com/10up/action-wordpress-plugin-deploy) GitHub Action to deploy the plugin to the WordPress.org plugin repository.

All development needs to happen in the `develop` branch. The `main` branch is reserved for releases. To create a new feature, make a fix, or change something else, create a new branch from `develop`. Once the changes are ready, create a pull request to merge the changes back into `develop`.

To release a new version, follow these steps:

1. Switch to the `develop` branch.
2. Update the version number in the `autoblue.php` file (twice)
3. Add a changelog entry with the changes and new version to `readme.txt`
4. Update the `Stable tag` in `readme.txt` to the new version number.
5. Create a new commit in `develop` with the version number change and the changelog entry.
6. Merge all changes from `develop` into `main`.
7. Create a new release on GitHub with the new version number and the changelog entry.
8. The GitHub Action will automatically deploy the new version to the WordPress.org plugin repository.
1. Switch to the `main` branch and make sure all changes are merged into it.
2. Run `bin/release.sh <version>` to create a new release. Replace `<version>` with the new version number.
3. Check the changelog in `readme.txt` and make changes if required.
4. Commit the changes and push them to the repository.
5. Create a new release on GitHub with the new version number, tag, and the changelog entry.
6. The GitHub Action will automatically deploy the new version to the WordPress.org plugin repository.

### Updating assets or readme without creating a new release

Expand All @@ -48,6 +52,5 @@ To update the assets (like screenshots) or readme without creating a new release
2. Update the assets in the `assets` directory (if required).
3. Update `readme.txt` with new information (if required).
4. Commit the changes and push them to the repository.
5. Merge the changes from `main` into `develop`.

The changes will be automatically deployed to the WordPress.org plugin repository by the [10up/action-wordpress-plugin-asset-update](https://github.com/10up/action-wordpress-plugin-asset-update) GitHub Action.
126 changes: 126 additions & 0 deletions bin/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/usr/bin/env bash

# Strict error handling
set -euo pipefail
IFS=$'\n\t'

readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
readonly PLUGIN_FILE="autoblue.php"
readonly README_FILE="readme.txt"

usage() {
cat <<-EOF
Usage: $(basename "$0") <version>
Draft a new release for the plugin.
Arguments:
version New version number (e.g., 2.1.0)
Must follow semantic versioning (X.Y.Z)
Examples:
$(basename "$0") 2.1.0
EOF
exit 1
}

version_gt() {
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"
}

validate_version() {
local new_version=$1
local prev_version=$2

if ! [[ $new_version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Version must follow semantic versioning (X.Y.Z)"
exit 1
fi

if ! version_gt "$new_version" "$prev_version"; then
echo "Error: New version ($new_version) must be higher than current version ($prev_version)"
exit 1
fi
}

check_prerequisites() {
if ! command -v git >/dev/null 2>&1; then
echo "Error: git is required but not installed"
exit 1
fi

local current_branch
current_branch="$(git rev-parse --abbrev-ref HEAD)"
if [[ "$current_branch" != "main" ]]; then
echo "Error: Not currently checked out to main! (on branch: $current_branch)"
exit 1
fi

if [[ -n "$(git status --porcelain)" ]]; then
echo "Error: Working directory not clean, make sure you're working from a clean checkout and try again."
exit 1
fi
}

update_files() {
local new_version=$1
local prev_version=$2
local files_updated=0

echo "Updating files from version $prev_version to $new_version..."

local commits
commits=$(git log --pretty=format:"* %s" "v${prev_version}"..HEAD)

if [[ -f "$SCRIPT_DIR/$PLUGIN_FILE" ]]; then
sed -i.bak \
-e "s/\* Version: .*/\* Version: $new_version/" \
-e "s/define( 'AUTOBLUE_VERSION', '.*' )/define( 'AUTOBLUE_VERSION', '$new_version' )/" \
"$SCRIPT_DIR/$PLUGIN_FILE"
rm "$SCRIPT_DIR/$PLUGIN_FILE.bak"
((files_updated++))
else
echo "Error: Plugin file not found at $SCRIPT_DIR/$PLUGIN_FILE"
exit 1
fi

if [[ -f "$SCRIPT_DIR/$README_FILE" ]]; then
sed -i.bak \
-e "s/Stable tag: .*/Stable tag: $new_version/" \
-e "/== Changelog ==/a\\
\\
= $new_version =\\
$commits
" "$SCRIPT_DIR/$README_FILE"
rm "$SCRIPT_DIR/$README_FILE.bak"
((files_updated++))
else
echo "Error: README file not found at $SCRIPT_DIR/$README_FILE"
exit 1
fi

echo "Successfully updated $files_updated files"
}

main() {
if [[ $# -ne 1 ]]; then
usage
fi

local new_version=$1

check_prerequisites

local prev_version
if ! prev_version=$(grep -o "Version: [0-9.]*" "$SCRIPT_DIR/$PLUGIN_FILE" | cut -d' ' -f2); then
echo "Error: Could not determine current version"
exit 1
fi

validate_version "$new_version" "$prev_version"
update_files "$new_version" "$prev_version"

echo "Success! Release draft created for version $new_version"
echo "Please review the changes before committing"
}

main "$@"

0 comments on commit 289e775

Please sign in to comment.