Created
July 27, 2025 05:16
-
-
Save arif98741/2b7c33267abc44e3b8add4dc6d96f3f0 to your computer and use it in GitHub Desktop.
SSH Github action Deployment pipeline
This file contains hidden or 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: Deployment to SSH Server | |
on: | |
push: | |
branches: | |
- dev | |
- production | |
pull_request: | |
branches: | |
- dev | |
- master | |
- production | |
jobs: | |
check-php-version: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
php-version: [ 8.2, 8.3 ] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up PHP ${{ matrix.php-version }} | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: ${{ matrix.php-version }} | |
extensions: mbstring, intl, bcmath, curl, json | |
- name: Install Composer | |
run: curl -sS https://getcomposer.org/installer | php | |
- name: Install dependencies with Composer | |
run: php composer.phar install --no-progress --prefer-dist | |
- name: Run PHPUnit tests (if applicable) | |
run: vendor/bin/phpunit --configuration phpunit.xml.dist || true | |
deployment: | |
runs-on: ubuntu-latest | |
needs: check-php-version | |
if: github.ref == 'refs/heads/production' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Executing remote command on server | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
port: ${{ secrets.SSH_PORT }} | |
password: ${{ secrets.SSH_PASSWORD }} | |
script: | | |
cd public_html | |
git checkout production | |
git pull | |
php artisan optimize:clear | |
php artisan config:cache | |
php artisan view:cache | |
php artisan route:cache | |
notification-to-admin: | |
runs-on: ubuntu-latest | |
needs: deployment | |
if: github.ref == 'refs/heads/production' #it should be on production branch | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Connection to Server and Send Notification | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
port: ${{ secrets.SSH_PORT }} | |
password: ${{ secrets.SSH_PASSWORD }} | |
script: | | |
cd public_html | |
php artisan app:send-success-deployment-mail --commit="${{ github.sha }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment