set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
while read local_ref local_sha remote_ref remote_sha; do
if [[ $local_ref == refs/tags/* ]]; then
tag_name=${local_ref#refs/tags/}
if [[ $tag_name =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
tag_version=${tag_name#v}
echo -e "${YELLOW}Validating version tag: $tag_name${NC}"
if [ ! -f "Cargo.toml" ]; then
echo -e "${RED}Error: Cargo.toml not found${NC}"
exit 1
fi
cargo_version=$(grep '^version = ' Cargo.toml | head -n1 | sed 's/version = "\(.*\)"/\1/')
echo " Tag version: $tag_version"
echo " Cargo.toml version: $cargo_version"
if [ "$tag_version" != "$cargo_version" ]; then
echo -e "${RED}❌ ERROR: Version mismatch detected!${NC}"
echo -e "Cannot push tag $tag_name because it doesn't match Cargo.toml version ($cargo_version)"
echo ""
echo -e "${YELLOW}To fix this:${NC}"
echo "1. Update Cargo.toml version to $tag_version, OR"
echo "2. Delete this tag and create one matching Cargo.toml version ($cargo_version)"
echo "3. Use scripts/release.sh to automate releases safely"
echo ""
echo "Commands to fix:"
echo " git tag -d $tag_name # Delete the tag"
echo " ./scripts/release.sh $cargo_version # Create proper release"
exit 1
fi
echo -e "${GREEN}✅ Version validation passed${NC}"
fi
fi
done
exit 0