generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 231
/
release.sh
executable file
·86 lines (67 loc) · 2.17 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
82
83
84
85
86
#!/bin/bash
set -euo pipefail
current_branch=$(git rev-parse --abbrev-ref HEAD)
if [[ "$current_branch" != "main" ]]; then
echo "Error: You are not on the 'main' branch. Current branch: '$current_branch'"
echo "Please switch to the 'main' branch to run this release."
echo "Exiting."
exit 1
fi
if [ "$#" -ne 2 ]; then
echo "Must provide exactly two arguments."
echo "First one must be the new version number."
echo "Second one must be the minimum obsidian version for this release."
echo ""
echo "Example usage:"
echo "./release.sh 0.3.0 0.11.13"
echo "Exiting."
exit 1
fi
if [[ $(git status --porcelain) ]]; then
echo "Changes in the git repo."
echo "Exiting."
exit 1
fi
NEW_VERSION=$1
MINIMUM_OBSIDIAN_VERSION=$2
if git rev-parse "$NEW_VERSION" >/dev/null 2>&1; then
echo "Error: Tag '$NEW_VERSION' already exists."
echo "Exiting."
exit 1
fi
echo "Updating to version ${NEW_VERSION} with minimum obsidian version ${MINIMUM_OBSIDIAN_VERSION}"
read -p "Continue? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "Running yarn in case node_modules is out-of-date"
yarn
echo "Updating X.Y.Z version numbers in docs"
find ./docs/ -name _meta -prune -o -type f -name '*.md' -exec sed -i '' s/X\.Y\.Z/${NEW_VERSION}/g {} +
echo "Updating package.json"
TEMP_FILE=$(mktemp)
jq ".version |= \"${NEW_VERSION}\"" package.json > "$TEMP_FILE" || exit 1
mv "$TEMP_FILE" package.json
echo "Updating manifest.json"
TEMP_FILE=$(mktemp)
jq ".version |= \"${NEW_VERSION}\" | .minAppVersion |= \"${MINIMUM_OBSIDIAN_VERSION}\"" manifest.json > "$TEMP_FILE" || exit 1
mv "$TEMP_FILE" manifest.json
echo "Updating versions.json"
TEMP_FILE=$(mktemp)
jq ". += {\"${NEW_VERSION}\": \"${MINIMUM_OBSIDIAN_VERSION}\"}" versions.json > "$TEMP_FILE" || exit 1
mv "$TEMP_FILE" versions.json
read -p "Create git commit, tag, and push? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
git add -A .
git commit -m"Update to version ${NEW_VERSION}"
git tag "${NEW_VERSION}"
git push
LEFTHOOK=0 git push --tags
echo "Remember to publish the documentation via Obsidian Publish!"
fi
else
echo "Exiting."
exit 1
fi