Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Releases: Add a script that does a full release #28048

Merged
merged 28 commits into from
Jan 19, 2023
Merged
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9a62b81
Initial commit
sdixon194 Dec 21, 2022
4863508
Check working directory and check for pre-release branch
sdixon194 Dec 21, 2022
61ec9da
Checkout prerelease
sdixon194 Dec 21, 2022
94b1184
Push pre-release branch
sdixon194 Dec 21, 2022
ee4cb66
Check arguments
sdixon194 Jan 3, 2023
724aa54
Change to a dummy release branch for testing
sdixon194 Jan 3, 2023
a6924c7
try that again
sdixon194 Jan 3, 2023
921fdcf
Add arugments to array
sdixon194 Jan 4, 2023
602f31e
Fix argument array
sdixon194 Jan 4, 2023
0535093
Add prompt to continue
sdixon194 Jan 4, 2023
0d7013b
Move comment
sdixon194 Jan 4, 2023
57282c9
Add squash for beta
sdixon194 Jan 4, 2023
93f03f1
Get build ID
sdixon194 Jan 9, 2023
cc2f1c6
Merge remote-tracking branch 'origin/trunk' into add/jetpack-release-all
sdixon194 Jan 9, 2023
19d3ff7
Clean up the script
sdixon194 Jan 10, 2023
807616e
Check for version as well
sdixon194 Jan 11, 2023
d08d1f2
Update usage
sdixon194 Jan 11, 2023
f38307c
Merge remote-tracking branch 'origin/trunk' into add/jetpack-release-all
sdixon194 Jan 18, 2023
0412d0c
Die when not on a clean working copy
sdixon194 Jan 18, 2023
136db12
Die if build fails, add some comments
sdixon194 Jan 18, 2023
55df119
Update tools/release-plugin.sh
sdixon194 Jan 19, 2023
22bd865
Update tools/release-plugin.sh
sdixon194 Jan 19, 2023
459c5a6
Update tools/release-plugin.sh
sdixon194 Jan 19, 2023
cb51566
Update tools/release-plugin.sh
sdixon194 Jan 19, 2023
fcd5ec9
Merge remote-tracking branch 'origin/trunk' into add/jetpack-release-all
sdixon194 Jan 19, 2023
eb10537
Update some verbage
sdixon194 Jan 19, 2023
96fd0a9
Fix parsing the project and version number
sdixon194 Jan 19, 2023
fc6c5e2
Remove exit
sdixon194 Jan 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions tools/release-plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#!/usr/bin/env bash

set -eo pipefail

BASE=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
. "$BASE/tools/includes/check-osx-bash-version.sh"
. "$BASE/tools/includes/chalk-lite.sh"
. "$BASE/tools/includes/proceed_p.sh"
. "$BASE/tools/includes/plugin-functions.sh"
. "$BASE/tools/includes/version-compare.sh"
. "$BASE/tools/includes/normalize-version.sh"


# Instructions
function usage {
cat <<-EOH
usage: $0 [options] <plugin> <version>

Conduct a full release of a specified plugin through release branch creation. The <plugin> must be the slug of the plugin, such as plugins/jetpack

Options:
-a Release an alpha version
-b Release a beta version
EOH
exit 1
}

# Get the options passed and parse them.
ARGS=('-p')
ALPHABETA=
while getopts "v:abh" opt; do
case ${opt} in
a)
ALPHABETA='-a'
ARGS+=("$ALPHABETA")
;;
b)
ALPHABETA='-b'
ARGS+=("$ALPHABETA")
;;
h)
usage
;;
?)
error "Invalid argument"
echo ""
usage
;;
esac
done
shift "$(($OPTIND -1))"

# If there are more than two arguments, bail.
[[ $# -gt 2 ]] && die "Too many arguments specified! Only provide a project and a version number. Got:$(printf ' "%s"' "$@")"$'\n'"(note all options must come before the project slug)"

# Get the project slug.
PROJECT=
for ARG in "$@"
do
SLUG="${ARG#projects/}" # DWIM
SLUG="${SLUG%/}" # Sanitize
if [[ -e "$BASE/projects/$SLUG/composer.json" ]]; then
yellow "Project found: $ARG"
PROJECT="$SLUG"
shift
break
fi
done
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will have weird behavior if someone does try to add extra non-option arguments before the slug. I'd lose the loop and process $1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, let me know if that works better.

[[ -z "$PROJECT" ]] && die "A valid project slug must be specified."

# Determine the project version

[[ -z $1 ]] && die "Please specify a version number"
# Figure out the version(s) to use for the plugin(s).
function check_ver {
normalize_version_number "$1"
if [[ ! "$NORMALIZED_VERSION" =~ ^[0-9]+(\.[0-9]+)+(-.*)?$ ]]; then
red "\"$NORMALIZED_VERSION\" does not appear to be a valid version number."
return 1
fi
local CUR_VERSION
CUR_VERSION=$("$BASE/tools/plugin-version.sh" "$PROJECT")
# shellcheck disable=SC2310
if version_compare "$CUR_VERSION" "$NORMALIZED_VERSION"; then
proceed_p "Version $NORMALIZED_VERSION <= $CUR_VERSION."
return $?
fi
return 0
}

if ! check_ver "$1"; then
die "Please specify a valid version number."
fi
VERSION="$1"

proceed_p "Releasing $PROJECT $VERSION" "Proceed?"

# Make sure we're standing on trunk and working directory is clean
CURRENT_BRANCH="$( git rev-parse --abbrev-ref HEAD )"
if [[ "$CURRENT_BRANCH" != "trunk" ]]; then
proceed_p "Not currently checked out to trunk." "Check out trunk before continuing?"
git checkout trunk && git pull
fi

if [[ "$(git status --porcelain)" ]]; then
sdixon194 marked this conversation as resolved.
Show resolved Hide resolved
red "Working directory not clean, make sure you're working from a clean checkout and try again." && die
sdixon194 marked this conversation as resolved.
Show resolved Hide resolved
fi

# Check out and push pre-release branch
BRANCHES="$( git branch )"
if [[ "$BRANCHES" =~ "prerelease" ]]; then
sdixon194 marked this conversation as resolved.
Show resolved Hide resolved
proceed_p "Existing prerelease branch found." "Delete it?"
git branch -D prerelease
fi

git checkout -b prerelease
if ! git push -u origin HEAD; then
red "Branch push failed. Check #jetpack-releases and make sure no one is doing a release already, then delete the branch at https://github.com/Automattic/jetpack/branches"
sdixon194 marked this conversation as resolved.
Show resolved Hide resolved
fi

# Run the changelogger release script
tools/changelogger-release.sh "${ARGS[@]}" "$PROJECT"

# When it completes, wait for user to edit anything they want, then push key to continue.
read -r -s -p $'Edit any changelog entries you want, then press enter to continue the release process.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this mention "in a different terminal window" or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good point, I know most folks use VS Code or something to edit, but specified to be sure.

echo ""

echo "Committing changes..."
git add --all
git commit -am "Changelog edits for $PROJECT"

# If we're running a beta, amend the changelog
if [[ "$PROJECT" == "projects/jetpack" && "$ALPHABETA" == "-b" ]]; then
echo "Releasing a beta, amending the readme.txt"
jetpack changelog squash plugins/jetpack readme
git commit -am "Amend readme.txt"
fi

# Push the changes, then tell the user to wait for the builds to complete and things to update.
git push -u origin prerelease

yellow "Waiting for build to complete and push to mirror repos"
BUILDID="$( gh run list --json headBranch,event,databaseId,workflowName --jq '.[] | select(.event=="push" and .headBranch=="prerelease" and .workflowName=="Build") | .databaseId' )"
if ! gh run watch "${BUILDID[0]}" --exit-status; then
echo "Build failed! Check for build errors on GitHub for more information." && die
fi

# After this, run tools/create-release-branch.sh to create a release branch.
yellow "Build is complete. Creating a release branch."
tools/create-release-branch.sh "$PROJECT" "$VERSION"

echo "Release branch created!"