npm run build 不适用于 GitHub Action 工作流程,但适用于本地

问题描述 投票:0回答:1

---
name: CI Workflow

on:
  pull_request:

concurrency:
  group: ${{ github.ref }}-ci-workflow

jobs:
  build:
    runs-on: ubuntu-latest
    continue-on-error: false
    timeout-minutes: 10
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: "18"

      - name: Install Dependencies
        run: |
          cd frontend
          npm ci

      - name: Build code
        run: |
          cd frontend
          npm run build

  test:
    runs-on: ubuntu-latest
    continue-on-error: false
    timeout-minutes: 5
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Setup Python
        uses: actions/setup-python@v4
        with:
          python-version: "3.9"

      - name: Install Dependencies
        run: |
          cd backend
          pip install -r requirements.txt

      - name: Test backend code using pytest
        run: |
          cd backend
          pytest tests
...

我正在构建一个 vue 应用程序。

如果我在 github actions 上运行,它将运行很长时间,超过 10 分钟,这比本地运行 npm run build 所需的时间要长得多。我还将我的前端部署到了 vercel,并且 npm run build 在那里工作。

我尝试将 npm i 更改为 npm ci。但还是不行。

npm continuous-integration github-actions workflow
1个回答
0
投票

这是一个带有缓存的配置。我认为即使没有缓存它也会运行得很快。定义缓存是有意义的。

但是如果您使用

npm run build
运行
--verbose
,您将看到什么: 错误:进程已完成,退出代码为 1。

不幸的是我无法帮助你,因为我不了解 vue.js。

name: CI Workflow

on:
  workflow_dispatch:

concurrency:
  group: ${{ github.ref }}-ci-workflow

jobs:
  build:
    runs-on: ubuntu-latest
    continue-on-error: false
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: "18"
          cache: 'npm'
          cache-dependency-path: frontend/package-lock.json
      
      - name: npm cache
        uses: actions/cache@v3
        id: frontend-node
        with:
          path: frontend/node_modules
          key: ${{ runner.os }}-frontend-node-${{ hashFiles('frontend/package-lock.json') }}

      - name: Install packages
        if: steps.frontend-node.outputs.cache-hit != 'true'
        run: |
          cd frontend
          npm ci            
      - name: Build code
        run: |
          cd frontend
          npm run build --verbose
© www.soinside.com 2019 - 2024. All rights reserved.