-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish.sh
More file actions
executable file
·70 lines (58 loc) · 1.65 KB
/
publish.sh
File metadata and controls
executable file
·70 lines (58 loc) · 1.65 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
#!/usr/bin/env bash
set -euo pipefail
DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$DIR"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BOLD='\033[1m'
NC='\033[0m'
ok() { echo -e "${GREEN}✓ $1${NC}"; }
info() { echo -e "${BOLD}$1${NC}"; }
warn() { echo -e "${YELLOW}$1${NC}"; }
fail() { echo -e "${RED}✗ $1${NC}"; exit 1; }
BUMP="${1:-}"
case "$BUMP" in
patch|minor|major) ;;
--help|-h)
echo "Usage: ./publish.sh <patch|minor|major>"
echo ""
echo "Lint, test, bump version, commit, tag, push — GitHub Actions publishes to npm."
echo ""
echo " patch 1.0.0 → 1.0.1"
echo " minor 1.0.0 → 1.1.0"
echo " major 1.0.0 → 2.0.0"
exit 0
;;
"") fail "Usage: ./publish.sh <patch|minor|major>" ;;
*) fail "Unknown argument: $BUMP. Use patch, minor, or major." ;;
esac
# Check for clean git state
if [ -n "$(git status --porcelain)" ]; then
fail "Working directory is not clean. Commit or stash changes first."
fi
NAME=$(node -p "require('./package.json').name")
# Lint
info "Linting..."
npm run lint || fail "Lint failed"
ok "Lint passed"
# Test
info "Testing..."
npm test || fail "Tests failed"
ok "Tests passed"
# Bump version
info "Bumping $BUMP version..."
npm version "$BUMP" --no-git-tag-version --silent
VERSION=$(node -p "require('./package.json').version")
ok "Version bumped to $VERSION"
# Commit + tag + push
info "Committing and pushing..."
git add package.json package-lock.json
git commit -m "$VERSION"
git tag "v$VERSION"
git push origin main --tags
ok "Pushed v$VERSION — GitHub Actions will publish to npm"
echo ""
info "$NAME@$VERSION"
echo -e " Track: ${BOLD}https://github.com/lpm-dev/cli/actions${NC}"