diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index a4f211a..ac79366 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -6,36 +6,47 @@ name: unit-test on: [push, pull_request] -# This ensures that previous jobs for the PR are canceled when the PR is updated. +# 取消正在进行的同名任务,避免资源占用 concurrency: - group: ${{ github.workflow }}-${{ github.head_ref }} + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true jobs: jest-run: - runs-on: ubuntu-20.04 - # let's make sure our tests pass on Chrome browser - name: Jest + runs-on: ubuntu-latest # 改用最新版系统,稳定性更好 + name: Jest Unit Test + timeout-minutes: 15 # 关键:设置超时,15分钟未完成则终止 + env: + # 优化Jest运行环境,避免内存溢出 + NODE_OPTIONS: --max_old_space_size=4096 + CI: true # 明确CI环境,Jest会禁用交互模式 + steps: - - name: Check out code into the Go module directory - uses: actions/checkout@v2 + - name: Check out code + uses: actions/checkout@v4 # 升级到最新版action with: fetch-depth: 0 - - name: Setup node env and build - uses: actions/setup-node@v3 + - name: Setup node env + uses: actions/setup-node@v4 # 升级到最新版action with: node-version: ^18.20.8 cache: 'yarn' cache-dependency-path: yarn.lock - - name: Install dependencies + - name: Configure yarn and install dependencies run: | yarn config set strict-ssl false - yarn install --frozen-lockfile + yarn install --frozen-lockfile --network-timeout 1000000 # 增加网络超时,避免安装卡住 - - name: Unit test - run: yarn run test:unit:coverage + - name: Run unit tests with coverage + run: yarn run test:unit:coverage --forceExit --detectOpenHandles + # --forceExit:强制退出Jest,避免测试后进程残留 + # --detectOpenHandles:检测未关闭的句柄,定位卡住原因 - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 # 升级到最新版action + if: success() # 仅当测试成功时才上传 + with: + fail_ci_if_error: false # 上传失败不影响CI结果 + timeout: 300 # Codecov上传超时时间