Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit ec93a1b

Browse files
committed
Add release script from master
1 parent eb7523b commit ec93a1b

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

bin/github-deploy.sh

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/bin/sh
2+
3+
RELEASER_PATH=$(pwd)
4+
PLUGIN_SLUG="woocommerce-gutenberg-products-block"
5+
GITHUB_ORG="woocommerce"
6+
IS_PRE_RELEASE=false
7+
8+
# Functions
9+
# Check if string contains substring
10+
is_substring() {
11+
case "$2" in
12+
*$1*)
13+
return 0
14+
;;
15+
*)
16+
return 1
17+
;;
18+
esac
19+
}
20+
21+
# Output colorized strings
22+
#
23+
# Color codes:
24+
# 0 - black
25+
# 1 - red
26+
# 2 - green
27+
# 3 - yellow
28+
# 4 - blue
29+
# 5 - magenta
30+
# 6 - cian
31+
# 7 - white
32+
output() {
33+
echo "$(tput setaf "$1")$2$(tput sgr0)"
34+
}
35+
36+
if ! [ -x "$(command -v hub)" ]; then
37+
echo 'Error: hub is not installed. Install from https://github.com/github/hub' >&2
38+
exit 1
39+
fi
40+
41+
# Release script
42+
echo
43+
output 2 "BLOCKS RELEASE SCRIPT"
44+
output 2 "====================="
45+
echo
46+
printf "This script will build files and create a tag on GitHub based on your local branch."
47+
echo
48+
echo
49+
printf "The /build/ directory will also be pushed to the tag."
50+
echo
51+
echo
52+
printf "Before proceeding, ensure you have checked out the correct branch you wish to release, and have committed/pushed all local changes."
53+
echo
54+
echo
55+
output 3 "Do you want to continue? [y/N]: "
56+
read -r PROCEED
57+
echo
58+
59+
if [ "$(echo "${PROCEED:-n}" | tr "[:upper:]" "[:lower:]")" != "y" ]; then
60+
output 1 "Release cancelled!"
61+
exit 1
62+
fi
63+
echo
64+
output 3 "Please enter the version number to tag, for example, 1.0.0:"
65+
read -r VERSION
66+
echo
67+
68+
# Check if is a pre-release.
69+
if is_substring "-" "${VERSION}"; then
70+
IS_PRE_RELEASE=true
71+
output 2 "Detected pre-release version!"
72+
fi
73+
74+
if [ ! -d "build" ]; then
75+
output 3 "Build directory not found. Aborting."
76+
exit 1
77+
fi
78+
79+
printf "Ready to proceed? [y/N]: "
80+
read -r PROCEED
81+
echo
82+
83+
if [ "$(echo "${PROCEED:-n}" | tr "[:upper:]" "[:lower:]")" != "y" ]; then
84+
output 1 "Release cancelled!"
85+
exit 1
86+
fi
87+
88+
output 2 "Starting release to GitHub..."
89+
echo
90+
91+
CURRENTBRANCH="$(git rev-parse --abbrev-ref HEAD)"
92+
93+
# Create a release branch.
94+
BRANCH="build/${VERSION}"
95+
git checkout -b $BRANCH
96+
97+
# Force add build directory and commit.
98+
git add build/. --force
99+
git add .
100+
git commit -m "Adding /build directory to release"
101+
102+
# Push branch upstream
103+
git push origin $BRANCH
104+
105+
# Create the new release.
106+
if [ $IS_PRE_RELEASE ]; then
107+
hub release create -m $VERSION -m "Release of version $VERSION. See readme.txt for details." -t $BRANCH --prerelease "v${VERSION}"
108+
else
109+
hub release create -m $MESSAGE -m "Release of version $VERSION. See readme.txt for details." -t $BRANCH "v${VERSION}"
110+
fi
111+
112+
git checkout $CURRENTBRANCH
113+
git branch -D $BRANCH
114+
git push origin --delete $BRANCH
115+
116+
output 2 "GitHub release complete."

0 commit comments

Comments
 (0)