-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·99 lines (75 loc) · 1.84 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
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
version=0.0.0
github() {
local version="$1"
local reset="$2"
if [ "$reset" == "--reset" ]; then
git checkout --orphan orphan
fi
git add .
git commit -am "build: $version"
git tag "$version" -m "build: $version"
git push origin "$version"
if [ "$reset" == "--reset" ]; then
git branch -M main
git push --force origin main
else
git push
fi
gh release create "$version" --generate-notes --title "$version" --notes "Release $version"
echo "Running npm publish"
npm run publish
if [ $? -ne 0 ]; then
echo "npm publish failed"
exit 1
else
echo "npm publish succeeded"
fi
}
changelog() {
local file="CHANGELOG.md"
local version="$1"
local previous_version=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null)
local changes="Changes in this version:"
# Generate a list of changes between the previous and current version
if [ -n "$previous_version" ]; then
local list=$(git log --pretty=format:"* %s" "$previous_version"..HEAD)
else
local list=$(git log --pretty=format:"* %s")
fi
# Remove the first two lines of the changelog file
sed '1,2d' "$file" > temp_changelog.mdx
# Write the new version's changelog entry
cat <<EOF > "$file"
# Changelog
### $version
$changes
$list
$(cat temp_changelog.mdx)
EOF
# Remove the temporary file
rm temp_changelog.mdx
}
update_version() {
local package="package.json"
version=$(jq -r '.version' "$package")
IFS='.' read -r major minor patch <<< "$version"
if (( patch < 9 )); then
(( patch++ ))
elif (( minor < 9 )); then
(( minor++ ))
patch=0
else
(( major++ ))
minor=0
patch=0
fi
version="$major.$minor.$patch"
jq ".version = \"$version\"" "$package" > temp.json && mv temp.json "$package"
}
update() {
update_version
changelog "$version"
github "$version" "$1"
}
update "$@"