GithHub CI with React: Push to another repo

I’ve set a GitHub action that make a build of my React application.

I need that build to be pushed to another repo that I’m using to keep track of the builds. This is the action that is actually running:

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

  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: origin-folder/build
          dst_path: /.
          dst_owner: federico-arona
          dst_repo_name: test-build
          dst_branch: main

By the way when the action run the copy job it fails with the following message:

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

What am I doing wrong?

Note that when the react-build scripts start, this is the directory it is running from:

origin-repo@0.1.0 build /home/runner/work/origin-folder/origin-folder

It looks like you’re trying to copy files created by the build job in the copy job. That won’t work, each job gets a fresh runner with an empty file system.

Depending on what fits your needs better, you could either:

1 Like

Thanks airtower-luna for your answer.

I’ve updated the action to this:

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

      

Note the added “ls” command that is giving this output:

Run ls

README.md
build
node_modules
package-lock.json
package.json
public
src

By the way the copy command still fails. Any idea?

Not really, except that ls showing that the build file or directory exists probably means the problem is with the andstor/copycat-action action. I can’t say if there’s an issue with your config or the action itself.

Thanks airtower, usign another copy action solved the issue:

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 ${{ matrix.node-version }}
        with:
          node-version: ${{ matrix.node-version }}
      #- name: Install dependencies
      - run: rm -rf node_modules/
      - run: rm -rf build
      - run: npm ci
      - run: npm run build
        env:
          CI: false
      - run: ls
      - name: Copy to another repo
        uses: dmnemec/copy_file_to_another_repo_action@main
        env:
          API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
        with:
          source_file: "build"
          destination_repo: "federico-arona/test-build"
          destination_folder: "/."
          user_email: "example@email.com"
          user_name: "example"
          commit_message: "A custom message for the commit"

Anyway I’m marking your previous answer as accepted because you clarified that each job has its own runner and an empty file system and since I was using two different jobs the problem was also related to that.

Thanks for your support.

2 Likes