-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-release.sh
More file actions
executable file
·195 lines (164 loc) · 5.36 KB
/
create-release.sh
File metadata and controls
executable file
·195 lines (164 loc) · 5.36 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/bash
# Script to create a release using git flow
# Usage: ./release.sh <version>
# Example: ./release.sh 0.4.0
set -e # Exit if any command fails
# Function to show help
show_help() {
echo "Usage: $0 <version>"
echo ""
echo "This script automates the release process using git flow:"
echo "1. Starts a new release branch"
echo "2. Updates version in package.json"
echo "3. Commits the changes"
echo "4. Finishes the release"
echo "5. Creates the corresponding tag"
echo ""
echo "Examples:"
echo " $0 0.4.0 # Release version 0.4.0"
echo " $0 1.0.0 # Release version 1.0.0"
echo ""
echo "Requirements:"
echo "- git flow must be initialized"
echo "- Must be on develop branch"
echo "- Clean working directory"
}
# Function to validate version format
validate_version() {
local version=$1
if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "❌ Error: Version format must be X.Y.Z (e.g: 1.0.0)"
exit 1
fi
}
# Function to verify that git flow is initialized
check_git_flow() {
if ! git config --get gitflow.branch.master &> /dev/null; then
echo "❌ Error: git flow is not initialized in this repository"
echo "Run: git flow init"
exit 1
fi
}
# Function to verify that we are on develop
check_develop_branch() {
current_branch=$(git branch --show-current)
if [ "$current_branch" != "develop" ]; then
echo "❌ Error: You must be on 'develop' branch to create a release"
echo "Current branch: $current_branch"
exit 1
fi
}
# Function to verify that working directory is clean
check_clean_working_dir() {
if ! git diff-index --quiet HEAD --; then
echo "❌ Error: There are uncommitted changes in working directory"
echo "Commit or stash your changes before continuing"
git status --short
exit 1
fi
}
# Function to verify that version doesn't exist already
check_version_exists() {
local version=$1
if git tag | grep -q "^v$version$"; then
echo "❌ Error: Version v$version already exists"
echo "Existing versions:"
git tag | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V
exit 1
fi
}
# Function to update version in package.json
update_package_version() {
local version=$1
local package_file="package.json"
echo "📝 Updating version in $package_file..."
# Use sed to update version in package.json
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
sed -i '' "s/\"version\": \"[^\"]*\"/\"version\": \"$version\"/" "$package_file"
else
# Linux
sed -i "s/\"version\": \"[^\"]*\"/\"version\": \"$version\"/" "$package_file"
fi
# Verify that the change was made correctly
local new_version=$(grep -o '"version": "[^"]*"' "$package_file" | cut -d'"' -f4)
if [ "$new_version" != "$version" ]; then
echo "❌ Error: Could not update version in package.json"
exit 1
fi
echo "✅ Version updated to $version in package.json"
}
# Main release function
create_release() {
local version=$1
echo "🚀 Starting release v$version..."
# Update develop with latest changes
echo "📥 Updating develop branch..."
git pull origin develop
# Start release branch
echo "🌿 Creating release branch..."
git flow release start "$version"
# Update version in package.json
update_package_version "$version"
# Commit version changes
echo "💾 Committing version changes..."
git add package.json
git commit -m "chore: bump version to $version"
# Finish release
echo "🔄 Finishing release..."
echo "Editor will open for tag message..."
git flow release finish "$version" -m "Release v$version"
# Push branches and tags
echo "📤 Pushing changes to remote repository..."
git checkout main
git push origin main
git checkout develop
git push origin develop
git push origin --tags
echo ""
echo "🎉 Release v$version completed successfully!"
echo ""
echo "Summary of actions performed:"
echo "✅ Release branch created and finished"
echo "✅ Version updated in package.json"
echo "✅ Tag v$version created"
echo "✅ Changes pushed to main, develop and tags"
echo ""
echo "Tag created: v$version"
echo "To view the tag: git show v$version"
}
# Main function
main() {
# Verify arguments
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
show_help
exit 0
fi
local version=$1
echo "🔍 Running pre-checks..."
# Verifications
validate_version "$version"
check_git_flow
check_develop_branch
check_clean_working_dir
check_version_exists "$version"
echo "✅ All checks passed"
echo ""
# Show release information
echo "📋 Release information:"
echo " Version: $version"
echo " Current branch: $(git branch --show-current)"
echo " Last commit: $(git log -1 --oneline)"
echo ""
# Confirm before proceeding
read -p "Proceed with release v$version? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "❌ Release cancelled by user"
exit 1
fi
# Create release
create_release "$version"
}
# Execute main function with all arguments
main "$@"