Skip to content

Commit 4e503c4

Browse files
committed
feat: 🎸 add auto-release script
1 parent d2e9b1d commit 4e503c4

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed

scripts/auto-release.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
3+
# Auto Release Script
4+
# This script automates the release process for json-joy without human prompts
5+
# It uses version-bump.sh to determine the appropriate version bump
6+
# Usage: ./scripts/auto-release.sh
7+
8+
set -e # Exit immediately if a command exits with a non-zero status
9+
10+
# Color codes for output
11+
RED='\033[0;31m'
12+
GREEN='\033[0;32m'
13+
YELLOW='\033[1;33m'
14+
NC='\033[0m' # No Color
15+
16+
echo -e "${GREEN}Starting automatic release process...${NC}\n"
17+
18+
# Step 1: Verify code quality and correctness
19+
echo -e "${YELLOW}Step 1: Verifying code quality and correctness...${NC}"
20+
echo "Running lint..."
21+
yarn lint
22+
23+
echo "Running format check..."
24+
yarn format
25+
26+
echo "Running typecheck..."
27+
yarn typecheck
28+
29+
echo "Running tests..."
30+
yarn test
31+
32+
echo "Generating typedoc..."
33+
yarn typedoc
34+
35+
echo -e "${GREEN}✓ Code quality verification completed${NC}\n"
36+
37+
# Step 2: Prepare for release
38+
echo -e "${YELLOW}Step 2: Preparing for release...${NC}"
39+
echo "Cleaning..."
40+
yarn clean
41+
42+
echo "Building..."
43+
yarn build
44+
45+
echo -e "${GREEN}✓ Build completed${NC}\n"
46+
47+
# Determine version bump from commit messages
48+
echo -e "${YELLOW}Determining version bump from commit messages...${NC}"
49+
VERSION_BUMP=$(./scripts/version-bump.sh)
50+
51+
echo "Detected version bump: ${VERSION_BUMP}"
52+
53+
# If no-bump, abort the release but exit with success
54+
if [ "$VERSION_BUMP" = "no-bump" ]; then
55+
echo -e "${YELLOW}No significant changes detected. Skipping release.${NC}"
56+
exit 0
57+
fi
58+
59+
echo -e "${GREEN}✓ Version bump determined: ${VERSION_BUMP}${NC}\n"
60+
61+
# Step 3: Update version in root package.json
62+
echo -e "${YELLOW}Step 3: Updating version in root package.json...${NC}"
63+
npm version --allow-same-version --no-git-tag-version "${VERSION_BUMP}"
64+
65+
NEW_VERSION=$(node -p "require('./package.json').version")
66+
echo -e "${GREEN}✓ Version updated to ${NEW_VERSION}${NC}\n"
67+
68+
# Step 4: Synchronize versions across all packages
69+
echo -e "${YELLOW}Step 4: Synchronizing versions across all packages...${NC}"
70+
./scripts/sync-versions.ts
71+
72+
echo -e "${GREEN}✓ Versions synchronized${NC}\n"
73+
74+
# Step 5: Publish to NPM
75+
echo -e "${YELLOW}Step 5: Publishing to NPM...${NC}"
76+
yarn workspaces foreach -A --no-private npm publish
77+
78+
echo -e "${GREEN}✓ Published to NPM${NC}\n"
79+
80+
# Step 6: Create Git tag and push to remote
81+
echo -e "${YELLOW}Step 6: Creating Git tag and pushing to remote...${NC}"
82+
git add .
83+
git commit -m "chore: release v${NEW_VERSION}"
84+
git tag "v${NEW_VERSION}"
85+
git push origin --tags
86+
87+
echo -e "${GREEN}✓ Git tag created and pushed${NC}\n"
88+
89+
echo -e "${GREEN}🎉 Release v${NEW_VERSION} completed successfully!${NC}"

scripts/version-bump.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
# Version Bump Script
4+
# This script determines the semantic version bump based on commit messages
5+
# from now until the last vx.x.x tagged commit.
6+
#
7+
# Returns:
8+
# - major: if there is at least one commit with "BREAKING CHANGE:"
9+
# - minor: if there is at least one commit starting with "feat:", "perf:", or "release:"
10+
# - patch: if there is at least one commit starting with "fix:" or "refactor:"
11+
# - no-bump: otherwise
12+
13+
# Get the last version tag
14+
LAST_TAG=$(git describe --tags --match "v*.*.*" 2>/dev/null || echo "")
15+
16+
if [ -z "$LAST_TAG" ]; then
17+
# No previous tag found, get all commits
18+
COMMITS=$(git log --pretty=format:"%B" HEAD)
19+
else
20+
# Get commits since the last tag
21+
COMMITS=$(git log "${LAST_TAG}..HEAD" --pretty=format:"%B")
22+
fi
23+
24+
# Check for BREAKING CHANGE
25+
if echo "$COMMITS" | grep -q "^BREAKING CHANGE:"; then
26+
echo "major"
27+
exit 0
28+
fi
29+
30+
# Check for feat:, perf:, or release: commits
31+
if echo "$COMMITS" | grep -q "^feat:\|^perf:\|^release:"; then
32+
echo "minor"
33+
exit 0
34+
fi
35+
36+
# Check for fix: or refactor: commits
37+
if echo "$COMMITS" | grep -q "^fix:\|^refactor:"; then
38+
echo "patch"
39+
exit 0
40+
fi
41+
42+
# No recognized commits
43+
echo "no-bump"
44+
exit 0

0 commit comments

Comments
 (0)