update ci.yaml 2
Some checks failed
CI Deploy Laravel / Test (push) Successful in 1m47s
CI Deploy Laravel / Build (push) Successful in 3m17s
CI Deploy Laravel / Deploy (push) Failing after 1m25s

This commit is contained in:
pesu98
2026-05-13 15:13:09 +08:00
parent 5289b0b215
commit d00fea4ecb

View File

@@ -34,6 +34,7 @@ jobs:
run: | run: |
cp .env.example .env cp .env.example .env
php artisan key:generate --force php artisan key:generate --force
- name: Install NPM dependencies - name: Install NPM dependencies
run: npm ci || npm install --no-audit --no-fund run: npm ci || npm install --no-audit --no-fund
@@ -78,6 +79,7 @@ jobs:
uses: actions/upload-artifact@v3.2.2-node20 uses: actions/upload-artifact@v3.2.2-node20
with: with:
name: laravel-build name: laravel-build
include-hidden-files: true
path: | path: |
app app
bootstrap bootstrap
@@ -106,40 +108,24 @@ jobs:
name: laravel-build name: laravel-build
path: release path: release
- name: Install SSH deployment tools - name: Install sshpass
run: sudo apt-get update && sudo apt-get install -y openssh-client sshpass rsync run: sudo apt-get update && sudo apt-get install -y sshpass
- name: Configure SSH - name: Install rsync
env: run: sudo apt-get install -y rsync
DEPLOY_KNOWN_HOSTS: ${{ secrets.DEPLOY_KNOWN_HOSTS }}
run: | - name: Add SSH host to known_hosts
mkdir -p ~/.ssh
chmod 700 ~/.ssh
if [ -n "$DEPLOY_KNOWN_HOSTS" ]; then
echo "$DEPLOY_KNOWN_HOSTS" >> ~/.ssh/known_hosts
chmod 600 ~/.ssh/known_hosts
fi
- name: Test SSH password login
env: env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }} DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }} DEPLOY_KNOWN_HOSTS: ${{ secrets.DEPLOY_KNOWN_HOSTS }}
DEPLOY_PASSWORD: ${{ secrets.DEPLOY_PASSWORD }}
SSHPASS: ${{ secrets.DEPLOY_PASSWORD }}
run: | run: |
if [ -z "$DEPLOY_PASSWORD" ]; then if [ -n "$DEPLOY_KNOWN_HOSTS" ]; then
echo "DEPLOY_PASSWORD secret is empty." echo "$DEPLOY_KNOWN_HOSTS" >> ~/.ssh/known_hosts
exit 1 else
ssh-keyscan -p "${DEPLOY_PORT:-22}" "$DEPLOY_HOST" >> ~/.ssh/known_hosts
fi fi
sshpass -e ssh \
-p "${DEPLOY_PORT:-22}" \
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null \
-o PreferredAuthentications=password \
-o PubkeyAuthentication=no \
-o NumberOfPasswordPrompts=1 \
"${DEPLOY_USER}@${DEPLOY_HOST}" \
"echo SSH connection ok"
- name: Deploy files with rsync over SSH - name: Deploy files with rsync over SSH
env: env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
@@ -153,9 +139,10 @@ jobs:
echo "DEPLOY_PASSWORD secret is empty." echo "DEPLOY_PASSWORD secret is empty."
exit 1 exit 1
fi fi
mkdir -p ~/.ssh mkdir -p ~/.ssh
sshpass -e rsync -az --delete \ rsync -az --delete \
-e "ssh -p ${DEPLOY_PORT:-22} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o PreferredAuthentications=password -o PubkeyAuthentication=no -o NumberOfPasswordPrompts=1" \ -e "sshpass -e ssh -p ${DEPLOY_PORT:-22}" \
--exclude='.env' \ --exclude='.env' \
--exclude='storage/' \ --exclude='storage/' \
--exclude='storage/logs/*' \ --exclude='storage/logs/*' \
@@ -163,6 +150,9 @@ jobs:
--exclude='storage/framework/sessions/*' \ --exclude='storage/framework/sessions/*' \
--exclude='storage/framework/views/*' \ --exclude='storage/framework/views/*' \
release/ "${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}" release/ "${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}"
sshpass -e ssh -p "${DEPLOY_PORT:-22}" "${DEPLOY_USER}@${DEPLOY_HOST}" "test -f \"${DEPLOY_PATH}/public/.htaccess\" || { echo 'public/.htaccess missing after rsync'; exit 1; }"
- name: Create .env on server from secret - name: Create .env on server from secret
env: env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
@@ -177,19 +167,14 @@ jobs:
echo "DEPLOY_ENV_FILE secret is empty." echo "DEPLOY_ENV_FILE secret is empty."
exit 1 exit 1
fi fi
if [ -z "$DEPLOY_PASSWORD" ]; then if [ -z "$DEPLOY_PASSWORD" ]; then
echo "DEPLOY_PASSWORD secret is empty." echo "DEPLOY_PASSWORD secret is empty."
exit 1 exit 1
fi fi
printf '%s' "$DEPLOY_ENV_FILE" | sshpass -e ssh \
-p "${DEPLOY_PORT:-22}" \ printf '%s' "$DEPLOY_ENV_FILE" | sshpass -e ssh -p "${DEPLOY_PORT:-22}" "${DEPLOY_USER}@${DEPLOY_HOST}" "mkdir -p \"${DEPLOY_PATH}\" && cat > \"${DEPLOY_PATH}/.env\" && chmod 600 \"${DEPLOY_PATH}/.env\""
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null \
-o PreferredAuthentications=password \
-o PubkeyAuthentication=no \
-o NumberOfPasswordPrompts=1 \
"${DEPLOY_USER}@${DEPLOY_HOST}" \
"mkdir -p \"${DEPLOY_PATH}\" && cat > \"${DEPLOY_PATH}/.env\" && chmod 600 \"${DEPLOY_PATH}/.env\""
- name: Run post-deploy Laravel commands - name: Run post-deploy Laravel commands
env: env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
@@ -203,15 +188,9 @@ jobs:
echo "DEPLOY_PASSWORD secret is empty." echo "DEPLOY_PASSWORD secret is empty."
exit 1 exit 1
fi fi
sshpass -e ssh \
-p "${DEPLOY_PORT:-22}" \ sshpass -e ssh -p "${DEPLOY_PORT:-22}" "${DEPLOY_USER}@${DEPLOY_HOST}" "cd ${DEPLOY_PATH} && mkdir -p storage/framework/cache/data storage/framework/sessions storage/framework/views storage/logs bootstrap/cache && chmod -R ug+rw storage bootstrap/cache && php artisan optimize:clear && php artisan config:cache && php artisan route:cache && php artisan view:cache"
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null \
-o PreferredAuthentications=password \
-o PubkeyAuthentication=no \
-o NumberOfPasswordPrompts=1 \
"${DEPLOY_USER}@${DEPLOY_HOST}" \
"cd ${DEPLOY_PATH} && mkdir -p storage/framework/cache/data storage/framework/sessions storage/framework/views storage/logs bootstrap/cache && chmod -R ug+rw storage bootstrap/cache && php artisan optimize:clear && php artisan config:cache && php artisan route:cache && php artisan view:cache"
# Required repository secrets: # Required repository secrets:
# - DEPLOY_HOST: Server hostname or IP. # - DEPLOY_HOST: Server hostname or IP.
# - DEPLOY_PORT: SSH port (optional, defaults to 22). # - DEPLOY_PORT: SSH port (optional, defaults to 22).