Skip to content

Merge branch 'main' of github.com:phutd/test-github-action #1

Merge branch 'main' of github.com:phutd/test-github-action

Merge branch 'main' of github.com:phutd/test-github-action #1

name: Deploy to Production
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: main
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
- name: Install Composer dependencies
run: composer install --prefer-dist --no-interaction --no-dev
- name: Upload files to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.PRODUCTION_SERVER_HOST }}
username: ${{ secrets.PRODUCTION_SERVER_USERNAME }}
key: "${{ secrets.PRODUCTION_SERVER_SSH_KEY }}"
source: "./"
target: "/tmp/new-version"
- name: Setup new version on Server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PRODUCTION_SERVER_HOST }}
username: ${{ secrets.PRODUCTION_SERVER_USERNAME }}
key: ${{ secrets.PRODUCTION_SERVER_SSH_KEY }}
script: |
# Stop Nginx
sudo service nginx stop
# Copy the .env file to the new version
cp /var/www/app/.env /tmp/new-version/.env
# Remove the old version
cd /var/www
sudo rm -rf app
# Move the new version to the right place
sudo mv /tmp/new-version app
# Update ownership and permissions
sudo chown -R $USER:www-data app
sudo chmod -R 775 app/storage
sudo chmod -R 775 app/bootstrap/cache
# Migrate the database
cd app
php artisan migrate --force --no-interaction
# Start Nginx
sudo service nginx start