🚸 Mejora la publicación de "crates" en crates.io
This commit is contained in:
parent
efa38b7f77
commit
d69b63e3d4
1 changed files with 56 additions and 25 deletions
|
|
@ -1,62 +1,88 @@
|
||||||
#!/bin/bash
|
#!/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 "$(dirname "$0")"
|
||||||
cd ..
|
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
|
if [ -n "$(git status --porcelain)" ]; then
|
||||||
echo "You have local changes!"
|
echo "You have local changes!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
read -p "Do you want to update the 'latest' branch? (y/n) " -n 1 -r
|
||||||
echo
|
echo
|
||||||
if [[ $REPLY =~ ^[Yy]$ ]]
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
then
|
|
||||||
echo "UPDATING 'latest' branch"
|
echo "UPDATING 'latest' branch"
|
||||||
git checkout latest
|
git checkout latest || { echo "Error switching to 'latest'"; exit 1; }
|
||||||
git merge main
|
git merge main || { echo "Error merging 'main' into 'latest'"; exit 1; }
|
||||||
echo "PUSHING updated 'latest' branch to remote repository"
|
echo "PUSHING updated 'latest' branch to remote repository"
|
||||||
git push origin latest
|
git push origin latest || { echo "Error pushing 'latest'"; exit 1; }
|
||||||
git checkout main
|
git checkout main || { echo "Error switching back to 'main'"; exit 1; }
|
||||||
else
|
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
|
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() {
|
function publish_crate() {
|
||||||
echo -e "\nPUBLISHING $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/')
|
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/')
|
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
|
if [ "$PUBLISHED_VERSION" = "$CURRENT_VERSION" ]; then
|
||||||
echo "Skipping version $CURRENT_VERSION as it already exists on crates.io"
|
echo "Skipping version $CURRENT_VERSION as it already exists on crates.io"
|
||||||
else
|
else
|
||||||
echo "Publishing version $CURRENT_VERSION..."
|
echo "Publishing version $CURRENT_VERSION..."
|
||||||
if [ "$CRATE" = "pagetop" ]; then
|
if [ "$CRATE" = "pagetop" ]; then
|
||||||
cargo publish
|
cargo publish || { echo "Error publishing $CRATE"; exit 1; }
|
||||||
else
|
else
|
||||||
cp ../../LICENSE-MIT .
|
cp "../../LICENSE-MIT" .
|
||||||
cp ../../LICENSE-APACHE .
|
cp "../../LICENSE-APACHE" .
|
||||||
git add LICENSE-MIT LICENSE-APACHE
|
git add LICENSE-MIT LICENSE-APACHE
|
||||||
cargo publish --allow-dirty
|
cargo publish --allow-dirty || { echo "Error publishing $CRATE"; exit 1; }
|
||||||
fi
|
fi
|
||||||
sleep 20
|
sleep $SLEEP_TIME
|
||||||
fi
|
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=(
|
HELPERS=(
|
||||||
pagetop-macros
|
pagetop-macros
|
||||||
pagetop-build
|
pagetop-build
|
||||||
)
|
)
|
||||||
|
PACKAGES=(
|
||||||
|
pagetop-seaorm
|
||||||
|
)
|
||||||
|
|
||||||
# Publish all helper crates
|
# Publica los 'crates' auxiliares
|
||||||
pushd helpers > /dev/null 2>&1
|
pushd helpers > /dev/null 2>&1
|
||||||
for CRATE in "${HELPERS[@]}"; do
|
for CRATE in "${HELPERS[@]}"; do
|
||||||
pushd "$CRATE" > /dev/null 2>&1
|
pushd "$CRATE" > /dev/null 2>&1
|
||||||
|
|
@ -65,9 +91,14 @@ for CRATE in "${HELPERS[@]}"; do
|
||||||
done
|
done
|
||||||
popd > /dev/null 2>&1
|
popd > /dev/null 2>&1
|
||||||
|
|
||||||
# Publish the root crate
|
# Publica la librería principal
|
||||||
CRATE=pagetop; publish_crate
|
CRATE=pagetop; publish_crate
|
||||||
|
|
||||||
# Reset local Git repository to clean licenses after publishing
|
# Publica los paquetes del proyecto
|
||||||
echo -e "\nCleaning local state"
|
pushd packages > /dev/null 2>&1
|
||||||
git reset HEAD --hard
|
for CRATE in "${PACKAGES[@]}"; do
|
||||||
|
pushd "$CRATE" > /dev/null 2>&1
|
||||||
|
publish_crate
|
||||||
|
popd > /dev/null 2>&1
|
||||||
|
done
|
||||||
|
popd > /dev/null 2>&1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue