Skip to content

Commit 1f4e750

Browse files
committed
chore: add quick script for release (scripts/publish.sh)
1 parent a3a6a83 commit 1f4e750

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

scripts/publish.sh

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/usr/bin/env zsh
2+
emulate -R zsh
3+
setopt errexit
4+
5+
0=${(%):-%N}
6+
7+
REPO=coder/envbuilder
8+
9+
run() {
10+
dirty="$(git status --porcelain | grep -v '^??')" || true
11+
if [[ -n $dirty ]]; then
12+
print error: uncommitted changes, aborting...
13+
print $dirty
14+
exit 1
15+
fi
16+
17+
branch=$(git rev-parse --abbrev-ref HEAD)
18+
if [[ ! $branch =~ ^release/[0-9]*\.[0-9]*$ ]]; then
19+
print "error: ${(qqq)branch} is not on a release branch (should be release/X.Y), aborting..."
20+
exit 1
21+
fi
22+
23+
v=$(git tag --list 'v*' --sort=-v:refname | head -n1 | tr -d v)
24+
vv=(${(@s,.,)v})
25+
case $1 in
26+
major) ((vv[1]++)); vv[2]=0; vv[3]=0;;
27+
minor) ((vv[2]++)); vv[3]=0;;
28+
patch) ((vv[3]++));;
29+
*) print 'error: unknown semver method $1, use patch, minor or major'; exit 1;;
30+
esac
31+
nv=${(j,.,)vv}
32+
33+
head_version=$(./scripts/version.sh)
34+
print "Latest version: v${v}"
35+
print "HEAD version: ${head_version}"
36+
print "New version: v${nv}"
37+
38+
git rev-parse --verify v${nv} &>/dev/null && {
39+
print "error: tag v${nv} already exists, aborting..."
40+
exit 1
41+
}
42+
43+
head_tag=$(git describe --tags --exact-match HEAD 2>/dev/null) && {
44+
print "error: HEAD is already tagged as ${head_tag}, aborting..."
45+
exit 1
46+
}
47+
48+
print "Running checks for ${head_version}..."
49+
50+
print -n " * Checking fmt... "
51+
output=$(./scripts/check_fmt.sh 2>&1) || {
52+
print ERROR
53+
print "error: check fmt failed, aborting..."
54+
print $output
55+
exit 1
56+
}
57+
print OK
58+
59+
print -n " * Building... "
60+
output=$(./scripts/build.sh 2>&1) || {
61+
print ERROR
62+
print "error: build failed, aborting..."
63+
print $output
64+
exit 1
65+
}
66+
print OK
67+
68+
changelog=(
69+
${(f)"$(git log --format='* %s %h' v${v}...HEAD)"}
70+
)
71+
changelog=(
72+
"## Changelog"
73+
""
74+
$changelog
75+
""
76+
"Compare: https://github.com/${REPO}/compare/v${v}...v${nv}"
77+
""
78+
"## Container image"
79+
""
80+
' * `docker pull ghcr.io/coder/envbuilder:'${nv}'`'
81+
)
82+
83+
print
84+
print "Changelog:"
85+
print
86+
indented=($'\t'${^changelog})
87+
print ${(F)indented}
88+
89+
print
90+
print -n "Publish v${nv} (Y/n): "
91+
read -r -k1
92+
case $REPLY in
93+
[Yy$'\n']) print;;
94+
[Nn]) print; exit 0;;
95+
*) print $'\n'error: bad response $REPLY; exit 1;;
96+
esac
97+
98+
git tag -a "v${nv}" -m "Release v${nv}"
99+
git push --follow-tags
100+
101+
typeset -a params=(
102+
tag=v${nv}
103+
title=v${nv}
104+
body="$(jq -rn --arg x "${(F)changelog}" '$x|@uri')"
105+
)
106+
107+
echo open https://github.com/${REPO}/releases/new'?'${(j.&.)params}
108+
}
109+
110+
if [[ -z $1 ]]; then
111+
1=patch
112+
fi
113+
114+
(cd ${0:h}/..; run $1)

0 commit comments

Comments
 (0)