forked from kube-rs/kube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.sh
executable file
·77 lines (67 loc) · 1.92 KB
/
release.sh
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
#!/bin/bash
set -euo pipefail
fail() {
echo "$@"
exit 2
}
git-tag() {
[ -z "$(git ls-files . --exclude-standard --others)" ] || fail "remove untracked files first"
git commit -am "${VERSION}"
git tag -a "${VERSION}" -m "${VERSION}"
git push
git push --tags
}
publish-changed-crate() {
local -r crate="$1"
if git diff --name-only origin/master "${crate}/Cargo.toml"; then
(cd "$crate"; cargo publish)
fi
}
publish() {
git-tag
publish-changed-crate kube
publish-changed-crate kube-derive
}
bump-files() {
sed -i "s/${VERSION}/${NEWVER}/g" README.md
sed -i "0,/version/s/version = \".*\"/version = \"${NEWVER}\"/" kube/Cargo.toml
sed -i "0,/version/s/version = \".*\"/version = \"${NEWVER}\"/" kube-derive/Cargo.toml
}
main() {
# Current master version is always the first one in kube/Cargo.toml
local -r VERSION="$(grep version kube/Cargo.toml | awk -F"\"" '{print $2}' | head -n 1)"
local -r SEMVER=(${VERSION//./ }) # <- parse subset of semver here
# NB: can maybe use cargo-bump in the future if it starts supporting workspaces
local NEWVER="" # set if we are bumping
local -r mode="$1"
if [[ "${mode}" == "major" ]]; then
NEWVER="$((SEMVER[0]+1)).${SEMVER[1]}.${SEMVER[2]}"
elif [[ "${mode}" == "minor" ]]; then
NEWVER="${SEMVER[0]}.$((SEMVER[1]+1)).${SEMVER[2]}"
elif [[ "${mode}" == "patch" ]]; then
NEWVER="${SEMVER[0]}.${SEMVER[1]}.$((SEMVER[2]+1))"
fi
# bumping something:
if [ -n "${NEWVER}" ]; then
[ -z "$(git status --porcelain)" ] || fail "deal with changes first"
echo "Bumping from ${VERSION} -> ${NEWVER}"
bump-files
git diff
exit 0
fi
# publish
if [[ "${mode}" == "publish" ]]; then
[ -n "$(git diff --name-only origin/master ./*/Cargo.toml)" ] || fail "./release.sh minor" first
publish
fi
}
# Usage: 2 stage
#
# ./release.sh minor
#
# Then check git output, and:
#
# ./release.sh publish
#
# shellcheck disable=SC2068
main $@