Files
cv-site/.github/workflows/deploy.yml
T
juanatsap b167378526 fix: update workflows for Go 1.25.1 and SSH deployment
Test workflow:
- Upgrade golangci-lint-action from v6 to v7
- v7 is required for golangci-lint v2.x support
- Remove skip-cache as v7 handles caching better

Deploy workflow:
- Fix SSH heredoc to use unquoted ENDSSH delimiter
- Allows environment variables to expand in remote session
- Fixes "Permission denied" by properly passing REPO_PATH and SERVICE_NAME
2025-10-31 12:20:42 +00:00

91 lines
2.8 KiB
YAML

name: Deploy CV Server
on:
push:
branches:
- main
workflow_dispatch: # Allow manual deployment from GitHub UI
jobs:
deploy:
name: Pull and Restart
runs-on: ubuntu-latest
steps:
- name: Deploy to server
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_PORT: ${{ secrets.SSH_PORT || '22' }}
SERVICE_NAME: ${{ secrets.SERVICE_NAME || 'cv' }}
REPO_PATH: ${{ secrets.REPO_PATH || '/home/txeo/Git/yo/cv' }}
run: |
echo "🚀 Deploying to server..."
# Setup SSH
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
ssh-keyscan -p $SSH_PORT -H $SSH_HOST >> ~/.ssh/known_hosts
# Pull latest code and restart service
echo "🔄 Pulling latest code and restarting service..."
ssh -i ~/.ssh/deploy_key -p $SSH_PORT $SSH_USER@$SSH_HOST << ENDSSH
set -e
echo "📥 Pulling latest changes..."
cd $REPO_PATH
git pull origin main
echo "🔄 Restarting service..."
sudo systemctl restart $SERVICE_NAME
echo "⏳ Waiting for service to start..."
sleep 3
# Check service status
if sudo systemctl is-active --quiet $SERVICE_NAME; then
echo "✅ Service restarted successfully"
sudo systemctl status $SERVICE_NAME --no-pager -l
else
echo "❌ Service failed to start"
sudo journalctl -u $SERVICE_NAME -n 50 --no-pager
exit 1
fi
ENDSSH
# Cleanup
rm ~/.ssh/deploy_key
echo "✅ Deployment completed successfully!"
- name: Verify deployment
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_PORT: ${{ secrets.SSH_PORT || '22' }}
run: |
echo "🔍 Verifying deployment..."
# Setup SSH for verification
echo "$SSH_PRIVATE_KEY" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
# Test health endpoint
ssh -i ~/.ssh/deploy_key -p $SSH_PORT $SSH_USER@$SSH_HOST << 'ENDSSH'
echo "Testing health endpoint..."
sleep 2
if curl -f http://localhost:1999/health > /dev/null 2>&1; then
echo "✅ Health check passed"
curl http://localhost:1999/health
else
echo "❌ Health check failed"
exit 1
fi
ENDSSH
rm ~/.ssh/deploy_key
echo "✅ Deployment verification complete!"