Skip to content

Merge pull request #4 from coundia/dev #19

Merge pull request #4 from coundia/dev

Merge pull request #4 from coundia/dev #19

Workflow file for this run

name: Deploy to OVH Server
on:
push:
branches: [main]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Clean install dependencies
run: |
rm -rf node_modules package-lock.json
npm install
- name: Build Astro project
run: npm run build
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: astro-build
path: dist/
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: astro-build
path: dist/
- name: Deploy to OVH Server
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SERVER_USER: ${{ secrets.SERVER_USER }}
SERVER_IP: ${{ secrets.SERVER_IP }}
SERVER_PATH: "/var/www/pcoundia.com/"
run: |
# Vérification des variables
if [[ -z "$SSH_PRIVATE_KEY" || -z "$SERVER_USER" || -z "$SERVER_IP" ]]; then
echo "Error: Missing environment variables!"
exit 1
fi
# Configuration of SSH
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" | tr -d '\r' | tee ~/.ssh/id_rsa > /dev/null
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H "$SERVER_IP" >> ~/.ssh/known_hosts
# Test SSH
ssh -o StrictHostKeyChecking=no "$SERVER_USER@$SERVER_IP" "echo 'SSH connection successful'"
rsync -avz --chown=$SERVER_USER:www-data --chmod=775 --delete dist/ "$SERVER_USER@$SERVER_IP:$SERVER_PATH"