Skip to content

Commit cbc57de

Browse files
ErisDSclaude
andcommitted
Prompt for bump type in ship:scoped
Defaulting to patch silently was a footgun — easy to ship a patch when you meant minor. Now prompts with patch/minor/major previews and a final y/N confirmation before commit + push. BUMP env var still honored for non-interactive use. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 11f70c4 commit cbc57de

1 file changed

Lines changed: 43 additions & 3 deletions

File tree

scripts/ship-scoped.sh

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ if [[ -z "${SCOPE:-}" ]]; then
66
exit 1
77
fi
88

9-
BUMP="${BUMP:-patch}"
109
REMOTE="${GHOST_UPSTREAM:-origin}"
1110
PKG_NAME="${SCOPE#@tryghost/}"
1211
PKG_DIR="packages/${PKG_NAME}"
@@ -27,13 +26,54 @@ if [[ "${CURRENT_BRANCH}" != "main" ]]; then
2726
exit 1
2827
fi
2928

30-
echo "Bumping ${SCOPE} (${BUMP}) and publishing via tag…"
29+
CURRENT_VERSION=$(node -p "require('./${PKG_DIR}/package.json').version")
3130

32-
(cd "${PKG_DIR}" && npm --no-git-tag-version version "${BUMP}")
31+
preview() {
32+
node -e "try { console.log(require('semver').inc('${CURRENT_VERSION}', '$1')); } catch (e) { console.log('?'); }"
33+
}
34+
35+
if [[ -z "${BUMP:-}" ]]; then
36+
if [[ ! -t 0 ]]; then
37+
echo "Error: BUMP not set and no TTY for prompting (e.g. BUMP=patch)" >&2
38+
exit 1
39+
fi
40+
PATCH_NEXT=$(preview patch)
41+
MINOR_NEXT=$(preview minor)
42+
MAJOR_NEXT=$(preview major)
43+
echo ""
44+
echo "Current ${SCOPE}: ${CURRENT_VERSION}"
45+
echo "Select release type:"
46+
echo " 1) patch (${CURRENT_VERSION}${PATCH_NEXT})"
47+
echo " 2) minor (${CURRENT_VERSION}${MINOR_NEXT})"
48+
echo " 3) major (${CURRENT_VERSION}${MAJOR_NEXT})"
49+
echo " 4) custom version"
50+
read -r -p "Choice [1-4]: " CHOICE
51+
case "${CHOICE}" in
52+
1) BUMP=patch ;;
53+
2) BUMP=minor ;;
54+
3) BUMP=major ;;
55+
4) read -r -p "Version: " BUMP ;;
56+
*) echo "Invalid selection" >&2; exit 1 ;;
57+
esac
58+
fi
59+
60+
(cd "${PKG_DIR}" && npm --no-git-tag-version version "${BUMP}" > /dev/null)
3361

3462
NEW_VERSION=$(node -p "require('./${PKG_DIR}/package.json').version")
3563
TAG="${SCOPE}@${NEW_VERSION}"
3664

65+
echo ""
66+
echo "About to: bump ${SCOPE} ${CURRENT_VERSION}${NEW_VERSION},"
67+
echo " commit, tag ${TAG}, and push to ${REMOTE}/main."
68+
if [[ -t 0 ]]; then
69+
read -r -p "Proceed? [y/N]: " CONFIRM
70+
if [[ "${CONFIRM}" != "y" && "${CONFIRM}" != "Y" ]]; then
71+
echo "Aborted — reverting version bump"
72+
git checkout -- "${PKG_DIR}/package.json"
73+
exit 1
74+
fi
75+
fi
76+
3777
git add "${PKG_DIR}/package.json"
3878
git commit -m "Published new versions"
3979
git tag "${TAG}"

0 commit comments

Comments
 (0)