From 9427294682b39686a0c494917368ec149146ac57 Mon Sep 17 00:00:00 2001 From: starmen1265 Date: Sun, 1 Mar 2026 01:01:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BD=BF=E7=94=A8=20container=20?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=20PHP=20=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - test.yml / ci.yml: 使用 composer:latest 镜像 (含 PHP) - deploy.yml: 使用 alpine:latest 镜像 + SSH 密钥配置 - 解决 runner 默认环境缺少 PHP 的问题 --- .gitea/workflows/ci.yml | 7 ++++++- .gitea/workflows/deploy.yml | 30 ++++++++++++++++++++++++++++-- .gitea/workflows/test.yml | 11 +++++------ 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 91c6bec..5672dd1 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -11,16 +11,18 @@ jobs: lint: name: 代码检查 runs-on: linux + container: + image: composer:latest steps: - name: 检出代码 run: | + apk add --no-cache git git clone -b ${{ github.ref_name }} ${{ github.server_url }}/${{ github.repository }}.git . git checkout ${{ github.sha }} - name: PHP 语法检查 run: | echo "📝 PHP 语法检查..." - echo "PHP 版本: $(php -v | head -1)" errors=0 for file in $(find . -name "*.php" -not -path "./vendor/*"); do output=$(php -l "$file" 2>&1) @@ -44,10 +46,13 @@ jobs: test: name: 单元测试 runs-on: linux + container: + image: composer:latest needs: lint steps: - name: 检出代码 run: | + apk add --no-cache git git clone -b ${{ github.ref_name }} ${{ github.server_url }}/${{ github.repository }}.git . git checkout ${{ github.sha }} diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index ab98b1f..385eb94 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -19,12 +19,25 @@ jobs: deploy-staging: name: 部署测试环境 runs-on: linux + container: + image: alpine:latest if: github.ref == 'refs/heads/develop' steps: + - name: 安装依赖 + run: apk add --no-cache openssh-client bash + + - name: 设置 SSH 密钥 + run: | + mkdir -p ~/.ssh + echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed255 + echo "Host micecola.top" >> ~/.ssh/config + echo " StrictHostKeyChecking no" >> ~/.ssh/config + - name: 部署到测试服务器 run: | echo "开始部署到测试环境..." - ssh -o StrictHostKeyChecking=no root@micecola.top << 'EOF' + ssh root@micecola.top << 'EOF' cd /var/www/kb-web-test # 备份 @@ -53,12 +66,25 @@ jobs: deploy-production: name: 部署正式环境 runs-on: linux + container: + image: alpine:latest if: github.ref == 'refs/heads/main' steps: + - name: 安装依赖 + run: apk add --no-cache openssh-client bash + + - name: 设置 SSH 密钥 + run: | + mkdir -p ~/.ssh + echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed255 + echo "Host micecola.top" >> ~/.ssh/config + echo " StrictHostKeyChecking no" >> ~/.ssh/config + - name: 备份并部署 run: | echo "开始部署到正式环境..." - ssh -o StrictHostKeyChecking=no root@micecola.top << 'EOF' + ssh root@micecola.top << 'EOF' # 备份 BACKUP_DIR="/var/www/kb-web-prod-backups" mkdir -p $BACKUP_DIR diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index ba50724..c87dfff 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -11,21 +11,23 @@ jobs: quick-test: name: 快速测试 runs-on: linux + container: + image: composer:latest steps: - name: 检出代码 run: | + apk add --no-cache git git clone -b ${{ github.ref_name }} ${{ github.server_url }}/${{ github.repository }}.git . git checkout ${{ github.sha }} - name: 检查环境 run: | echo "PHP: $(php -v | head -1)" - echo "Composer: $(composer --version 2>/dev/null || echo 'not found')" + echo "Composer: $(composer --version)" - name: PHP 语法检查 run: | echo "📝 PHP 语法检查..." - echo "PHP 版本: $(php -v | head -1)" errors=0 for file in $(find . -name "*.php" -not -path "./vendor/*"); do output=$(php -l "$file" 2>&1) @@ -43,10 +45,7 @@ jobs: fi - name: 安装依赖 - run: | - if [ -f composer.json ]; then - composer install --prefer-dist --no-progress --no-interaction - fi + run: composer install --prefer-dist --no-progress --no-interaction - name: 运行测试 run: |