'Github action to push build folder to a different repo

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



Solution 1:[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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1