#!/bin/bash set -e if [ $(git diff HEAD --name-only | wc -l) -ne 0 ]; then echo "Please commit all changes first" >&2 exit 1 fi VERSION=$(grep ^version Cargo.toml | cut -d'"' -f2) if ! head -1 RELEASE_NOTES.md | grep "# Version ${VERSION}$" >/dev/null; then echo "RELEASE_NOTES.md doesn't have Version ${VERSION} at start" >&2 exit 1 fi if [ $(git tag -l v${VERSION}) ]; then echo "A tag already exists for version ${VERSION}" >&2 exit 1 fi MIN_RUST_VER=$(grep ^rust-version Cargo.toml | cut -d'"' -f2) if [ -z "$MIN_RUST_VER" ]; then echo "Failed to determine minimum rust version" >&2 exit 1 fi echo "Releasing version ${VERSION} with minimum rust version ${MIN_RUST_VER}" SB=$HOME/bin/sb if [ ! -e $SB ]; then SB="" fi $SB cargo clippy -- -D warnings $SB cargo clippy --no-default-features -- -D warnings $SB cargo test $SB cargo run --release -- acl --no-ui --ignore-newer-config-versions --save-requests --fail-on-warnings $SB cargo run --release -- acl --no-ui --ignore-newer-config-versions --save-requests --fail-on-warnings test $SB cargo +${MIN_RUST_VER}-x86_64-unknown-linux-gnu test --all $SB cargo package git tag v${VERSION} git push origin git push origin refs/tags/v${VERSION} cargo publish sleep 120 echo "Waiting for release build to complete..." for i in {1..1000}; do code=$(curl -o /dev/null --silent -Iw '%{http_code}' https://github.com/cackle-rs/cackle/releases/download/v${VERSION}/cackle-v${VERSION}-x86_64-unknown-linux-musl.tar.gz) if [ $code != 404 ]; then break fi if [ $i = 10 ]; then echo "Giving up waiting for release. Last code was $code" fi sleep 60 done echo "Release build is available" ( cd ../cackle-action git checkout latest perl -pi -e 's/default: "0.*"$/default: "'$VERSION'"/' action.yml git add action.yml git commit -m "Release $VERSION" git push origin latest git checkout -b $VERSION git push origin $VERSION git checkout latest )