forked from felixrieseberg/clippy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
84 lines (69 loc) · 3.39 KB
/
Copy pathrelease.sh
File metadata and controls
84 lines (69 loc) · 3.39 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
#!/usr/bin/env bash
# release.sh — bump version, run tests, build, tag, and push a Sprout release
# Usage: bash release.sh <major|minor|patch>
# bash release.sh patch # 0.5.0 → 0.5.1
# bash release.sh minor # 0.5.0 → 0.6.0
# bash release.sh major # 0.5.0 → 1.0.0
set -euo pipefail
BUMP="${1:-}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
if [[ -z "$BUMP" || ! "$BUMP" =~ ^(major|minor|patch)$ ]]; then
echo "Usage: bash release.sh <major|minor|patch>"
exit 1
fi
# ── Guard: clean working tree ──────────────────────────────────────────────
if [[ -n "$(git status --porcelain)" ]]; then
echo "ERROR: Working tree is dirty. Commit or stash changes first."
git status --short
exit 1
fi
CURRENT=$(python3 -c "import json; print(json.load(open('package.json'))['version'])")
echo "==> Current version: $CURRENT"
# ── Bump version ───────────────────────────────────────────────────────────
IFS='.' read -r MAJ MIN PAT <<< "$CURRENT"
case "$BUMP" in
major) MAJ=$((MAJ + 1)); MIN=0; PAT=0 ;;
minor) MIN=$((MIN + 1)); PAT=0 ;;
patch) PAT=$((PAT + 1)) ;;
esac
NEW_VERSION="$MAJ.$MIN.$PAT"
echo "==> Bumping to: $NEW_VERSION"
# Update package.json
python3 -c "
import json
with open('package.json') as f: d = json.load(f)
d['version'] = '$NEW_VERSION'
with open('package.json', 'w') as f: json.dump(d, f, indent=2)
print(' package.json updated')
"
# Update app.py VERSION constant if present
if grep -q "^VERSION = " app.py; then
sed -i "s/^VERSION = \"[^\"]*\"/VERSION = \"$NEW_VERSION\"/" app.py
echo " app.py updated"
fi
# ── Run tests ──────────────────────────────────────────────────────────────
echo "--> Running Python tests..."
python3 -m pytest -q || { echo "ERROR: Python tests failed — aborting release"; exit 1; }
echo "--> Running frontend tests..."
npm run test -- --run || { echo "ERROR: Frontend tests failed — aborting release"; exit 1; }
# ── Build frontend ─────────────────────────────────────────────────────────
echo "--> Building frontend..."
npm run build
# ── Commit + tag ───────────────────────────────────────────────────────────
echo "--> Committing version bump..."
git add package.json app.py 2>/dev/null || git add package.json
git commit -m "chore: bump version to $NEW_VERSION"
echo "--> Tagging v$NEW_VERSION..."
git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION"
# ── Push ───────────────────────────────────────────────────────────────────
echo "--> Pushing to origin..."
git push origin main
git push origin "v$NEW_VERSION"
echo ""
echo "✓ Released v$NEW_VERSION"
echo " Tag: v$NEW_VERSION"
echo " Commit: $(git rev-parse --short HEAD)"
echo ""
echo "To deploy on the Pi:"
echo " git pull && bash install.sh"