GitHub Actions provides free CI/CD for public repositories. This guide deploys to a Linux server via SSH on every push to main.
Create Deployment Key
ssh-keygen -t ed25519 -C "github-actions-deploy" -f ~/.ssh/github_deploy
cat ~/.ssh/github_deploy.pub >> ~/.ssh/authorized_keys
# Add private key to GitHub: Settings → Secrets → SERVER_SSH_KEY
Workflow File
name: Deploy
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
cd /var/www/app
git pull origin main
composer install --no-dev
php artisan migrate --force
Conclusion
GitHub Actions automates deployments reliably. Our team sets up CI/CD pipelines using GitHub Actions and GitLab CI.
Comments