From 3c3dfc3c64cb1d6f5e4f21ee85ea6339bc5de74c Mon Sep 17 00:00:00 2001 From: Diego Andres Ramirez Mejia <157324739+DiegoAndresRamirez@users.noreply.github.com> Date: Sat, 30 Nov 2024 20:08:48 -0500 Subject: [PATCH] Update deploy-main.yml --- .github/workflows/deploy-main.yml | 42 +++++++++++++++++-------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/.github/workflows/deploy-main.yml b/.github/workflows/deploy-main.yml index 3f4e50f..e1ae7e1 100644 --- a/.github/workflows/deploy-main.yml +++ b/.github/workflows/deploy-main.yml @@ -1,27 +1,31 @@ name: CI/CD - Crudzaso + on: push: - branches: [ main ] + branches: + - main + jobs: build-and-deploy: runs-on: ubuntu-latest steps: - - name: Fix git ownership - run: | - git config --global --add safe.directory "${{ secrets.PATH }}" - - name: Executing remote SSH commands using password - uses: appleboy/ssh-action@v0.1.6 + - name: Checkout Repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up SSH Agent + uses: webfactory/ssh-agent@v0.9.0 with: - host: ${{ secrets.HOST_SERVER }} - username: ${{ secrets.USERNAME_SERVER }} - password: ${{ secrets.PASSWORD_SERVER }} - port: ${{ secrets.PORT_SERVER }} - script: | - cd "${{ secrets.PATH }}" - git pull origin main - git fetch - echo '${{ secrets.ENV_FILE }}' > .env - composer install --no-dev --optimize-autoloader - composer dump-autoload - php artisan migrate:fresh --seed || (echo "Migrations failed, but continuing deployment" && true) - php artisan optimize:clear + ssh-private-key: ${{ secrets.SSH_KEY_SERVER }} + + - name: Deploy Application + run: | + ssh -o StrictHostKeyChecking=no ${{ secrets.USERNAME_SERVER }}@${{ secrets.HOST_SERVER }} << 'EOF' + cd ${{ secrets.PATH }} + git pull origin main + echo '${{ secrets.ENV_FILE }}' > .env + composer install --no-dev --optimize-autoloader + php artisan migrate --force + php artisan optimize:clear + EOF