Skip to content

Commit 6f0bd23

Browse files
committed
fix: keep release.sh ASCII only
1 parent b8984eb commit 6f0bd23

1 file changed

Lines changed: 45 additions & 40 deletions

File tree

scripts/release.sh

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,117 @@
11
#!/usr/bin/env bash
2-
# release.sh cut a release entirely from your machine: bump, build, test,
2+
# release.sh - cut a release entirely from your machine: bump, build, test,
33
# publish to npm, push, and create the GitHub Release.
44
#
55
# Usage:
6-
# ./scripts/release.sh patch # 0.3.0 0.3.1
7-
# ./scripts/release.sh minor # 0.3.0 0.4.0
8-
# ./scripts/release.sh major # 0.3.0 1.0.0
6+
# ./scripts/release.sh patch # 0.3.0 -> 0.3.1
7+
# ./scripts/release.sh minor # 0.3.0 -> 0.4.0
8+
# ./scripts/release.sh major # 0.3.0 -> 1.0.0
99
# ./scripts/release.sh 1.2.3 # explicit version
1010
#
1111
# Prerequisites (one-time): `npm login` (publishing uses your local npm auth,
1212
# including a 2FA OTP prompt if enabled) and `gh auth login` (for the release).
13+
#
14+
# Keep this script ASCII-only and brace every "${var}" reference. Under `set -u`,
15+
# a $var directly abutting a multibyte character (e.g. an ellipsis) is parsed as
16+
# part of the variable name and crashes with "unbound variable".
1317

1418
set -euo pipefail
1519

1620
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
17-
cd "$ROOT"
21+
cd "${ROOT}"
1822

1923
current="$(node -p "require('./package.json').version")"
2024

21-
# ── Resolve the bump ────────────────────────────────────────────────────────
25+
# --- Resolve the bump -------------------------------------------------------
2226
if [[ -z "${1:-}" ]]; then
2327
echo "Usage: ./scripts/release.sh <patch|minor|major|x.y.z>" >&2
24-
echo "Current version: $current" >&2
28+
echo "Current version: ${current}" >&2
2529
exit 1
2630
fi
2731

2832
bump="$1"
29-
case "$bump" in
33+
case "${bump}" in
3034
patch|minor|major) ;;
3135
[0-9]*.[0-9]*.[0-9]*) ;;
32-
*) echo "Error: '$bump' must be patch, minor, major, or an explicit x.y.z" >&2; exit 1 ;;
36+
*) echo "Error: '${bump}' must be patch, minor, major, or an explicit x.y.z" >&2; exit 1 ;;
3337
esac
3438

35-
# ── Safety checks ───────────────────────────────────────────────────────────
39+
# --- Safety checks ----------------------------------------------------------
3640
branch="$(git rev-parse --abbrev-ref HEAD)"
37-
if [[ "$branch" != "main" ]]; then
38-
echo "Error: releases must be cut from 'main' (currently on '$branch')." >&2
41+
if [[ "${branch}" != "main" ]]; then
42+
echo "Error: releases must be cut from 'main' (currently on '${branch}')." >&2
3943
exit 1
4044
fi
4145

4246
if [[ -n "$(git status --porcelain)" ]]; then
43-
echo "Error: working tree is not clean commit or stash changes first." >&2
47+
echo "Error: working tree is not clean - commit or stash changes first." >&2
4448
exit 1
4549
fi
4650

47-
echo "Syncing with origin/main"
51+
echo "Syncing with origin/main..."
4852
git fetch --quiet origin main
4953
if [[ "$(git rev-parse HEAD)" != "$(git rev-parse origin/main)" ]]; then
50-
echo "Error: local main is not in sync with origin/main pull/push first." >&2
54+
echo "Error: local main is not in sync with origin/main - pull/push first." >&2
5155
exit 1
5256
fi
5357

5458
if ! npm whoami >/dev/null 2>&1; then
55-
echo "Error: not logged in to npm run 'npm login' first." >&2
59+
echo "Error: not logged in to npm - run 'npm login' first." >&2
5660
exit 1
5761
fi
5862

59-
# ── Validate (before bumping, so a failure leaves no dangling version) ───────
60-
echo "Running tests"
63+
# --- Validate (before bumping, so a failure leaves no dangling version) -----
64+
echo "Running tests..."
6165
npm test
62-
echo "Building"
66+
echo "Building..."
6367
npm run build:all
6468

65-
# ── Bump + tag (local only so far) ──────────────────────────────────────────
69+
# --- Bump + tag (local only so far) -----------------------------------------
6670
# npm version updates package.json + package-lock.json, commits, and tags vX.Y.Z.
67-
newtag="$(npm version "$bump" -m "Release v%s")" # prints e.g. "v0.4.0"
68-
echo "Bumped $current$newtag"
71+
newtag="$(npm version "${bump}" -m "Release v%s")" # prints e.g. "v0.4.0"
72+
echo "Bumped ${current} -> ${newtag}"
6973

70-
# ── Publish to npm ──────────────────────────────────────────────────────────
71-
echo "Publishing to npm (enter your 2FA OTP if prompted)"
74+
# --- Publish to npm ---------------------------------------------------------
75+
echo "Publishing to npm (enter your 2FA OTP if prompted)..."
7276
if ! npm publish; then
7377
echo "" >&2
7478
echo "Error: npm publish failed. The version bump was committed and tagged locally," >&2
7579
echo "but nothing was pushed. To undo and retry:" >&2
76-
echo " git tag -d $newtag && git reset --hard HEAD~1" >&2
80+
echo " git tag -d ${newtag} && git reset --hard HEAD~1" >&2
7781
exit 1
7882
fi
7983

80-
# ── Point the demo at the just-published version ────────────────────────────
81-
# The demo's "vendored release" build (served on GitHub Pages) is regenerated from the published npm package pinned in docs/
84+
# --- Point the demo at the just-published version ---------------------------
85+
# The demo's "vendored release" build (served on GitHub Pages) is regenerated
86+
# from the published npm package pinned in docs/, so bump docs/ to this release.
8287
newversion="${newtag#v}"
8388
pkg="@raspberrypifoundation/python-friendly-error-messages"
84-
echo "Pointing the demo at $newtag"
85-
if ( cd "$ROOT/docs" && npm pkg set "dependencies.$pkg=^$newversion" && npm install >/dev/null 2>&1 ); then
89+
echo "Pointing the demo at ${newtag}..."
90+
if ( cd "${ROOT}/docs" && npm pkg set "dependencies.${pkg}=^${newversion}" && npm install >/dev/null 2>&1 ); then
8691
git add docs/package.json docs/package-lock.json
87-
git commit -m "chore: point demo at $newtag" >/dev/null
92+
git commit -m "chore: point demo at ${newtag}" >/dev/null
8893
else
89-
echo "Warning: couldn't update the demo dependency the new version may not have" >&2
94+
echo "Warning: couldn't update the demo dependency - the new version may not have" >&2
9095
echo "propagated to npm yet. Once it has, run:" >&2
91-
echo " (cd docs && npm install $pkg@^$newversion) && git commit -am 'chore: point demo at $newtag' && git push" >&2
96+
echo " (cd docs && npm install ${pkg}@^${newversion}) && git commit -am 'chore: point demo at ${newtag}' && git push" >&2
9297
git checkout -- docs/package.json docs/package-lock.json 2>/dev/null || true
9398
fi
9499

95-
# ── Push + GitHub Release ───────────────────────────────────────────────────
100+
# --- Push + GitHub Release --------------------------------------------------
96101
git push --follow-tags origin main
97102

98103
repo="RaspberryPiFoundation/python-friendly-error-messages"
99104
if command -v gh >/dev/null 2>&1; then
100-
if ! gh release create "$newtag" --title "$newtag" --generate-notes; then
105+
if ! gh release create "${newtag}" --title "${newtag}" --generate-notes; then
101106
echo "Warning: GitHub Release creation failed (npm publish + push already succeeded)." >&2
102-
echo "Create it manually: gh release create $newtag --title $newtag --generate-notes" >&2
107+
echo "Create it manually: gh release create ${newtag} --title ${newtag} --generate-notes" >&2
103108
fi
104109
else
105-
echo "Warning: gh CLI not found GitHub Release not created." >&2
106-
echo "Install gh, then run: gh release create $newtag --title $newtag --generate-notes" >&2
110+
echo "Warning: gh CLI not found - GitHub Release not created." >&2
111+
echo "Install gh, then run: gh release create ${newtag} --title ${newtag} --generate-notes" >&2
107112
fi
108113

109114
echo ""
110-
echo "Released $newtag"
111-
echo " npm: https://www.npmjs.com/package/@raspberrypifoundation/python-friendly-error-messages/v/${newtag#v}"
112-
echo " GitHub: https://github.com/$repo/releases/tag/$newtag"
115+
echo "Released ${newtag}"
116+
echo " npm: https://www.npmjs.com/package/@raspberrypifoundation/python-friendly-error-messages/v/${newversion}"
117+
echo " GitHub: https://github.com/${repo}/releases/tag/${newtag}"

0 commit comments

Comments
 (0)