Skip to content

Instantly share code, notes, and snippets.

@some1else
Created March 1, 2024 11:58
Show Gist options
  • Save some1else/06b5dd668ce6cb1ae432d38766169f08 to your computer and use it in GitHub Desktop.
Save some1else/06b5dd668ce6cb1ae432d38766169f08 to your computer and use it in GitHub Desktop.
Vite & Rails: Build, commit & deploy
#!/bin/sh
start_time=$(date +%s)
trap 'end_time=$(date +%s); echo "\n *** Completed in: $((end_time - start_time)) seconds\n"' EXIT
echo "\033[35m\n *** Build & deploy to production\n\033[0m"
# Guards
cd app-frontend
if [[ -n $(git status -s) ]]; then
echo "\033[31m\n *** Error: There are uncommitted changes in the frontend repo\n\033[0m"
read -p " *** Do you want to commit them? (y/n): " user_choice
if [[ $user_choice =~ ^[Yy]$ ]]; then
echo "\033[32m\n *** Commiting changes to frontend repo\n\033[0m"
git add .
git commit -m "Build & deploy"
git push
else
echo "\033[31m\n *** Exited\n\033[0m"
exit 1
fi
fi
cd ..
cd app-backend
if [[ -n $(git status -s) ]]; then
echo "\033[31m\n *** Error: There are uncommitted changes in the backend repo\n\033[0m"
read -p "\n *** Do you want to commit them? (y/n): " user_choice
if [[ $user_choice =~ ^[Yy]$ ]]; then
echo "\033[32m\n *** Commiting changes to backend repo\n\033[0m"
git add .
git commit -m "Build & deploy"
git push
else
echo "\033[31m\n *** Exited\n\033[0m"
exit 1
fi
fi
cd ..
# Frontend build
echo "\033[32m\n *** Building frontend\n\033[0m"
cd app-frontend
yarn install
yarn build
cd ..
# Move built assets into place
echo "\033[32m\n *** Moving dist/assets into public/static\n\033[0m"
cd app-backend
rm -f public/static/js/*
cp ../app-frontend/dist/assets/*.js public/static/js/
rm -f public/static/css/*
cp ../app-frontend/dist/assets/*.css public/static/css/
# Show changed files
git add .
git status
echo "\033[32m\n *** Pushing changes to backend repo\n\033[0m"
git commit -m "Build frontend."
git push
echo "\033[32m\n *** Deploying to production\n\033[0m"
bundle exec cap production deploy
cd ..
echo "\033[32m\n *** Done\n\033[0m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment