From 29856ecaaaad552345f318f20174f17142d6e77e Mon Sep 17 00:00:00 2001 From: niyyzf Date: Fri, 18 Jul 2025 19:30:12 +0800 Subject: [PATCH] Refactor CI workflow to implement caching for Node.js and Python dependencies, and update installation commands for Node.js and Python --- .gitea/workflows/ci.yml | 51 ++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 70e7fa4..05c03fa 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -10,28 +10,31 @@ jobs: build: runs-on: ubuntu-latest-2 steps: - - name: 克隆本地 checkout action - run: | - git clone http://114.67.155.184:3000/niyyzf/checkout.git ./.actions/checkout - - - name: 克隆本地 setup-node action - run: | - git clone http://114.67.155.184:3000/niyyzf/setup-node.git ./.actions/setup-node - - - name: 克隆本地 setup-python action - run: | - git clone http://114.67.155.184:3000/niyyzf/setup-python.git ./.actions/setup-python - - - name: 检查 setup-node 目录 - run: ls -l ./.actions/setup-node - - name: 检出代码 uses: ./.actions/checkout - - name: 设置 Node.js - uses: ./.actions/setup-node + # Node.js 缓存 + - name: 缓存 node_modules + uses: actions/cache@v3 with: - node-version: '18' + 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 @@ -41,19 +44,19 @@ jobs: working-directory: platform run: npm run build - - name: 设置 Python - uses: ./.actions/setup-python - with: - python-version: '3.10' + - name: 安装 Python + run: | + apt-get update + apt-get install -y python3 python3-pip - name: 安装后端依赖 working-directory: back - run: pip install -r requirements.txt + run: pip3 install -r requirements.txt - name: 运行后端测试(如有) working-directory: back run: | - if [ -f tests/test.py ]; then python -m unittest discover -s tests; fi + if [ -f tests/test.py ]; then python3 -m unittest discover -s tests; fi - name: 构建 Docker 镜像 run: docker-compose build \ No newline at end of file