From d69b63e3d4749d04ef0cd326dd2c4eb4fcf7bf3d Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Fri, 6 Dec 2024 20:58:38 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20Mejora=20la=20publicaci=C3=B3n?= =?UTF-8?q?=20de=20"crates"=20en=20crates.io?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/publish.sh | 81 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 25 deletions(-) diff --git a/tools/publish.sh b/tools/publish.sh index 168752dd..16aaf3b5 100755 --- a/tools/publish.sh +++ b/tools/publish.sh @@ -1,62 +1,88 @@ #!/bin/bash -# Navigate to the root workspace directory +# Este script automatiza la publicación de los 'crates' del proyecto PageTop en crates.io + +# Configuración global, tiempo de espera en segundos entre publicaciones +SLEEP_TIME=20 + +# Comprueba que las herramientas necesarias están disponibles +command -v git > /dev/null || { echo "Error: Git is not installed"; exit 1; } +command -v cargo > /dev/null || { echo "Error: Cargo is not installed"; exit 1; } + +# Cambia al directorio raíz del espacio de trabajo cd "$(dirname "$0")" cd .. -# Check if there are unstaged changes in the Git repository +# Verifica si el repositorio del proyecto tiene cambios locales sin preparar if [ -n "$(git status --porcelain)" ]; then echo "You have local changes!" exit 1 fi -# Updates the 'latest' branch with changes from 'main' +# Actualiza la rama 'latest' con los cambios de 'main' read -p "Do you want to update the 'latest' branch? (y/n) " -n 1 -r echo -if [[ $REPLY =~ ^[Yy]$ ]] -then +if [[ $REPLY =~ ^[Yy]$ ]]; then echo "UPDATING 'latest' branch" - git checkout latest - git merge main + git checkout latest || { echo "Error switching to 'latest'"; exit 1; } + git merge main || { echo "Error merging 'main' into 'latest'"; exit 1; } echo "PUSHING updated 'latest' branch to remote repository" - git push origin latest - git checkout main + git push origin latest || { echo "Error pushing 'latest'"; exit 1; } + git checkout main || { echo "Error switching back to 'main'"; exit 1; } else - echo "Omitting update of 'latest' branch" + read -p "Are you sure you don't want to update the 'latest' branch? (y/n) " -n 1 -r + echo + if [[ $REPLY =~ ^[Nn]$ ]]; then + echo "Exiting without completing the process" + exit 1 + fi + echo "Continuing without updating the 'latest' branch" fi +# Función para restaurar el estado local del repositorio +function clean_up() { + echo -e "\nCleaning local state" + git reset HEAD --hard > /dev/null 2>&1 +} -# Define a function to publish a crate to crates.io +# Registra la función 'clean_up' para que se ejecute al finalizar el script, incluso tras errores +trap clean_up EXIT + +# Función para publicar un 'crate' en crates.io function publish_crate() { echo -e "\nPUBLISHING $CRATE" - # Get the last published version from crates.io + # Obtiene la última versión publicada en crates.io PUBLISHED_VERSION=$(cargo search "$CRATE " | grep "^$CRATE = " | sed -E 's/^.*"([^"]+)".*$/\1/') - # Read the current version from Cargo.toml + # Lee la versión actual desde Cargo.toml CURRENT_VERSION=$(grep '^version = ' Cargo.toml | head -n 1 | sed -E 's/^version = "([^"]+)".*$/\1/') - # Compare the versions + + # Compara las versiones y publica si es necesario 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 + cargo publish || { echo "Error publishing $CRATE"; exit 1; } else - cp ../../LICENSE-MIT . - cp ../../LICENSE-APACHE . + cp "../../LICENSE-MIT" . + cp "../../LICENSE-APACHE" . git add LICENSE-MIT LICENSE-APACHE - cargo publish --allow-dirty + cargo publish --allow-dirty || { echo "Error publishing $CRATE"; exit 1; } fi - sleep 20 + sleep $SLEEP_TIME fi } -# If package A depends on package B, B must come before A in this list +# Si el 'crate' A depende del 'crate' B, entonces B debe aparecer antes que A en estas listas HELPERS=( pagetop-macros pagetop-build ) +PACKAGES=( + pagetop-seaorm +) -# Publish all helper crates +# Publica los 'crates' auxiliares pushd helpers > /dev/null 2>&1 for CRATE in "${HELPERS[@]}"; do pushd "$CRATE" > /dev/null 2>&1 @@ -65,9 +91,14 @@ for CRATE in "${HELPERS[@]}"; do done popd > /dev/null 2>&1 -# Publish the root crate +# Publica la librería principal CRATE=pagetop; publish_crate -# Reset local Git repository to clean licenses after publishing -echo -e "\nCleaning local state" -git reset HEAD --hard +# Publica los paquetes del proyecto +pushd packages > /dev/null 2>&1 +for CRATE in "${PACKAGES[@]}"; do + pushd "$CRATE" > /dev/null 2>&1 + publish_crate + popd > /dev/null 2>&1 +done +popd > /dev/null 2>&1