forked from colbymchenry/codegraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·70 lines (59 loc) · 1.83 KB
/
release.sh
File metadata and controls
executable file
·70 lines (59 loc) · 1.83 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
# Tag the current commit with the version in package.json and publish a
# matching GitHub Release whose body is the corresponding CHANGELOG.md entry.
#
# Run AFTER you have:
# - bumped package.json
# - added a `## [X.Y.Z] - YYYY-MM-DD` block at the top of CHANGELOG.md
# - committed, pushed to origin, and run `npm publish`
#
# Idempotent: safe to re-run after a partial failure. Skips steps that are
# already done (tag created, tag pushed, release published).
#
# Usage: ./scripts/release.sh
set -euo pipefail
cd "$(dirname "$0")/.."
VERSION=$(node -p "require('./package.json').version")
TAG="v${VERSION}"
REPO=$(git remote get-url origin | sed -E 's|.*github\.com[:/]||; s|\.git$||')
if [ -z "${REPO}" ]; then
echo "error: could not derive owner/repo from origin remote URL" >&2
exit 1
fi
if ! grep -q "^## \[${VERSION}\]" CHANGELOG.md; then
echo "error: no '## [${VERSION}]' entry found in CHANGELOG.md" >&2
exit 1
fi
NOTES=$(awk -v v="${VERSION}" '
/^## \[/ {
if (p) exit
if ($0 ~ "^## \\[" v "\\]") p = 1
}
p
' CHANGELOG.md)
if [ -z "${NOTES}" ]; then
echo "error: failed to extract changelog notes for ${VERSION}" >&2
exit 1
fi
if git rev-parse "${TAG}" >/dev/null 2>&1; then
echo "✓ tag ${TAG} already exists locally"
else
echo "→ tagging ${TAG}"
git tag "${TAG}"
fi
if git ls-remote --exit-code --tags origin "${TAG}" >/dev/null 2>&1; then
echo "✓ tag ${TAG} already on origin"
else
echo "→ pushing ${TAG} to origin"
git push origin "${TAG}"
fi
if gh release view "${TAG}" --repo "${REPO}" >/dev/null 2>&1; then
echo "✓ release ${TAG} already published"
else
echo "→ creating GitHub Release ${TAG} on ${REPO}"
gh release create "${TAG}" \
--repo "${REPO}" \
--title "${TAG}" \
--notes "${NOTES}"
fi
echo "done: https://github.com/${REPO}/releases/tag/${TAG}"