name: CI on: push: branches: - main pull_request: jobs: build: runs-on: ubuntu-latest-2 steps: - name: 检出代码 uses: ./.actions/checkout # Node.js 缓存 - name: 缓存 node_modules uses: actions/cache@v3 with: path: platform/node_modules key: node-modules-${{ hashFiles('platform/package-lock.json') }} restore-keys: | node-modules- # Python 缓存 - name: 缓存 pip uses: actions/cache@v3 with: path: ~/.cache/pip key: pip-cache-${{ hashFiles('back/requirements.txt') }} restore-keys: | pip-cache- - name: 安装 Node.js run: | curl -fsSL https://deb.nodesource.com/setup_21.x | bash - apt-get install -y nodejs - name: 安装前端依赖 working-directory: platform run: npm install - name: 构建前端 working-directory: platform run: npm run build - name: 安装 Python run: | apt-get update apt-get install -y python3 python3-pip - name: 安装后端依赖 working-directory: back run: pip3 install -r requirements.txt - name: 运行后端测试(如有) working-directory: back run: | if [ -f tests/test.py ]; then python3 -m unittest discover -s tests; fi - name: 构建 Docker 镜像 run: docker-compose build