Skip to content

Commit fab2726

Browse files
author
Andrea Cosentino
committed
chore: refactor release script
1 parent 29870ec commit fab2726

1 file changed

Lines changed: 150 additions & 150 deletions

File tree

scripts/release.sh

Lines changed: 150 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,150 @@
1-
#!/bin/bash
2-
3-
set -e
4-
5-
# Colors for output
6-
RED='\033[0;31m'
7-
GREEN='\033[0;32m'
8-
YELLOW='\033[1;33m'
9-
BLUE='\033[0;34m'
10-
NC='\033[0m' # No Color
11-
12-
# Version type (patch, minor, major)
13-
VERSION_TYPE=$1
14-
15-
if [ -z "$VERSION_TYPE" ]; then
16-
echo -e "${RED}❌ Error: Version type required (patch, minor, or major)${NC}"
17-
echo "Usage: bash scripts/release.sh [patch|minor|major]"
18-
exit 1
19-
fi
20-
21-
if [[ ! "$VERSION_TYPE" =~ ^(patch|minor|major)$ ]]; then
22-
echo -e "${RED}❌ Error: Invalid version type '$VERSION_TYPE'${NC}"
23-
echo "Valid types: patch, minor, major"
24-
exit 1
25-
fi
26-
27-
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
28-
echo -e "${BLUE}🚀 Starting Release Process - $VERSION_TYPE version bump${NC}"
29-
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
30-
31-
# Check if git working directory is clean
32-
if [ -n "$(git status --porcelain)" ]; then
33-
echo -e "${RED}❌ Error: Working directory is not clean${NC}"
34-
echo "Please commit or stash your changes before releasing"
35-
git status --short
36-
exit 1
37-
fi
38-
39-
# Check if on main branch (optional, comment out if not needed)
40-
CURRENT_BRANCH=$(git branch --show-current)
41-
if [ "$CURRENT_BRANCH" != "main" ] && [ "$CURRENT_BRANCH" != "master" ]; then
42-
echo -e "${YELLOW}⚠️ Warning: Not on main/master branch (current: $CURRENT_BRANCH)${NC}"
43-
read -p "Continue anyway? (y/N) " -n 1 -r
44-
echo
45-
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
46-
exit 1
47-
fi
48-
fi
49-
50-
# Get current version
51-
CURRENT_VERSION=$(node -p "require('./package.json').version")
52-
echo -e "${BLUE}📦 Current version: ${YELLOW}$CURRENT_VERSION${NC}"
53-
54-
# Run pre-release checks
55-
echo -e "\n${BLUE}🔍 Running pre-release checks...${NC}"
56-
57-
echo -e "${BLUE} 1/5 Running linter...${NC}"
58-
pnpm run lint || {
59-
echo -e "${RED}❌ Linting failed${NC}"
60-
exit 1
61-
}
62-
63-
echo -e "${BLUE} 2/5 Running type check...${NC}"
64-
pnpm run typecheck || {
65-
echo -e "${RED}❌ Type checking failed${NC}"
66-
exit 1
67-
}
68-
69-
echo -e "${BLUE} 3/5 Running tests...${NC}"
70-
pnpm run test:run || {
71-
echo -e "${RED}❌ Tests failed${NC}"
72-
exit 1
73-
}
74-
75-
echo -e "${BLUE} 4/5 Building package...${NC}"
76-
pnpm run build || {
77-
echo -e "${RED}❌ Build failed${NC}"
78-
exit 1
79-
}
80-
81-
echo -e "${BLUE} 5/5 Building documentation...${NC}"
82-
pnpm run docs:build || {
83-
echo -e "${RED}❌ Documentation build failed${NC}"
84-
exit 1
85-
}
86-
87-
echo -e "${GREEN}✅ All pre-release checks passed!${NC}"
88-
89-
# Bump version (this will also run 'version' script which updates changelog)
90-
echo -e "\n${BLUE}📝 Bumping version ($VERSION_TYPE)...${NC}"
91-
pnpm version $VERSION_TYPE --no-git-tag-version
92-
93-
# Get new version
94-
NEW_VERSION=$(node -p "require('./package.json').version")
95-
echo -e "${GREEN}✅ Version bumped: ${YELLOW}$CURRENT_VERSION$NEW_VERSION${NC}"
96-
97-
# Generate changelog
98-
echo -e "\n${BLUE}📝 Generating changelog...${NC}"
99-
pnpm run changelog || {
100-
echo -e "${YELLOW}⚠️ Changelog generation failed, continuing...${NC}"
101-
}
102-
103-
# Commit changes
104-
echo -e "\n${BLUE}💾 Committing changes...${NC}"
105-
git add package.json CHANGELOG.md docs/.vitepress/dist
106-
git commit -m "chore(release): v$NEW_VERSION" || {
107-
echo -e "${YELLOW}⚠️ Nothing to commit${NC}"
108-
}
109-
110-
# Create git tag
111-
echo -e "\n${BLUE}🏷️ Creating git tag v$NEW_VERSION...${NC}"
112-
git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION"
113-
114-
# Push to remote
115-
echo -e "\n${BLUE}📤 Pushing to remote...${NC}"
116-
git push origin $CURRENT_BRANCH
117-
git push origin "v$NEW_VERSION"
118-
119-
echo -e "${GREEN}✅ Git tag created and pushed${NC}"
120-
121-
# Publish to npm
122-
echo -e "\n${BLUE}📦 Publishing to npm...${NC}"
123-
echo -e "${YELLOW}⚠️ This will publish version $NEW_VERSION to npm${NC}"
124-
read -p "Continue with npm publish? (y/N) " -n 1 -r
125-
echo
126-
127-
if [[ $REPLY =~ ^[Yy]$ ]]; then
128-
pnpm publish --access public --no-git-checks || {
129-
echo -e "${RED}❌ npm publish failed${NC}"
130-
echo -e "${YELLOW}Don't worry, the version bump and git tag are already pushed.${NC}"
131-
echo -e "${YELLOW}You can manually publish later with: pnpm publish --access public${NC}"
132-
exit 1
133-
}
134-
135-
echo -e "\n${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
136-
echo -e "${GREEN}🎉 Release v$NEW_VERSION completed successfully!${NC}"
137-
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
138-
echo -e "${GREEN}✅ Package published to npm${NC}"
139-
echo -e "${GREEN}✅ Git tag pushed to remote${NC}"
140-
echo -e "${GREEN}✅ Changelog updated${NC}"
141-
echo -e ""
142-
echo -e "${BLUE}📦 npm: ${YELLOW}https://www.npmjs.com/package/@ndriadev/vite-plugin-universal-api${NC}"
143-
echo -e "${BLUE}🏷️ Tag: ${YELLOW}https://github.com/nDriaDev/vite-plugin-universal-api/releases/tag/v$NEW_VERSION${NC}"
144-
else
145-
echo -e "\n${YELLOW}⚠️ Skipped npm publish${NC}"
146-
echo -e "${BLUE}Version bump and git tag have been pushed to remote.${NC}"
147-
echo -e "${BLUE}To publish manually later, run: ${YELLOW}pnpm publish --access public${NC}"
148-
fi
149-
150-
echo ""
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Colors for output
6+
RED='\033[0;31m'
7+
GREEN='\033[0;32m'
8+
YELLOW='\033[1;33m'
9+
BLUE='\033[0;34m'
10+
NC='\033[0m' # No Color
11+
12+
# Version type (patch, minor, major)
13+
VERSION_TYPE=$1
14+
15+
if [ -z "$VERSION_TYPE" ]; then
16+
echo -e "${RED}❌ Error: Version type required (patch, minor, or major)${NC}"
17+
echo "Usage: bash scripts/release.sh [patch|minor|major]"
18+
exit 1
19+
fi
20+
21+
if [[ ! "$VERSION_TYPE" =~ ^(patch|minor|major)$ ]]; then
22+
echo -e "${RED}❌ Error: Invalid version type '$VERSION_TYPE'${NC}"
23+
echo "Valid types: patch, minor, major"
24+
exit 1
25+
fi
26+
27+
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
28+
echo -e "${BLUE}🚀 Starting Release Process - $VERSION_TYPE version bump${NC}"
29+
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
30+
31+
# Check if git working directory is clean
32+
if [ -n "$(git status --porcelain)" ]; then
33+
echo -e "${RED}❌ Error: Working directory is not clean${NC}"
34+
echo "Please commit or stash your changes before releasing"
35+
git status --short
36+
exit 1
37+
fi
38+
39+
# Check if on main branch (optional, comment out if not needed)
40+
CURRENT_BRANCH=$(git branch --show-current)
41+
if [ "$CURRENT_BRANCH" != "main" ] && [ "$CURRENT_BRANCH" != "master" ]; then
42+
echo -e "${YELLOW}⚠️ Warning: Not on main/master branch (current: $CURRENT_BRANCH)${NC}"
43+
read -p "Continue anyway? (y/N) " -n 1 -r
44+
echo
45+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
46+
exit 1
47+
fi
48+
fi
49+
50+
# Get current version
51+
CURRENT_VERSION=$(node -p "require('./package.json').version")
52+
echo -e "${BLUE}📦 Current version: ${YELLOW}$CURRENT_VERSION${NC}"
53+
54+
# Run pre-release checks
55+
echo -e "\n${BLUE}🔍 Running pre-release checks...${NC}"
56+
57+
echo -e "${BLUE} 1/5 Running linter...${NC}"
58+
pnpm run lint || {
59+
echo -e "${RED}❌ Linting failed${NC}"
60+
exit 1
61+
}
62+
63+
echo -e "${BLUE} 2/5 Running type check...${NC}"
64+
pnpm run typecheck || {
65+
echo -e "${RED}❌ Type checking failed${NC}"
66+
exit 1
67+
}
68+
69+
echo -e "${BLUE} 3/5 Running tests...${NC}"
70+
pnpm run test:run || {
71+
echo -e "${RED}❌ Tests failed${NC}"
72+
exit 1
73+
}
74+
75+
echo -e "${BLUE} 4/5 Building package...${NC}"
76+
pnpm run build || {
77+
echo -e "${RED}❌ Build failed${NC}"
78+
exit 1
79+
}
80+
81+
echo -e "${BLUE} 5/5 Building documentation...${NC}"
82+
pnpm run docs:build || {
83+
echo -e "${RED}❌ Documentation build failed${NC}"
84+
exit 1
85+
}
86+
87+
echo -e "${GREEN}✅ All pre-release checks passed!${NC}"
88+
89+
# Bump version (this will also run 'version' script which updates changelog)
90+
echo -e "\n${BLUE}📝 Bumping version ($VERSION_TYPE)...${NC}"
91+
pnpm version $VERSION_TYPE --no-git-tag-version
92+
93+
# Get new version
94+
NEW_VERSION=$(node -p "require('./package.json').version")
95+
echo -e "${GREEN}✅ Version bumped: ${YELLOW}$CURRENT_VERSION$NEW_VERSION${NC}"
96+
97+
# Generate changelog
98+
echo -e "\n${BLUE}📝 Generating changelog...${NC}"
99+
pnpm run changelog || {
100+
echo -e "${YELLOW}⚠️ Changelog generation failed, continuing...${NC}"
101+
}
102+
103+
# Commit changes
104+
echo -e "\n${BLUE}💾 Committing changes...${NC}"
105+
git add package.json CHANGELOG.md docs/.vitepress/dist
106+
git commit -m "chore(release): v$NEW_VERSION" || {
107+
echo -e "${YELLOW}⚠️ Nothing to commit${NC}"
108+
}
109+
110+
# Create git tag
111+
echo -e "\n${BLUE}🏷️ Creating git tag v$NEW_VERSION...${NC}"
112+
git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION"
113+
114+
# Push to remote
115+
echo -e "\n${BLUE}📤 Pushing to remote...${NC}"
116+
git push origin $CURRENT_BRANCH
117+
git push origin "v$NEW_VERSION"
118+
119+
echo -e "${GREEN}✅ Git tag created and pushed${NC}"
120+
121+
# Publish to npm
122+
echo -e "\n${BLUE}📦 Publishing to npm...${NC}"
123+
echo -e "${YELLOW}⚠️ This will publish version $NEW_VERSION to npm${NC}"
124+
read -p "Continue with npm publish? (y/N) " -n 1 -r
125+
echo
126+
127+
if [[ $REPLY =~ ^[Yy]$ ]]; then
128+
pnpm publish --access public --no-git-checks || {
129+
echo -e "${RED}❌ npm publish failed${NC}"
130+
echo -e "${YELLOW}Don't worry, the version bump and git tag are already pushed.${NC}"
131+
echo -e "${YELLOW}You can manually publish later with: pnpm publish --access public${NC}"
132+
exit 1
133+
}
134+
135+
echo -e "\n${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
136+
echo -e "${GREEN}🎉 Release v$NEW_VERSION completed successfully!${NC}"
137+
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
138+
echo -e "${GREEN}✅ Package published to npm${NC}"
139+
echo -e "${GREEN}✅ Git tag pushed to remote${NC}"
140+
echo -e "${GREEN}✅ Changelog updated${NC}"
141+
echo -e ""
142+
echo -e "${BLUE}📦 npm: ${YELLOW}https://www.npmjs.com/package/@ndriadev/vite-plugin-universal-api${NC}"
143+
echo -e "${BLUE}🏷️ Tag: ${YELLOW}https://github.com/nDriaDev/vite-plugin-universal-api/releases/tag/v$NEW_VERSION${NC}"
144+
else
145+
echo -e "\n${YELLOW}⚠️ Skipped npm publish${NC}"
146+
echo -e "${BLUE}Version bump and git tag have been pushed to remote.${NC}"
147+
echo -e "${BLUE}To publish manually later, run: ${YELLOW}pnpm publish --access public${NC}"
148+
fi
149+
150+
echo ""

0 commit comments

Comments
 (0)