Skip to content

Commit 7282b68

Browse files
[bin] add script for releasing premium add-ons
1 parent bd92c2a commit 7282b68

1 file changed

Lines changed: 91 additions & 0 deletions

File tree

bin/release_addon.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env bash
2+
3+
PLUGIN_DIR=$(basename $PWD)
4+
VERSION=$1
5+
REMOTE="danny@eu1.ibericode.com"
6+
REMOTE_APP_DIR="/var/www/my.boxzillaplugin.com"
7+
PACKAGE_FILE="$HOME/Downloads/$PLUGIN_DIR-$VERSION.zip"
8+
9+
# Exit on errors
10+
set -e
11+
12+
# Check if VERSION argument was supplied
13+
if [ "$#" -lt 1 ]; then
14+
echo "1 parameters expected, $# found"
15+
echo "Usage: boxzilla_release <VERSION>"
16+
exit 1
17+
fi
18+
19+
# Check if we're inside plugin directory
20+
if [ ! -e "$PLUGIN_DIR.php" ]; then
21+
echo "Plugin entry file not found. Please run this command from inside the $PLUGIN_DIR directory."
22+
exit 1
23+
fi
24+
25+
# Check if there are uncommitted changes
26+
if [ -n "$(git status --porcelain)" ]; then
27+
echo "There are uncommitted changes. Please commit those changes before initiating a release."
28+
exit 1
29+
fi
30+
31+
if [ -e "$PACKAGE_FILE" ]; then
32+
echo "$PACKAGE_FILE exists. Deleting it."
33+
rm "$PACKAGE_FILE"
34+
fi
35+
36+
# Build JS & CSS assets
37+
if [[ -e "gulpfile.js" ]]; then
38+
npx gulp
39+
else
40+
npm run build
41+
fi
42+
43+
# Update version numbers in code
44+
for FILE in "*.php"; do
45+
sed -i "s/^Version: .*$/Version: $VERSION/g" $FILE
46+
sed -i "s/define('\(.*_VERSION\)', '.*');/define('\1', '$VERSION');/g" $FILE
47+
done
48+
49+
# Move up one directory level because we need plugin directory in ZIP file
50+
cd ..
51+
52+
zip -r "$PACKAGE_FILE" "$PLUGIN_DIR" \
53+
-x "$PLUGIN_DIR/.*" \
54+
-x "$PLUGIN_DIR/vendor/*" \
55+
-x "$PLUGIN_DIR/node_modules/*" \
56+
-x "$PLUGIN_DIR/gulpfile.js" \
57+
-x "$PLUGIN_DIR/tests" \
58+
-x "$PLUGIN_DIR/webpack.config*.js" \
59+
-x "$PLUGIN_DIR/*.json" \
60+
-x "$PLUGIN_DIR/*.lock" \
61+
-x "$PLUGIN_DIR/*.xml" \
62+
-x "$PLUGIN_DIR/assets/src/*"
63+
64+
SIZE=$(stat --printf="%s" "$PACKAGE_FILE")
65+
SIZE_KB=$(echo "$SIZE / 1024" | bc)
66+
echo "$PACKAGE_FILE created ($SIZE_KB KB)"
67+
68+
# Go back into plugin directory
69+
cd "$PLUGIN_DIR"
70+
printf "Push $PACKAGE_NAME to production? [y/N] "
71+
read CONFIRM
72+
if [[ "$CONFIRM" != "y" ]]; then
73+
exit 1;
74+
fi;
75+
76+
# Copy package to production server
77+
echo "Copying plugin package to production server"
78+
scp "$PACKAGE_FILE" "$REMOTE":"$REMOTE_APP_DIR/var/plugins/$PLUGIN_DIR-$VERSION.zip"
79+
80+
# Update version on production server
81+
echo "Updating plugin version on production server"
82+
ssh -t "$REMOTE" "cd $REMOTE_APP_DIR && bin/console app:plugins:update $PLUGIN_DIR --plugin-version=\"$VERSION\""
83+
84+
# Create git tag
85+
git add . -A
86+
git commit -m "v$VERSION"
87+
git tag "$VERSION"
88+
89+
# Push to git remote
90+
git push origin master
91+
git push origin "tags/$VERSION"

0 commit comments

Comments
 (0)