From edb00bfa16eda3caa9db95c53a671bde5e0b7a76 Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Thu, 5 Dec 2024 14:34:46 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20A=C3=B1ade=20script=20para=20la?= =?UTF-8?q?=20publicaci=C3=B3n=20de=20crates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/publish.sh | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 tools/publish.sh diff --git a/tools/publish.sh b/tools/publish.sh new file mode 100755 index 00000000..168752dd --- /dev/null +++ b/tools/publish.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +# Navigate to the root workspace directory +cd "$(dirname "$0")" +cd .. + +# Check if there are unstaged changes in the Git repository +if [ -n "$(git status --porcelain)" ]; then + echo "You have local changes!" + exit 1 +fi + +# Updates the 'latest' branch with changes from 'main' +read -p "Do you want to update the 'latest' branch? (y/n) " -n 1 -r +echo +if [[ $REPLY =~ ^[Yy]$ ]] +then + echo "UPDATING 'latest' branch" + git checkout latest + git merge main + echo "PUSHING updated 'latest' branch to remote repository" + git push origin latest + git checkout main +else + echo "Omitting update of 'latest' branch" +fi + + +# Define a function to publish a crate to crates.io +function publish_crate() { + echo -e "\nPUBLISHING $CRATE" + # Get the last published version from crates.io + PUBLISHED_VERSION=$(cargo search "$CRATE " | grep "^$CRATE = " | sed -E 's/^.*"([^"]+)".*$/\1/') + # Read the current version from Cargo.toml + CURRENT_VERSION=$(grep '^version = ' Cargo.toml | head -n 1 | sed -E 's/^version = "([^"]+)".*$/\1/') + # Compare the versions + if [ "$PUBLISHED_VERSION" = "$CURRENT_VERSION" ]; then + echo "Skipping version $CURRENT_VERSION as it already exists on crates.io" + else + echo "Publishing version $CURRENT_VERSION..." + if [ "$CRATE" = "pagetop" ]; then + cargo publish + else + cp ../../LICENSE-MIT . + cp ../../LICENSE-APACHE . + git add LICENSE-MIT LICENSE-APACHE + cargo publish --allow-dirty + fi + sleep 20 + fi +} + +# If package A depends on package B, B must come before A in this list +HELPERS=( + pagetop-macros + pagetop-build +) + +# Publish all helper crates +pushd helpers > /dev/null 2>&1 +for CRATE in "${HELPERS[@]}"; do + pushd "$CRATE" > /dev/null 2>&1 + publish_crate + popd > /dev/null 2>&1 +done +popd > /dev/null 2>&1 + +# Publish the root crate +CRATE=pagetop; publish_crate + +# Reset local Git repository to clean licenses after publishing +echo -e "\nCleaning local state" +git reset HEAD --hard