Skip to content

Commit c7e2e3a

Browse files
committed
chore: add release script
1 parent 3b0b23e commit c7e2e3a

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

scripts/release.sh

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#!/bin/bash
2+
3+
# Release script for direct-payment-pci-dss-webserver
4+
# Usage: release.sh [patch|minor|major]
5+
6+
set -e
7+
8+
RED='\033[0;31m'
9+
GREEN='\033[0;32m'
10+
YELLOW='\033[1;33m'
11+
NC='\033[0m'
12+
13+
if ! command -v gh >/dev/null 2>&1; then
14+
print_warning "GitHub CLI not found. Please create a release manually."
15+
exit 1
16+
fi
17+
18+
if [ -z "$1" ]; then
19+
echo "Usage: ./scripts/release.sh [patch|minor|major]"
20+
echo " patch: increment patch version (0.0.5 -> 0.0.6)"
21+
echo " minor: increment minor version (0.0.5 -> 0.1.0)"
22+
echo " major: increment major version (0.0.5 -> 1.0.0)"
23+
exit 1
24+
fi
25+
26+
if ! gh auth status >/dev/null 2>&1; then
27+
print_warning "GitHub CLI not authenticated. Please run 'gh auth login' to authenticate."
28+
exit 1
29+
fi
30+
31+
print_status() {
32+
if [ -n "$CI" ]; then
33+
echo -e "$1"
34+
else
35+
echo -e "${GREEN}[INFO]${NC} $1"
36+
fi
37+
}
38+
39+
print_error() {
40+
if [ -n "$CI" ]; then
41+
echo -e "$1"
42+
else
43+
echo -e "${RED}[ERROR]${NC} $1"
44+
fi
45+
}
46+
47+
print_warning() {
48+
if [ -n "$CI" ]; then
49+
echo -e "$1"
50+
else
51+
echo -e "${YELLOW}[WARNING]${NC} $1"
52+
fi
53+
}
54+
55+
increment_version() {
56+
local version=$1
57+
local increment_type=$2
58+
59+
IFS='.' read -ra VERSION_PARTS <<< "$version"
60+
local major=${VERSION_PARTS[0]}
61+
local minor=${VERSION_PARTS[1]}
62+
local patch=${VERSION_PARTS[2]}
63+
64+
case $increment_type in
65+
"major")
66+
major=$((major + 1))
67+
minor=0
68+
patch=0
69+
;;
70+
"minor")
71+
minor=$((minor + 1))
72+
patch=0
73+
;;
74+
"patch")
75+
patch=$((patch + 1))
76+
;;
77+
*)
78+
print_error "Invalid increment type. Use 'patch', 'minor', or 'major'"
79+
exit 1
80+
;;
81+
esac
82+
83+
echo "$major.$minor.$patch"
84+
}
85+
86+
print_status "Switching to main branch"
87+
git switch main > /dev/null
88+
print_status "Pulling latest changes from main branch"
89+
git pull origin main --quiet
90+
91+
INCREMENT_TYPE="$1"
92+
93+
if [[ ! "$INCREMENT_TYPE" =~ ^(patch|minor|major)$ ]]; then
94+
print_error "Invalid argument. Use 'patch', 'minor', or 'major'"
95+
echo "Usage: ./scripts/release.sh [patch|minor|major]"
96+
exit 1
97+
fi
98+
99+
CURRENT_VERSION=$(node -p "require('./package.json').version")
100+
VERSION=$(increment_version "$CURRENT_VERSION" "$INCREMENT_TYPE")
101+
102+
print_status "Current version: $CURRENT_VERSION"
103+
print_status "Incrementing $INCREMENT_TYPE version..."
104+
print_status "New version will be: $VERSION"
105+
106+
if [ -z "$CI" ]; then
107+
read -p "Continue with version $VERSION? (y/N): " -n 1 -r
108+
echo
109+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
110+
print_warning "Release cancelled"
111+
exit 0
112+
fi
113+
fi
114+
115+
print_status "Updating package.json version to \"$VERSION\""
116+
npm version "$VERSION" > /dev/null
117+
118+
print_status "Pushing version bump to main branch"
119+
git push origin main --quiet --follow-tags
120+
121+
print_status "Creating GitHub release"
122+
gh release create "v${VERSION}" --generate-notes
123+
124+
if [ $? -ne 0 ]; then
125+
print_error "Failed to create pull request for the release."
126+
exit 1
127+
fi
128+
129+
print_status "GitHub release created successfully!"

0 commit comments

Comments
 (0)