Last active
April 9, 2025 03:34
-
-
Save tarikmanoar/b1d8a0b51d19851c975166a7d468f421 to your computer and use it in GitHub Desktop.
This gist help you to deploy laravel application from github to your server using ssh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: π Laravel Deploy | |
on: | |
push: | |
branches: [master] | |
workflow_dispatch: # Allow manual triggering | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: π¦ Checkout code | |
uses: actions/checkout@v4 | |
- name: βοΈ Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '8.3' | |
extensions: mbstring, xml, ctype, iconv, intl, pdo_mysql, bcmath, zip, curl, fileinfo, tokenizer, dom, json, exif, gd, imagick, mysqli, redis, sodium, pgsql, sqlite3 | |
coverage: none | |
- name: π§° Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 'lts/*' | |
cache: 'npm' | |
- name: β»οΈ Cache Composer dependencies | |
id: composer-cache | |
uses: actions/cache@v3 | |
with: | |
path: vendor | |
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | |
restore-keys: ${{ runner.os }}-composer- | |
- name: π§© Install Composer dependencies | |
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader | |
- name: Run PHP Code Style (Pint) | |
run: vendor/bin/pint | |
- name: β»οΈ Cache NPM dependencies | |
id: npm-cache | |
uses: actions/cache@v3 | |
with: | |
path: node_modules | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: ${{ runner.os }}-node- | |
- name: π₯ Install NPM dependencies | |
run: npm ci | |
- name: π¨ Build frontend assets | |
run: npm run build | |
- name: π Upload to server via SCP | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
port: ${{ secrets.PORT }} | |
password: ${{ secrets.PASSWORD }} | |
source: ".,!.git,!.github,!node_modules,!tests,!storage/framework/testing,!.env,!.vscode,!.idea" | |
target: ${{ secrets.DIR }} | |
strip_components: 0 | |
- name: π οΈ Run deployment commands | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
port: ${{ secrets.PORT }} | |
password: ${{ secrets.PASSWORD }} | |
script: | | |
cd ${{ secrets.DIR }} | |
php artisan down --retry=60 | |
php artisan migrate --force | |
php artisan optimize:clear | |
php artisan optimize | |
php artisan storage:link | |
# Verify deployment succeeded | |
if php artisan --version > /dev/null; then | |
php artisan up | |
echo "Deployment successful!" | |
else | |
echo "Deployment failed, site remains in maintenance mode" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment