A github action. Generate a file in your action then use this action to push it to a folder in another repository. You have to have permssion to push to that repository.
- Forked from https://github.com/cpina/github-action-push-to-another-repository which, at the time, deleted the files in a target repository, then pushed a generated file into that blank repository.
- Edits were made based on https://github.com/dmnemec/copy_file_to_another_repo_action which, at the time, pushed a copy of an already existing file to a directory in a target repository.
Path to your generated file or to multiple files. Example: 'path/to/file.md'
. I think it doesn't have to be in a folder. Maybe a file that already exists in your current repo would work too, but I haven't tried that yet.
Repository to push file to. Example: 'some_user/some_repo'
Folder to create or use in destination repository. It can be a set of nested folders. Example: '.github/workflows'
[Optional] A branch in the destination repository. Default is "main". I think the branch needs to already exist, but I'm not sure.
[Optional] Name of the commit's author. Default is user name of account doing the pushing.
[Optional] Email for the commit. Default is author@no-reply...
Token/Secret that lets your repo push to a repo on which you have permissions. Example: ${{ secrets.PUSH_FILE_TOKEN }}`
Generate your personal token (github instructions):
- Go to https://github.com/settings/tokens
- Generate a new token
- Choose to allow access to "repo"
- Choose to allow access to "workflow"
- Copy the token
Make the token available to the Github Action:
- Go to the repository you will push from
- Tap the 'Settings' tab
- Tap 'Secrets' in the column on the left
- Tap "Add a new secret"
- Give it a name that will help you remember what it's for, like "PUSH_FILE_TOKEN"
steps:
- uses: actions/checkout@v2
- name: Create output folder and files
run: sh ./generate_files.sh
- name: Push files
uses: plocket/push-generated-file@master
with:
token: ${{ secrets.PUSH_FILE_TOKEN }}
source_file_path: 'output'
destination_repo: 'plocket/some-destination-repository'
destination_folder: 'folder/in/repository'
target_branch: 'feature-branch'
author: 'plocket'
author_email: 'plocket@example.com'
If you want to push different files to two different directories in the same repository, repeat the above in a new run IN THE SAME JOB.
DO NOT try to create separate job
s for each destination folder you want to push to. Jobs happen at the same time as each other and they will try to push on top of the same commit sometimes. That is, one job will make a push and change the destination repo hash then the next job will try to make a push to the old hash and it will fail. run
s happen sequentially and that makes sure each push builds on the last one correctly.
steps:
- uses: actions/checkout@v2
- name: Create 1st output folder and files
run: sh ./generate_files.sh
- name: Push files
uses: plocket/push-generated-file@master
with:
token: ${{ secrets.PUSH_FILE_TOKEN }}
source_file_path: 'first_output_directory'
destination_repo: 'plocket/some-destination-repository'
destination_folder: 'folder/in/repository'
target_branch: 'feature-branch'
author: 'plocket'
author_email: 'plocket@example.com'
- name: Create 2nd output folder and files
run: sh ./generate_other_files.sh
- name: Push the same or different files
uses: plocket/push-generated-file@master
with:
token: ${{ secrets.PUSH_FILE_TOKEN }}
# You need a different output folder so that all the
# previous files don't build up in one folder and get
# pushed to every destination folder
source_file_path: 'second_output_directory'
destination_repo: 'plocket/some-destination-repository'
destination_folder: 'other/destination_folder'
target_branch: 'feature-branch'
author: 'plocket'
author_email: 'plocket@example.com'