This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy Next.js App to PM2 Server | |
on: | |
push: | |
branches: [dev, main] | |
#on: | |
# workflow_run: | |
# workflows: ["Run front end tests"] | |
# types: | |
# - completed | |
jobs: | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
steps: | |
- name: Pull using ssh | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.OVH_SERVER_HOST }} | |
username: ${{ secrets.OVH_SERVER_USERNAME }} | |
password: ${{ secrets.OVH_SERVER_PASSWORD }} | |
port: ${{ secrets.OVH_SERVER_PORT }} | |
# This script navigates to the Next.js application directory, fetches the latest changes from the repository, | |
# and pulls them. It then checks if there have been any changes to the package.json file since the last commit. | |
# If there have been changes, it runs 'pnpm i' to install or update dependencies accordingly. | |
script: | | |
cd /var/www/next-auth | |
sudo git fetch | |
sudo git pull | |
CHANGED=$(git diff --name-only HEAD HEAD~1 | grep package.json | wc -l) | |
if [ "$CHANGED" -ne "0" ]; then | |
echo "🔄 Package.json update detected, installing node modules... " | |
sudo pnpm i | |
fi | |
echo "📦Building project" | |
sudo pnpm run build |