【问题标题】:GitHub CI: Push React build to another repoGitHub CI:将 React 构建推送到另一个仓库
【发布时间】:2021-06-19 14:46:35
【问题描述】:

我设置了一个 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

我做错了什么?

【问题讨论】:

    标签: react-native github github-actions github-ci


    【解决方案1】:

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

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

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

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

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-12
      • 1970-01-01
      • 2011-07-26
      • 1970-01-01
      • 2016-06-26
      • 1970-01-01
      • 2018-09-13
      • 2021-08-22
      相关资源
      最近更新 更多