Skip to content

Commit

Permalink
Release to cargo from make-release script
Browse files Browse the repository at this point in the history
and reformatting the script with `shfmt -i 4 -ci -w
misc/make-release.sh`
  • Loading branch information
chmouel committed Sep 18, 2023
1 parent ab452d7 commit 4b7d0f5
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions misc/make-release.sh
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
#!/usr/bin/env bash
set -euf
VERSION=${1-""}
CARGO_VERSION=$(grep '^version = "' Cargo.toml|grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')
PKGNAME=$(grep '^name = "' Cargo.toml|sed -E 's/.*"(\w+)"/\1/')
CARGO_VERSION=$(grep '^version = "' Cargo.toml | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')
PKGNAME=$(grep '^name = "' Cargo.toml | sed -E 's/.*"(\w+)"/\1/')

bumpversion() {
current=$(git describe --tags $(git rev-list --tags --max-count=1))
echo "Current tag version is ${current}"
current=$(git describe --tags $(git rev-list --tags --max-count=1))
echo "Current tag version is ${current}"

major=$(python3 -c "import semver,sys;print(str(semver.VersionInfo.parse(sys.argv[1]).bump_major()))" ${current})
minor=$(python3 -c "import semver,sys;print(str(semver.VersionInfo.parse(sys.argv[1]).bump_minor()))" ${current})
patch=$(python3 -c "import semver,sys;print(str(semver.VersionInfo.parse(sys.argv[1]).bump_patch()))" ${current})
major=$(python3 -c "import semver,sys;print(str(semver.VersionInfo.parse(sys.argv[1]).bump_major()))" ${current})
minor=$(python3 -c "import semver,sys;print(str(semver.VersionInfo.parse(sys.argv[1]).bump_minor()))" ${current})
patch=$(python3 -c "import semver,sys;print(str(semver.VersionInfo.parse(sys.argv[1]).bump_patch()))" ${current})

echo "If we bump we get, Major: ${major} Minor: ${minor} Patch: ${patch}"
read -p "To which version you would like to bump [M]ajor, Mi[n]or, [P]atch or Manua[l]: " ANSWER
if [[ ${ANSWER,,} == "m" ]];then
mode="major"
elif [[ ${ANSWER,,} == "n" ]];then
mode="minor"
elif [[ ${ANSWER,,} == "p" ]];then
mode="patch"
elif [[ ${ANSWER,,} == "l" ]];then
read -p "Enter version: " -e VERSION
return
else
print "no or bad reply??"
exit
fi
VERSION=$(python3 -c "import semver,sys;print(str(semver.VersionInfo.parse(sys.argv[1]).bump_${mode}()))" ${current})
[[ -z ${VERSION} ]] && {
echo "could not bump version automatically"
exit
}
echo "[release] Releasing ${VERSION}"
echo "If we bump we get, Major: ${major} Minor: ${minor} Patch: ${patch}"
read -p "To which version you would like to bump [M]ajor, Mi[n]or, [P]atch or Manua[l]: " ANSWER
if [[ ${ANSWER,,} == "m" ]]; then
mode="major"
elif [[ ${ANSWER,,} == "n" ]]; then
mode="minor"
elif [[ ${ANSWER,,} == "p" ]]; then
mode="patch"
elif [[ ${ANSWER,,} == "l" ]]; then
read -p "Enter version: " -e VERSION
return
else
print "no or bad reply??"
exit
fi
VERSION=$(python3 -c "import semver,sys;print(str(semver.VersionInfo.parse(sys.argv[1]).bump_${mode}()))" ${current})
[[ -z ${VERSION} ]] && {
echo "could not bump version automatically"
exit
}
echo "[release] Releasing ${VERSION}"
}

[[ $(git rev-parse --abbrev-ref HEAD) != main ]] && {
echo "you need to be on the main branch"
exit 1
echo "you need to be on the main branch"
exit 1
}
[[ -z ${VERSION} ]] && bumpversion

Expand All @@ -48,3 +48,4 @@ git commit -S -m "Release ${VERSION} 🥳" ${vfile} Cargo.lock || true
git tag -s ${VERSION} -m "Releasing version ${VERSION}"
git push --tags origin ${VERSION}
git push origin main --no-verify
env CARGO_REGISTRY_TOKEN=$(pass show cargo/token) cargo publish

0 comments on commit 4b7d0f5

Please sign in to comment.