name: Deploy to Hosting Server on: workflow_dispatch: inputs: confirm: description: 'Type DEPLOY to deploy this branch to the hosting server' required: true default: '' jobs: deploy: name: Manual deploy runs-on: ubuntu-latest if: ${{ github.event.inputs.confirm == 'DEPLOY' }} env: DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }} DEPLOY_USER: ${{ secrets.DEPLOY_USER }} DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }} DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }} steps: - name: Checkout uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '8.2' extensions: dom, gd, intl, mbstring, mysqli, zip coverage: none - name: Validate Composer config run: composer validate --no-check-publish --strict - name: Install production dependencies run: composer install --no-dev --no-interaction --prefer-dist --no-progress --optimize-autoloader - name: Configure SSH run: | test -n "${DEPLOY_HOST}" test -n "${DEPLOY_USER}" test -n "${DEPLOY_PATH}" test -n "${DEPLOY_SSH_KEY}" mkdir -p ~/.ssh chmod 700 ~/.ssh printf '%s\n' "${DEPLOY_SSH_KEY}" > ~/.ssh/deploy_key chmod 600 ~/.ssh/deploy_key SSH_PORT="${DEPLOY_PORT:-22}" ssh-keyscan -p "${SSH_PORT}" "${DEPLOY_HOST}" >> ~/.ssh/known_hosts - name: Deploy files run: | SSH_PORT="${DEPLOY_PORT:-22}" ssh -i ~/.ssh/deploy_key -p "${SSH_PORT}" "${DEPLOY_USER}@${DEPLOY_HOST}" \ "mkdir -p '${DEPLOY_PATH}' '${DEPLOY_PATH}/writable/cache' '${DEPLOY_PATH}/writable/logs' '${DEPLOY_PATH}/writable/session' '${DEPLOY_PATH}/writable/uploads' '${DEPLOY_PATH}/writable/debugbar'" rsync -az --delete \ -e "ssh -i ~/.ssh/deploy_key -p ${SSH_PORT}" \ --exclude '.git/' \ --exclude '.gitea/' \ --exclude '.env' \ --exclude 'env' \ --exclude 'env.*' \ --exclude 'writable/cache/***' \ --exclude 'writable/logs/***' \ --exclude 'writable/session/***' \ --exclude 'writable/uploads/***' \ --exclude 'writable/debugbar/***' \ --exclude 'tests/' \ --exclude 'phpunit.xml*' \ ./ "${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/" - name: Finalize deployment run: | SSH_PORT="${DEPLOY_PORT:-22}" ssh -i ~/.ssh/deploy_key -p "${SSH_PORT}" "${DEPLOY_USER}@${DEPLOY_HOST}" \ "cd '${DEPLOY_PATH}' && php spark cache:clear || true"