-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.sh
executable file
·77 lines (59 loc) · 1.7 KB
/
publish.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
#!/bin/bash
echo "Publishing new version to GitHub..."
# Function to extract latest version from CHANGELOG.md
get_latest_version() {
# Extract the first version number found in CHANGELOG.md
version=$(grep -m 1 "## \[.*\]" CHANGELOG.md | grep -o "\[.*\]" | tr -d "[]")
echo $version
}
# Function to extract latest changes from CHANGELOG.md
get_latest_changes() {
# Read CHANGELOG.md and extract content between first and second version headers
awk '/^## \[/{i++}i==1{print}i==2{exit}' CHANGELOG.md | tail -n +2
}
# Get version and changes
VERSION=$(get_latest_version)
if [ -z "$VERSION" ]; then
echo "Error: Could not find version in CHANGELOG.md"
exit 1
fi
echo "Found version: $VERSION"
# Store changes in a temporary file
TEMP_FILE=$(mktemp)
get_latest_changes > "$TEMP_FILE"
if [ ! -s "$TEMP_FILE" ]; then
echo "Error: Could not extract changes from CHANGELOG.md"
rm "$TEMP_FILE"
exit 1
fi
echo -e "\nChanges to be published:"
cat "$TEMP_FILE"
# Confirm with user
read -p "Continue with publish? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Publish cancelled"
rm "$TEMP_FILE"
exit 1
fi
# Check if we're in a git repository
if ! git rev-parse --git-dir > /dev/null 2>&1; then
echo "Error: Not a git repository"
rm "$TEMP_FILE"
exit 1
fi
# Add all changes
git add .
# Create commit with changelog entry
git commit -m "Release version $VERSION
$(cat "$TEMP_FILE")"
# Create and push tag
git tag -a "v$VERSION" -m "Version $VERSION
$(cat "$TEMP_FILE")"
# Push changes and tags
echo "Pushing changes and tags to GitHub..."
git push origin main
git push origin "v$VERSION"
# Cleanup
rm "$TEMP_FILE"
echo "Successfully published version $VERSION"