chore: 更新 OpenLiteWaf submodule 指针(副行再缩) #81
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [main, master] | |
| pull_request: | |
| branches: [main, master] | |
| workflow_dispatch: | |
| jobs: | |
| test: | |
| name: Tests (PHP ${{ matrix.php-version }}) | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| php-version: ['8.4', '8.5'] | |
| services: | |
| mariadb: | |
| image: mariadb:11 | |
| env: | |
| MARIADB_DATABASE: logshare | |
| MARIADB_USER: logshare | |
| MARIADB_PASSWORD: logshare | |
| MARIADB_ROOT_PASSWORD: root | |
| ports: [3306:3306] | |
| options: >- | |
| --health-cmd="healthcheck.sh --connect --innodb_initialized" | |
| --health-interval=10s --health-timeout=5s --health-retries=3 | |
| redis: | |
| image: redis:7-alpine | |
| ports: [6379:6379] | |
| options: >- | |
| --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ matrix.php-version }} | |
| extensions: mbstring, json, zlib, pdo_mysql, redis, pcntl, posix, sockets, swoole | |
| coverage: pcov | |
| tools: composer:v2 | |
| - name: Cache Composer | |
| uses: actions/cache@v4 | |
| with: | |
| path: vendor | |
| key: composer-${{ runner.os }}-php${{ matrix.php-version }}-${{ hashFiles('composer.lock') }} | |
| restore-keys: composer-${{ runner.os }}-php${{ matrix.php-version }}- | |
| - name: Install Dependencies | |
| run: composer install --prefer-dist --no-progress --no-interaction | |
| - name: Copy Config | |
| run: cp Config.inc.example.php Config.inc.php | |
| - name: Initialize MariaDB Schema | |
| run: | | |
| php -r ' | |
| $pdo = new PDO("mysql:host=127.0.0.1;dbname=logshare", "logshare", "logshare", [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); | |
| $pdo->exec(file_get_contents("docker/mariadb-init.sql")); | |
| echo "schema initialized\n"; | |
| ' | |
| - name: Run Tests | |
| run: composer test | |
| env: | |
| DB_HOST: 127.0.0.1 | |
| DB_PORT: 3306 | |
| DB_DATABASE: logshare | |
| DB_USERNAME: logshare | |
| DB_PASSWORD: logshare | |
| REDIS_HOST: 127.0.0.1 | |
| REDIS_PORT: 6379 | |
| - name: Generate Coverage | |
| if: matrix.php-version == '8.4' | |
| run: composer test:coverage | |
| env: | |
| DB_HOST: 127.0.0.1 | |
| DB_PORT: 3306 | |
| DB_DATABASE: logshare | |
| DB_USERNAME: logshare | |
| DB_PASSWORD: logshare | |
| REDIS_HOST: 127.0.0.1 | |
| REDIS_PORT: 6379 | |
| - name: Verify Coverage Report | |
| if: matrix.php-version == '8.4' | |
| run: test -s coverage/clover.xml | |
| - name: Upload Coverage | |
| uses: codecov/codecov-action@v4 | |
| if: matrix.php-version == '8.4' | |
| with: | |
| files: ./coverage/clover.xml | |
| fail_ci_if_error: false | |
| static-analysis: | |
| name: Static Analysis | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Validate Composer Configuration | |
| run: composer validate --strict | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.5' | |
| extensions: mbstring, json, zlib | |
| tools: composer:v2 | |
| - name: Cache Composer | |
| uses: actions/cache@v4 | |
| with: | |
| path: vendor | |
| key: composer-${{ runner.os }}-php8.5-${{ hashFiles('composer.lock') }} | |
| restore-keys: composer-${{ runner.os }}-php8.5- | |
| - name: Install Dependencies | |
| run: composer install --prefer-dist --no-progress --no-interaction | |
| - name: Copy Config | |
| run: cp Config.inc.example.php Config.inc.php | |
| - name: Run PHPStan | |
| run: composer stan | |
| architecture: | |
| name: Architecture Tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.5' | |
| extensions: mbstring, json, zlib | |
| tools: composer:v2 | |
| - name: Cache Composer | |
| uses: actions/cache@v4 | |
| with: | |
| path: vendor | |
| key: composer-${{ runner.os }}-php8.5-${{ hashFiles('composer.lock') }} | |
| restore-keys: composer-${{ runner.os }}-php8.5- | |
| - name: Install Dependencies | |
| run: composer install --prefer-dist --no-progress --no-interaction | |
| - name: Copy Config | |
| run: cp Config.inc.example.php Config.inc.php | |
| - name: Run Architecture Tests | |
| run: composer test:architecture | |
| hyperf-boot: | |
| name: Hyperf Boot (Swoole) | |
| runs-on: ubuntu-latest | |
| services: | |
| mariadb: | |
| image: mariadb:11 | |
| env: | |
| MARIADB_DATABASE: logshare | |
| MARIADB_USER: logshare | |
| MARIADB_PASSWORD: logshare | |
| MARIADB_ROOT_PASSWORD: root | |
| ports: [3306:3306] | |
| options: >- | |
| --health-cmd="healthcheck.sh --connect --innodb_initialized" | |
| --health-interval=10s --health-timeout=5s --health-retries=3 | |
| redis: | |
| image: redis:7-alpine | |
| ports: [6379:6379] | |
| options: >- | |
| --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.5' | |
| extensions: mbstring, json, zlib, pdo_mysql, redis, pcntl, posix, sockets, swoole | |
| tools: composer:v2 | |
| - name: Cache Composer | |
| uses: actions/cache@v4 | |
| with: | |
| path: vendor | |
| key: composer-${{ runner.os }}-php8.5-swoole-${{ hashFiles('composer.lock') }} | |
| restore-keys: composer-${{ runner.os }}-php8.5-swoole- | |
| - name: Install Dependencies | |
| run: composer install --prefer-dist --no-progress --no-interaction | |
| - name: Copy Config | |
| run: cp Config.inc.example.php Config.inc.php | |
| - name: Initialize MariaDB Schema | |
| run: | | |
| php -r ' | |
| $pdo = new PDO("mysql:host=127.0.0.1;dbname=logshare", "logshare", "logshare", [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); | |
| $pdo->exec(file_get_contents("docker/mariadb-init.sql")); | |
| echo "schema initialized\n"; | |
| ' | |
| - name: Verify Framework Boots | |
| run: php bin/hyperf.php list | |
| - name: Start Server & Smoke Test | |
| run: | | |
| php bin/hyperf.php start > /tmp/hyperf.log 2>&1 & | |
| sleep 15 | |
| # HTTP + 路由 | |
| curl -sf http://127.0.0.1:9501/v1/limits | grep -q storageTime || { echo '=== hyperf.log ==='; cat /tmp/hyperf.log; exit 1; } | |
| # MariaDB 存储(POST /v1/log 走 MariaDbStorage) | |
| curl -sf http://127.0.0.1:9501/v1/log -H 'Content-Type: application/json' -d '{"content":"[INFO] smoke test"}' | grep -q '"id"' || { echo '=== hyperf.log ==='; cat /tmp/hyperf.log; exit 1; } | |
| # RAG MCP(主 server /rag 路径) | |
| curl -sf http://127.0.0.1:9501/rag -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' | grep -q jsonrpc || { echo '=== hyperf.log ==='; cat /tmp/hyperf.log; exit 1; } | |
| kill $(cat runtime/hyperf.pid) | |
| env: | |
| DB_HOST: 127.0.0.1 | |
| DB_PORT: 3306 | |
| DB_DATABASE: logshare | |
| DB_USERNAME: logshare | |
| DB_PASSWORD: logshare | |
| REDIS_HOST: 127.0.0.1 | |
| REDIS_PORT: 6379 | |
| docker: | |
| name: Docker Build | |
| runs-on: ubuntu-latest | |
| needs: [test, static-analysis, architecture, hyperf-boot] | |
| if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/main') | |
| # compose.yaml 的必填变量(hyperf/redis/mariadb)在 build 插值阶段即校验, | |
| # CI 仅做构建与冒烟测试,使用占位密码即可 | |
| env: | |
| MARIADB_PASSWORD: ci-placeholder | |
| MARIADB_ROOT_PASSWORD: ci-placeholder | |
| REDIS_PASSWORD: ci-placeholder | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| # 冒烟测试经 nginx 挂载 OpenLiteWaf(submodule)的 Lua 文件, | |
| # 必须一并检出,否则挂载源为空目录导致 WAF/统计页全部失效 | |
| submodules: recursive | |
| - name: Build Image | |
| run: docker compose -f docker/compose.yaml build | |
| - name: Prepare Config for Smoke Test | |
| run: | | |
| cp Config.inc.example.php Config.inc.php | |
| cp .env.example .env | |
| - name: Generate Self-Signed Certificate for Smoke Test | |
| # nginx 443 与 healthcheck 需要证书文件;CI 上 docker/certs/ 为空。 | |
| # 域名从 default.conf 的证书路径动态提取,避免仓库域名调整后 | |
| # CI 仍生成旧域名的证书导致 nginx 启动失败 | |
| run: | | |
| DOMAIN=$(sed -n 's#.*live/\([^/]*\)/fullchain.pem.*#\1#p' docker/nginx/default.conf | head -1) | |
| if [ -z "$DOMAIN" ]; then | |
| echo "无法从 docker/nginx/default.conf 提取证书域名"; exit 1 | |
| fi | |
| echo "生成自签证书: $DOMAIN" | |
| mkdir -p "docker/certs/live/$DOMAIN" | |
| openssl req -x509 -newkey rsa:2048 -nodes \ | |
| -keyout "docker/certs/live/$DOMAIN/privkey.pem" \ | |
| -out "docker/certs/live/$DOMAIN/fullchain.pem" \ | |
| -days 1 -subj "/CN=$DOMAIN" | |
| - name: Test Image Starts | |
| run: | | |
| docker compose -f docker/compose.yaml up -d | |
| ready=0 | |
| for i in $(seq 1 30); do | |
| if curl -skf https://localhost/v1/limits > /dev/null; then | |
| ready=1 | |
| break | |
| fi | |
| sleep 3 | |
| done | |
| if [ "$ready" != "1" ]; then | |
| echo "=== hyperf 日志 ===" | |
| docker compose -f docker/compose.yaml logs hyperf nginx | |
| docker compose -f docker/compose.yaml down | |
| exit 1 | |
| fi | |
| # OpenLiteWaf 统计页(经 nginx 的 OpenResty Lua 直接响应) | |
| curl -skf https://localhost/security/stats || { echo '=== nginx 日志 ==='; docker compose -f docker/compose.yaml logs nginx; docker compose -f docker/compose.yaml down; exit 1; } | |
| echo "smoke test 通过" | |
| docker compose -f docker/compose.yaml down |