diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index beb8c66..ec6770a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: Deploy Portal +name: Deploy Portal API on: push: @@ -8,39 +8,48 @@ on: jobs: deploy: - name: Deploy to Production runs-on: ubuntu-latest steps: - - name: Deploy via SSH + - name: Deploy uses: appleboy/ssh-action@v1.2.0 with: host: ${{ secrets.HOST }} username: ${{ secrets.USERNAME }} - password: ${{ secrets.SSH_PASSWORD }} + key: ${{ secrets.SSH_PRIVATE_KEY }} port: ${{ secrets.PORT }} script_stop: true script: | set -e - DEPLOY_PATH="/var/www/vhosts/api.portal.tgs.com.vn/httpdocs" + + BRANCH="production" REPO_URL="${{ secrets.REPO_URL }}" - if [ ! -d "$DEPLOY_PATH/.git" ]; then - echo "First deploy - cloning repository..." - git clone -b product "$REPO_URL" "$DEPLOY_PATH" + cd httpdocs + + if [ ! -d ".git" ]; then + echo "First deploy..." + + rm -rf ./* + + git clone -b "$BRANCH" "$REPO_URL" . else - echo "Pulling latest code..." - cd "$DEPLOY_PATH" - git pull origin product + echo "Updating source..." + + git fetch origin + + git reset --hard origin/$BRANCH fi - echo "Installing dependencies..." - composer install --no-dev --optimize-autoloader --no-interaction --no-progress + composer install \ + --no-dev \ + --optimize-autoloader \ + --no-interaction - echo "Running migrations..." php artisan migrate --force - echo "Optimizing..." php artisan optimize + php artisan queue:restart || true + echo "Deploy completed."