2

I have 2 repos, repo A with source code and repo B that publishes the build folder to the web.

I have an action for this purpose but im getting an error:

git clone --single-branch --branch main ***github.com/blockcodelabs/B.git /tmp/tmp.NCbLCG<BR>
Cloning into '/tmp/tmp.NCbLCG'...<BR>
remote: Invalid username or password.<BR>
fatal: Authentication failed for 'https://github.com/blockcodelabs/B.git/'<BR>

The action is setup on Repo A, and Repo B has secret.ACCESS_TOKEN:

name: Push File(or Dir) to another repository

on:
  push:
    branches: [master]

jobs:
  copy-file:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Push to another repo
      uses: dmnemec/copy_file_to_another_repo_action@main
      env:
        ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} 
      with:
        source_file: 'build'
        destination_repo: 'blockcodelabs/B'
        destination_folder: 'build'
        user_email: 'email'
        user_name: 'username'
        commit_message: 'Automatic Build To B'

*Update - added picture on error point, for more details. enter image description here

LGarcia
  • 21
  • 3

1 Answers1

1

Check at which point in your GitHub action the error occur:

  • at the actions/checkout@v2 step? (in which case, an access token should be used there)
  • at the dmnemec/copy_file_to_another_repo_action@main step

In both instance, the URL used is an HTTPS one, not an SSH one.

The dmnemec/copy_file_to_another_repo_action entrypoint.sh#L28 shows:

git clone --single-branch --branch $INPUT_DESTINATION_BRANCH \
"https://x-access-token:$API_TOKEN_GITHUB@$INPUT_GIT_SERVER/$INPUT_DESTINATION_REPO.git" "$CLONE_DIR"

That means you need to set API_TOKEN_GITHUB with your secret, in order for the git clone to succeed.

env:
        API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}

That is: API_TOKEN_GITHUB, not ACCESS_TOKEN.


As noted in "API_TOKEN_GITHUB not recognized with copy_file_to_another_repo_action GitHub workflow" by rempsyc:

The issue in my case was that I had created the secret in the destination repo instead of the source repo.
Swapping those two fixed the issue.

So be mindful where you have created the secret.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • its happening on the dmnemec/copy_file_to_another_repo_action@main step. – LGarcia Apr 11 '22 at 12:56
  • added a screenshot for better details. – LGarcia Apr 11 '22 at 13:17
  • @LGarcia OK, thank you for the update. I have updated my answer accordingly. – VonC Apr 11 '22 at 16:35
  • Ive updated the variable but still getting the same error. Its a Personal Access Token is that the correct type? – LGarcia Apr 12 '22 at 10:13
  • 1
    @LGarcia Check first, through an echo, that `secrets.API_TOKEN_GITHUB` has a value (and the expected one, the `ghp_...`. If so, check the [scope of the token](https://docs.github.com/en/developers/apps/building-oauth-apps/scopes-for-oauth-apps). Maybe a wider scope would help. – VonC Apr 12 '22 at 15:41
  • I have the same issue. I've first tried a fine-grained token but it didn't work. Then I tried a classic token and it also didn't work. Have you ever found a solution @LGarcia? – rempsyc Jan 23 '23 at 22:40
  • I have posted my issue here: https://stackoverflow.com/questions/75216087/api-token-github-not-recognized-with-copy-file-to-another-repo-action-github – rempsyc Jan 23 '23 at 23:36
  • @rempsyc I see you have found the root cause, good catch. I have edited the answer to reference your error message and own answer, for more visibility. – VonC Jan 24 '23 at 06:33