-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish.sh
More file actions
executable file
·175 lines (147 loc) · 4.1 KB
/
publish.sh
File metadata and controls
executable file
·175 lines (147 loc) · 4.1 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env bash
set -euo pipefail
die() {
echo "error: $*" >&2
exit 1
}
usage() {
cat <<'EOF'
Usage:
./publish.sh <crate> <version> [--publish] [--dry-run]
Arguments:
<crate> Crate to release: seq_geom_parser or piscem-rs
<version> New version (X.Y.Z format)
Options:
--publish Publish to crates.io after bumping and committing
--dry-run Show what would be done without modifying anything
-h, --help Show this help message
Examples:
./publish.sh seq_geom_parser 1.0.0 --publish
./publish.sh piscem-rs 0.3.0 --publish
./publish.sh piscem-rs 0.3.0 --dry-run
EOF
}
print_cmd() {
printf '+'
printf ' %q' "$@"
printf '\n'
}
run() {
print_cmd "$@"
if [[ "$DRY_RUN" == true ]]; then
return 0
fi
"$@"
}
CRATE=""
VERSION=""
PUBLISH=false
DRY_RUN=false
while [[ $# -gt 0 ]]; do
case "$1" in
--publish)
PUBLISH=true
;;
--dry-run)
DRY_RUN=true
;;
-h|--help)
usage
exit 0
;;
-*)
die "unknown option: $1"
;;
*)
if [[ -z "$CRATE" ]]; then
CRATE="$1"
elif [[ -z "$VERSION" ]]; then
VERSION="$1"
else
die "too many positional arguments"
fi
;;
esac
shift
done
[[ -n "$CRATE" ]] || { usage; exit 1; }
[[ -n "$VERSION" ]] || { usage; exit 1; }
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([+-][0-9A-Za-z.-]+)*$ ]]; then
die "version must look like X.Y.Z, optionally with prerelease/build suffixes"
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Determine the Cargo.toml path for the crate
case "$CRATE" in
piscem-rs)
CARGO_TOML="Cargo.toml"
TAG="${CRATE}-v${VERSION}"
PUBLISH_ARGS=""
;;
seq_geom_parser)
CARGO_TOML="crates/seq_geom_parser/Cargo.toml"
TAG="${CRATE}-v${VERSION}"
PUBLISH_ARGS="-p seq_geom_parser"
;;
*)
die "unknown crate: $CRATE (expected: piscem-rs or seq_geom_parser)"
;;
esac
LOCKFILE="Cargo.lock"
[[ -f "$CARGO_TOML" ]] || die "not found: $CARGO_TOML"
[[ -f "$LOCKFILE" ]] || die "not found: $LOCKFILE"
CURRENT_VERSION="$(sed -n 's/^version = "\(.*\)"/\1/p' "$CARGO_TOML" | head -1)"
[[ -n "$CURRENT_VERSION" ]] || die "could not determine current crate version from $CARGO_TOML"
if [[ "$CURRENT_VERSION" == "$VERSION" ]]; then
die "crate version is already $VERSION"
fi
if git rev-parse "$TAG" >/dev/null 2>&1; then
die "tag $TAG already exists"
fi
if [[ -n "$(git status --porcelain)" ]]; then
die "working tree is not clean; commit or stash existing changes first"
fi
echo "Crate : $CRATE"
echo "Cargo.toml : $CARGO_TOML"
echo "Current version : $CURRENT_VERSION"
echo "New version : $VERSION"
echo "Tag : $TAG"
if [[ "$PUBLISH" == true ]]; then
echo "Publish crate : yes"
else
echo "Publish crate : no"
fi
if [[ "$DRY_RUN" == true ]]; then
echo "Dry-run : yes"
else
echo "Dry-run : no"
fi
echo
echo "Updating $CARGO_TOML"
echo " version: $CURRENT_VERSION -> $VERSION"
if [[ "$DRY_RUN" == false ]]; then
sed -i.bak "1,/^version = /s/^version = \".*\"/version = \"${VERSION}\"/" "$CARGO_TOML"
rm -f "${CARGO_TOML}.bak"
fi
UPDATED_VERSION="$(sed -n 's/^version = "\(.*\)"/\1/p' "$CARGO_TOML" | head -1)"
if [[ "$DRY_RUN" == false ]]; then
[[ "$UPDATED_VERSION" == "$VERSION" ]] || die "crate version update failed"
else
echo "Dry-run: would rewrite $CARGO_TOML and refresh $LOCKFILE"
fi
run cargo check -q
run git add "$CARGO_TOML" "$LOCKFILE"
run git commit -m "chore(release): bump ${CRATE} to v${VERSION}"
if [[ "$PUBLISH" == true ]]; then
run cargo publish $PUBLISH_ARGS --allow-dirty
fi
run git tag -a "$TAG" -m "${CRATE} v${VERSION}"
run git push origin HEAD
run git push origin "$TAG"
if [[ "$DRY_RUN" == true ]]; then
echo
echo "Dry-run complete"
else
echo
echo "Release bump complete for ${CRATE} v${VERSION}"
fi