GitHub Actions Upload Artifact未从npm运行生成中找到提供的路径



我正在尝试使用CICD原理建立一个react网站。我可以在本地运行它,使用"npm-run-build"来获取构建文件夹,当我手动将文件推送到S3时,网站运行良好。然而,当我尝试通过github操作运行构建和部署时,上传工件步骤会发出以下警告:"警告:未找到具有所提供路径的文件:build。不会上载任何项目。'显然,部署作业会失败,因为它找不到任何可下载的工件。为什么会发生这种情况?生成文件夹肯定是在创建中,因为在生成后运行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

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

通过将路径从"build/"更改为"frontend/build"修复了此问题。

最新更新