forked from ibericode/koko-analytics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.sh
executable file
·78 lines (63 loc) · 2.41 KB
/
package.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
set -euo pipefail
# Check if VERSION argument was supplied
if [ "$#" -lt 1 ]; then
echo "1 parameters expected, $# found"
echo "Usage: package.sh <VERSION>"
exit 1
fi
PLUGIN_SLUG=$(basename "$PWD")
PLUGIN_FILE="$PLUGIN_SLUG.php"
VERSION=$1
PACKAGE_FILE="$PWD/../$PLUGIN_SLUG-$VERSION.zip"
# Check if we're inside plugin directory
if [ ! -e "$PLUGIN_FILE" ]; then
echo "Plugin entry file not found. Please run this command from inside the $PLUGIN_SLUG directory."
exit 1
fi
# Check if there are uncommitted changes
if [ -n "$(git status --porcelain)" ]; then
echo "There are uncommitted changes. Please commit those changes before initiating a release."
exit 1
fi
# Update referrer blocklist
curl https://raw.githubusercontent.com/matomo-org/referrer-spam-blacklist/master/spammers.txt -k -o data/referrer-blocklist
git add data/referrer-blocklist || true
git commit -m "update referrer blocklist from https://raw.githubusercontent.com/matomo-org/referrer-spam-blacklist/master/spammers.txt" || true
# Build (optimized) client-side assets
npm run build
# Update version numbers in code
sed -i "s/^Version:.*$/Version: $VERSION/g" "$PLUGIN_FILE"
sed -i "s/define(\s*'\(.*_VERSION\)'\s*,\s*'.*'\s*);/define('\1', '$VERSION');/g" "$PLUGIN_FILE"
sed -i "s/^Stable tag:.*$/Stable tag: $VERSION/g" "readme.txt"
# Copy over changelog from CHANGELOG.md to readme.txt
# Ref: https://git.sr.ht/~dvko/dotfiles/tree/master/item/bin/wp-update-changelog
wp-update-changelog
# Move up one directory level because we need plugin directory in ZIP file
cd ..
# Check if there is an existing file for this release already
rm -f "$PACKAGE_FILE"
# Create archive (excl. development files)
zip -r "$PACKAGE_FILE" "$PLUGIN_SLUG" \
-x "$PLUGIN_SLUG/.*" \
-x "$PLUGIN_SLUG/vendor/*" \
-x "$PLUGIN_SLUG/node_modules/*" \
-x "$PLUGIN_SLUG/tests/*" \
-x "$PLUGIN_SLUG/webpack.config*.js" \
-x "$PLUGIN_SLUG/*.json" \
-x "$PLUGIN_SLUG/*.lock" \
-x "$PLUGIN_SLUG/phpcs.xml" \
-x "$PLUGIN_SLUG/*.sh" \
-x "$PLUGIN_SLUG/assets/src/*" \
-x "$PLUGIN_SLUG/assets/dist/img/screenshot-*" \
-x "$PLUGIN_SLUG/assets/dist/img/banner-*" \
-x "$PLUGIN_SLUG/code-snippets/*"
cd "$PLUGIN_SLUG"
SIZE=$(ls -lh "$PACKAGE_FILE" | cut -d' ' -f5)
echo "$(basename "$PACKAGE_FILE") created ($SIZE)"
# Create tag in Git and push to remote
git add . -A
git commit -m "v$VERSION"
git tag "$VERSION"
git push origin main
git push origin "tags/$VERSION"