fix: 使用 container 指定 PHP 镜像
Test CI / 快速测试 (push) Has been cancelled

- test.yml / ci.yml: 使用 composer:latest 镜像 (含 PHP)
- deploy.yml: 使用 alpine:latest 镜像 + SSH 密钥配置
- 解决 runner 默认环境缺少 PHP 的问题
This commit is contained in:
2026-03-01 01:01:06 +08:00
parent 21ddf36151
commit 9427294682
3 changed files with 39 additions and 9 deletions
+6 -1
View File
@@ -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 }}
+28 -2
View File
@@ -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
+5 -6
View File
@@ -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: |