0

我设置了一个 GitHub 操作来构建我的 React 应用程序。

我需要将该构建推送到另一个我用来跟踪构建的存储库。这是实际运行的操作:

on:
  push:
    branches: [master]

jobs:
  build:
    name: create-package
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [14]

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        name: Use Node.js 14
        with:
          node-version: ${{ matrix.node-version }}
      #- name: Install dependencies
      - run: npm ci

      - run: npm run build --if-present
        env:
          CI: false

  copy:
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Copy to another repo
        uses: andstor/copycat-action@v3
        with:
          personal_token: ${{ secrets.API_TOKEN_GITHUB }}
          src_path: build
          dst_path: /.
          dst_owner: federico-arona
          dst_repo_name: test-build
          dst_branch: main

顺便说一句,当操作运行复制作业时,它会失败并显示以下消息:

cp: can't stat 'origin-repo/build': No such file or directory

我究竟做错了什么?

4

1 回答 1

0

对于任何需要这个答案的人。

问题与我使用两个不同的作业有关,一个用于运行构建,另一个用于将该构建复制到另一个存储库。

这是行不通的,因为每个作业都有自己的运行器和自己的文件系统,这意味着数据不会在作业之间共享。

为了避免这个问题,我在一份工作中全力以赴。另一种解决方案是将作业之间的构建作为工件传递:

https://docs.github.com/en/actions/guides/storing-workflow-data-as-artifacts#passing-data-between-jobs-in-a-workflow

另一个问题与我使用的复制操作有关。由于某种原因,该操作没有找到构建目录,可能是因为它假设了不同的工作目录。我切换到另一个动作。

这是最终结果:

on:
  push:
    branches: [master]

jobs:
  build:
    name: create-package
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [14]

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        name: Use Node.js 14
        with:
          node-version: ${{ matrix.node-version }}
      - run: npm ci

      - run: npm run build --if-present
        env:
          CI: false
      - run: ls
      - name: Copy to another repo
        uses: andstor/copycat-action@v3
        with:
          personal_token: ${{ secrets.API_TOKEN_GITHUB }}
          src_path: build
          dst_path: /.
          dst_owner: federico-arona
          dst_repo_name: test-build
          dst_branch: main
于 2021-03-23T22:17:32.040 回答