Skip to content

Instantly share code, notes, and snippets.

@tarikmanoar
Last active April 9, 2025 03:34
Show Gist options
  • Select an option

  • Save tarikmanoar/b1d8a0b51d19851c975166a7d468f421 to your computer and use it in GitHub Desktop.

Select an option

Save tarikmanoar/b1d8a0b51d19851c975166a7d468f421 to your computer and use it in GitHub Desktop.

Revisions

  1. tarikmanoar revised this gist Apr 9, 2025. 1 changed file with 50 additions and 19 deletions.
    69 changes: 50 additions & 19 deletions github-ci-cd.yml
    Original file line number Diff line number Diff line change
    @@ -1,48 +1,71 @@
    name: CI/CD with GitHub Actions
    name: 🎉 Laravel Deploy

    on:
    push:
    branches: [master]
    workflow_dispatch: # Allow manual triggering

    jobs:
    build-and-deploy:
    deploy:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
    - name: 📦 Checkout code
    uses: actions/checkout@v4

    - name: Set up PHP
    - 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: Install Composer dependencies
    run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader

    - name: Set up Node.js
    - name: 🧰 Setup Node.js
    uses: actions/setup-node@v3
    with:
    node-version: '*'
    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 install
    - name: 📥 Install NPM dependencies
    run: npm ci

    - name: Build assets with Vite
    - name: 🔨 Build frontend assets
    run: npm run build

    - name: Copy repository contents via SCP ==MANOAR==
    - 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"
    source: ".,!.git,!.github,!node_modules,!tests,!storage/framework/testing,!.env,!.vscode,!.idea"
    target: ${{ secrets.DIR }}
    verbose: false
    strip_components: 0

    - name: Executing remote commands
    - name: 🛠️ Run deployment commands
    uses: appleboy/ssh-action@master
    with:
    host: ${{ secrets.HOST }}
    @@ -51,8 +74,16 @@ jobs:
    password: ${{ secrets.PASSWORD }}
    script: |
    cd ${{ secrets.DIR }}
    php artisan down --retry=60
    php artisan migrate --force
    php artisan config:cache
    php artisan route:cache
    php artisan view:cache
    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
  2. tarikmanoar created this gist Nov 18, 2024.
    58 changes: 58 additions & 0 deletions github-ci-cd.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    name: CI/CD with GitHub Actions

    on:
    push:
    branches: [master]

    jobs:
    build-and-deploy:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
    uses: actions/checkout@v4

    - name: Set up PHP
    uses: shivammathur/setup-php@v2
    with:
    php-version: '8.3'

    - name: Install Composer dependencies
    run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader

    - name: Set up Node.js
    uses: actions/setup-node@v3
    with:
    node-version: '*'

    - name: Install NPM dependencies
    run: npm install

    - name: Build assets with Vite
    run: npm run build

    - name: Copy repository contents via SCP ==MANOAR==
    uses: appleboy/scp-action@master
    with:
    host: ${{ secrets.HOST }}
    username: ${{ secrets.USERNAME }}
    port: ${{ secrets.PORT }}
    password: ${{ secrets.PASSWORD }}
    source: "*,!.git"
    target: ${{ secrets.DIR }}
    verbose: false

    - name: Executing remote 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 migrate --force
    php artisan config:cache
    php artisan route:cache
    php artisan view:cache
    php artisan storage:link