1

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 }}
      #- 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

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

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

What am I doing wrong?

Federico Arona
  • 125
  • 1
  • 13

1 Answers1

1

For anyone that needs an answer on this.

The problem was related to the fact that I was using two different jobs, one to run the build and one to copy that build to another repo.

This won't work because each job has its own runner and its own file system, meaning that the data aren't shared between jobs.

To avoid this problem I made all on in one job. Another solution is to pass the build between jobs as artifact:

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

Another problem was related to the copy action I was using. For some reason that action didn't find the build directory, probably because its assuming a different working directory. I switched to another action.

Here's the final result:

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
Federico Arona
  • 125
  • 1
  • 13