Improve build script with error handling and automated commit process

This commit is contained in:
Iker García Calviño 2025-02-24 21:27:19 +01:00
parent 6979aef88c
commit e6454972f4

51
src/static/app/build.sh Executable file → Normal file
View File

@ -1,27 +1,36 @@
#!/bin/bash
echo "Running vite build..."
if vite build; then
echo "Vite build successful."
else
echo "Vite build failed. Exiting."
set -e # Exit script on any command failure
# Check if Vite is installed
if ! command -v vite &>/dev/null; then
echo "[ERROR] Vite is not installed. Please install it before running this script."
exit 1
fi
echo "Checking for changes to commit..."
if git diff-index --quiet HEAD --; then
# Check if Git is installed
if ! command -v git &>/dev/null; then
echo "[ERROR] Git is not installed. Please install it before running this script."
exit 1
fi
# Run Vite build
echo "Running Vite build..."
vite build
echo "[SUCCESS] Vite build completed."
# Check if there are uncommitted changes
if ! git diff --quiet || ! git diff --cached --quiet; then
echo "Changes detected. Committing..."
if git commit -a; then
echo "Git commit successful."
else
echo "Git commit failed. Exiting."
exit 1
fi
git add .
git commit -m "Automated build commit at $(date '+%Y-%m-%d %H:%M:%S')"
echo "[SUCCESS] Git commit successful."
else
echo "No changes to commit. Skipping commit."
fi
echo "Pushing changes to remote..."
if git push; then
echo "Git push successful."
else
echo "Git push failed. Exiting."
exit 1
echo "[INFO] No changes to commit. Skipping commit."
fi
# Push changes to remote repository
echo "Pushing changes..."
git push origin "$(git rev-parse --abbrev-ref HEAD)"
echo "[SUCCESS] Changes pushed successfully."