-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrelease.sh
executable file
·82 lines (65 loc) · 1.95 KB
/
release.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
79
80
81
#!/bin/sh
set -e
TRUNK_BRANCH="master"
RELEASES_DIR="./releases"
PKG_NAME=$(jq -r .name package.json)
OLD_VERSION=$(jq -r .version package.json)
SEMVER_REGEX="\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)"
MAJOR=$(echo $OLD_VERSION | sed -e "s/$SEMVER_REGEX/\1/")
MINOR=$(echo $OLD_VERSION | sed -e "s/$SEMVER_REGEX/\2/")
PATCH=$(echo $OLD_VERSION | sed -e "s/$SEMVER_REGEX/\3/")
case "$1" in
"patch")
PATCH=$(($PATCH + 1))
;;
"minor")
MINOR=$(($MINOR + 1))
PATCH=0
;;
"major")
MAJOR=$(($MAJOR + 1))
MINOR=0
PATCH=0
;;
*)
echo "First argument must be version level (major|minor|patch)."
return 1
;;
esac
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "Changing version $OLD_VERSION -> $NEW_VERSION"
VERSION_DIR="$PKG_NAME-v$NEW_VERSION"
TARGET_DIR="$RELEASES_DIR/$VERSION_DIR"
# checks
if [ $(git rev-parse --abbrev-ref HEAD) != "$TRUNK_BRANCH" ]; then
echo "Not on trunk branch '$TRUNK_BRANCH'"
return 1
elif ! git diff --quiet HEAD -- package.json; then
echo "You have uncommitted changes in package.json."
return 1
elif [ -d "$TARGET_DIR" ]; then
echo "Target directory exists: $TARGET_DIR"
return 1
elif ! yarn lint; then
echo "Linting failed"
return 1
elif ! yarn test; then
echo "Tests failed"
return 1
fi
echo "Updating package.json..."
sed -i "s/\([\"']version[\"']:\s*[\"']\)\($OLD_VERSION\)\([\"']\)/\1$NEW_VERSION\3/" package.json
echo "Committing..."
git commit -n package.json -m"v$OLD_VERSION -> v$NEW_VERSION"
git tag "v$NEW_VERSION"
echo "Building production assets..."
yarn dist
echo "Copying assets..."
mkdir -pv "$TARGET_DIR"
cp -rv dist/* "$TARGET_DIR"
cp -rv config.js themes localization examples package.json README.md "$TARGET_DIR"
echo "Adjusting index.html..."
sed -i 's/type="module" crossorigin/defer/g' "$TARGET_DIR/index.html"
echo "Creating archives..."
cd "$RELEASES_DIR"
zip -r "$VERSION_DIR.zip" "$VERSION_DIR"