- test.yml / ci.yml: 使用 composer:latest 镜像 (含 PHP) - deploy.yml: 使用 alpine:latest 镜像 + SSH 密钥配置 - 解决 runner 默认环境缺少 PHP 的问题
This commit is contained in:
@@ -11,16 +11,18 @@ jobs:
|
|||||||
lint:
|
lint:
|
||||||
name: 代码检查
|
name: 代码检查
|
||||||
runs-on: linux
|
runs-on: linux
|
||||||
|
container:
|
||||||
|
image: composer:latest
|
||||||
steps:
|
steps:
|
||||||
- name: 检出代码
|
- name: 检出代码
|
||||||
run: |
|
run: |
|
||||||
|
apk add --no-cache git
|
||||||
git clone -b ${{ github.ref_name }} ${{ github.server_url }}/${{ github.repository }}.git .
|
git clone -b ${{ github.ref_name }} ${{ github.server_url }}/${{ github.repository }}.git .
|
||||||
git checkout ${{ github.sha }}
|
git checkout ${{ github.sha }}
|
||||||
|
|
||||||
- name: PHP 语法检查
|
- name: PHP 语法检查
|
||||||
run: |
|
run: |
|
||||||
echo "📝 PHP 语法检查..."
|
echo "📝 PHP 语法检查..."
|
||||||
echo "PHP 版本: $(php -v | head -1)"
|
|
||||||
errors=0
|
errors=0
|
||||||
for file in $(find . -name "*.php" -not -path "./vendor/*"); do
|
for file in $(find . -name "*.php" -not -path "./vendor/*"); do
|
||||||
output=$(php -l "$file" 2>&1)
|
output=$(php -l "$file" 2>&1)
|
||||||
@@ -44,10 +46,13 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
name: 单元测试
|
name: 单元测试
|
||||||
runs-on: linux
|
runs-on: linux
|
||||||
|
container:
|
||||||
|
image: composer:latest
|
||||||
needs: lint
|
needs: lint
|
||||||
steps:
|
steps:
|
||||||
- name: 检出代码
|
- name: 检出代码
|
||||||
run: |
|
run: |
|
||||||
|
apk add --no-cache git
|
||||||
git clone -b ${{ github.ref_name }} ${{ github.server_url }}/${{ github.repository }}.git .
|
git clone -b ${{ github.ref_name }} ${{ github.server_url }}/${{ github.repository }}.git .
|
||||||
git checkout ${{ github.sha }}
|
git checkout ${{ github.sha }}
|
||||||
|
|
||||||
|
|||||||
@@ -19,12 +19,25 @@ jobs:
|
|||||||
deploy-staging:
|
deploy-staging:
|
||||||
name: 部署测试环境
|
name: 部署测试环境
|
||||||
runs-on: linux
|
runs-on: linux
|
||||||
|
container:
|
||||||
|
image: alpine:latest
|
||||||
if: github.ref == 'refs/heads/develop'
|
if: github.ref == 'refs/heads/develop'
|
||||||
steps:
|
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: 部署到测试服务器
|
- name: 部署到测试服务器
|
||||||
run: |
|
run: |
|
||||||
echo "开始部署到测试环境..."
|
echo "开始部署到测试环境..."
|
||||||
ssh -o StrictHostKeyChecking=no root@micecola.top << 'EOF'
|
ssh root@micecola.top << 'EOF'
|
||||||
cd /var/www/kb-web-test
|
cd /var/www/kb-web-test
|
||||||
|
|
||||||
# 备份
|
# 备份
|
||||||
@@ -53,12 +66,25 @@ jobs:
|
|||||||
deploy-production:
|
deploy-production:
|
||||||
name: 部署正式环境
|
name: 部署正式环境
|
||||||
runs-on: linux
|
runs-on: linux
|
||||||
|
container:
|
||||||
|
image: alpine:latest
|
||||||
if: github.ref == 'refs/heads/main'
|
if: github.ref == 'refs/heads/main'
|
||||||
steps:
|
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: 备份并部署
|
- name: 备份并部署
|
||||||
run: |
|
run: |
|
||||||
echo "开始部署到正式环境..."
|
echo "开始部署到正式环境..."
|
||||||
ssh -o StrictHostKeyChecking=no root@micecola.top << 'EOF'
|
ssh root@micecola.top << 'EOF'
|
||||||
# 备份
|
# 备份
|
||||||
BACKUP_DIR="/var/www/kb-web-prod-backups"
|
BACKUP_DIR="/var/www/kb-web-prod-backups"
|
||||||
mkdir -p $BACKUP_DIR
|
mkdir -p $BACKUP_DIR
|
||||||
|
|||||||
@@ -11,21 +11,23 @@ jobs:
|
|||||||
quick-test:
|
quick-test:
|
||||||
name: 快速测试
|
name: 快速测试
|
||||||
runs-on: linux
|
runs-on: linux
|
||||||
|
container:
|
||||||
|
image: composer:latest
|
||||||
steps:
|
steps:
|
||||||
- name: 检出代码
|
- name: 检出代码
|
||||||
run: |
|
run: |
|
||||||
|
apk add --no-cache git
|
||||||
git clone -b ${{ github.ref_name }} ${{ github.server_url }}/${{ github.repository }}.git .
|
git clone -b ${{ github.ref_name }} ${{ github.server_url }}/${{ github.repository }}.git .
|
||||||
git checkout ${{ github.sha }}
|
git checkout ${{ github.sha }}
|
||||||
|
|
||||||
- name: 检查环境
|
- name: 检查环境
|
||||||
run: |
|
run: |
|
||||||
echo "PHP: $(php -v | head -1)"
|
echo "PHP: $(php -v | head -1)"
|
||||||
echo "Composer: $(composer --version 2>/dev/null || echo 'not found')"
|
echo "Composer: $(composer --version)"
|
||||||
|
|
||||||
- name: PHP 语法检查
|
- name: PHP 语法检查
|
||||||
run: |
|
run: |
|
||||||
echo "📝 PHP 语法检查..."
|
echo "📝 PHP 语法检查..."
|
||||||
echo "PHP 版本: $(php -v | head -1)"
|
|
||||||
errors=0
|
errors=0
|
||||||
for file in $(find . -name "*.php" -not -path "./vendor/*"); do
|
for file in $(find . -name "*.php" -not -path "./vendor/*"); do
|
||||||
output=$(php -l "$file" 2>&1)
|
output=$(php -l "$file" 2>&1)
|
||||||
@@ -43,10 +45,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
- name: 安装依赖
|
- name: 安装依赖
|
||||||
run: |
|
run: composer install --prefer-dist --no-progress --no-interaction
|
||||||
if [ -f composer.json ]; then
|
|
||||||
composer install --prefer-dist --no-progress --no-interaction
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: 运行测试
|
- name: 运行测试
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
Reference in New Issue
Block a user