Search code examples
gitrepositorygithub-actionsgithub-secretgithub-token

`API_TOKEN_GITHUB` not recognized with `copy_file_to_another_repo_action` GitHub workflow


I am using the copy_file_to_another_repo_action GitHub workflow from dmnemec (https://github.com/dmnemec/copy_file_to_another_repo_action) to push a file from one repo that I own to another repo that I own (here is my workflow).

The workflow succeeds until it tries to push the commit, at which points it fails with message "Invalid username or password":

Pushing git commit
+ git push -u origin HEAD:master
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/rempsyc/starter-academic.git/'

Yet, I have created a GitHub secret called API_TOKEN_GITHUB (like in the workflow file) in the source repo that pushes the file:

enter image description here

The token has the following permissions:

enter image description here

I've tried both a fine-grained token and classic token with appropriate permissions, with the same result. Those are the permissions for the fined-grained token (only for the destination repo, where the file needs to be uploaded):

enter image description here

Because the workflow uses the API_TOKEN_GITHUB with env: instead of with:, I tried using an environment secret instead, with the same result:

enter image description here

Is there something obvious I am missing?

This is the same question as: Github action to push build folder to a different repo. However, it has no accepted answer (and the current answer also hasn't worked for me). There is also How to commit and push to a private repo(A), from a different repo(B), in github actions workflow (B) , using personal access token but I am following the same steps and still facing this issue.

Edit:

I tested my token as per the troubleshooting steps listed here (https://cpina.github.io/push-to-another-repository-docs/troubleshooting.html) and the token works as expected: I was able to create a branch and push to it.

Note that I forgot to mention that I've changed the destination branch to master from the original workflow (destination_branch: 'master') since the default was main.


Solution

  • 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.