Skip to content

Update main.yml

Update main.yml #16

Workflow file for this run

name: Sync & Build Docs
on:
push:
branches:
- main
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Build Documentation
run: npm run build
- name: Configure SSH
if: success()
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts
- name: Test SSH Connection
if: success()
run: ssh -o StrictHostKeyChecking=no ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }} "echo SSH connection successful"
- name: Sync files to server
if: success()
run: rsync -avz --exclude 'node_modules' --exclude '.git' ./ ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }}:/var/www/teramont-docs
- name: Run build on server
if: success()
run: |
ssh ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }} << 'EOF'
export NVM_DIR="/root/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
export PATH="/root/.nvm/versions/node/v18.17.1/bin:$PATH"
cd /var/www/teramont-docs
echo "📦 Installing dependencies..."
npm install
echo "🛠️ Running build..."
if npm run build; then
echo "🚀 Build complete!"
else
echo "❌ Build failed! Deployment aborted."
exit 1
fi
EOF