* Using SSH deploy keys (recommended, a bit harder to setup): [push-to-another-repository-deploy-keys-example](https://github.com/cpina/push-to-another-repository-deploy-keys-example). The configuration is in the file [.github/workflows/ci.yml](https://github.com/cpina/push-to-another-repository-deploy-keys-example/blob/main/.github/workflows/ci.yml#L21)
* Using a Personal Access Token (first style, not recommended but easier to setup: [push-to-another-repository-example](https://github.com/cpina/push-to-another-repository-example). The configuration is in the file [.github/workflows/ci.yml](https://github.com/cpina/push-to-another-repository-example/blob/main/.github/workflows/ci.yml#L21)
In those examples the file [build.sh](https://github.com/cpina/push-to-another-repository-deploy-keys-example/blob/main/build.sh) is executes which creates a new directory `output/` and this directory is copied across the [destination repository](https://github.com/cpina/push-to-another-repository-output)
Before using the GitHub Action **it is needed to set up either the Personal Access Token or the SSH Keys as described below.**
:warning: Please bear in mind: files in the target repository's specified directory are deleted unless the option `target-directory` is used (in this case only the files for this directory are deleted).
To output to a repository such as `https://github.com/cpina/push-to-another-repository-output` this variable would be `push-to-another-repository-output`
:warning:: the GitHub Action currently deletes all the files and directories in the destination repository. The idea is to copy from an `output` directory into the `destination-repository-name` having a copy without any previous files there.
The name that will be used for the commit in the destination-repository-name. If not specified, the `destination-github-username` will be used instead.
The Username/Organization for the destination repository, if different from `destination-github-username`. For the repository `https://github.com/cpina/push-to-another-repository-output` is `cpina`.
The action, entirely executed in your GitHub continuous integration environment, needs to be able to push to the destination repository.
There are two options to do this:
* Create an SSH deploy key. This key is restricted to the destination repository only
* Create a GitHub Personal Authentication Token: the token has access to all your repositories
Someone with write access to your repository or this action, could technically add code to leak the key. Thus, *it is recommended to use the SSH deploy key method to minimise repercusions* if this was the case.
This action supports both methods to keep backwards compatibility, because in the beginning it only supported the GitHub Personal Authentication token.
*`ssh-keygen -t ed25519 -C "your_email@example.com"` (the type ed25519 is recommended by [GitHub documentation](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key))
* ssh will ask for a file path: `Enter file in which to save the key`: write a new file name. I suggest the default directory and as a filename: `id_github_name_of_your_repository` to avoid overwriting a previous file. If you will be using this action for multiple repositories, you might want to generate different keys for each one.
* Leave the passphrase empty (otherwise we would need to pass the passphrase to the GitHub Action)
* Go to the GitHub page of the destination repository
* Click on "Settings" (settings for the repository, not the account settings)
* On the left-hand side pane click on "Deploy keys"
* Click on "Add deploy key"
* Title: "GitHub Action push to another repository"
* Key: paste the contents of the file with the public key. This was generated in the "Generate the key files" step and the name is "id_github_name_of_your_repository.pub"
* Enable "Allow write access"barbar
#### Origin repository
* Go to the GitHub page of the origin repository
* On the left-hand side pane click on "Secrets" and then on "Actions"
* Click on "New repository secret"
* Name: "SSH_DEPLOY_KEY"
* Value: paste the contents of the file with the private key. This was generated in the "Generate the key files" step and the name is "id_github_name_of_your_repository"
You don't need to do this if you chose to set up the deploy keys using the steps above. This method is here for compatibility with the initial approach of this GitHub Action. The personal access token would have access to all your repositories, so if it were to be leaked the damage would be greater.