GitHub Actions 上传工件未从 npm run build 中找到提供的路径

Mic*_*ert 8 npm github-actions cicd

我正在尝试使用 CICD 原则建立一个 React 网站。我可以在本地运行它,使用“npm run build”获取构建文件夹,并且当我手动将文件推送到 S3 时,网站运行良好。但是,当我尝试通过 github 操作运行构建和部署时,upload-artifacts 步骤会给出以下警告:“警告:在提供的路径中找不到文件:构建”。不会上传任何工件。” 显然,部署作业会失败,因为它找不到任何要下载的工件。究竟为什么会发生这种情况?自从在构建后运行 ls 将其列为当前工作目录中的文件夹之一以来,肯定会创建构建文件夹。

name: frontend_actions
on:
  workflow_dispatch:
  push:
    paths:
      - 'frontend/'
      - '.github/workflows/frontend_actions.yml'
    branches:
      - master
defaults:
  run:
    working-directory: frontend
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v2
    - name: npm install
      run: npm install
    - name: npm build
      run: npm run build
      env:
        CI: false
    - name: Upload Artifact
      uses: actions/upload-artifact@master
      with:
        name: build
        path: build
  deploy:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Download Artifact
        uses: actions/download-artifact@master
        with:
          name: build
          path: build
      - name: Deploy to S3
        uses: jakejarvis/s3-sync-action@master
        with:
          args: --acl public-read --follow-symlinks --delete
        env:
          AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          AWS_REGION: 'us-west-2'   # optional: defaults to us-east-1
          SOURCE_DIR: 'build'   # optional: defaults to entire repository
Run Code Online (Sandbox Code Playgroud)

Mic*_*ert 19

事实证明我对github actions的了解并不完整。为作业设置默认工作目录时,默认目录仅由使用“run”的命令使用。因此,所有“使用”操作都在基目录中运行。我想我从未遇到过这个问题,因为我从未尝试过上传/下载不是在基本 github 目录中创建的工件。

通过将路径从“build/”更改为“frontend/build”解决了该问题。