From 5d549c89874be658456f749028fe9526e765ee3b Mon Sep 17 00:00:00 2001 From: Michel Boudreau Date: Fri, 30 Jul 2021 09:28:47 +1000 Subject: [PATCH 1/6] Adding ability to push to external repo Remote input, defaults to origin --- entrypoint.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/entrypoint.py b/entrypoint.py index 2a62019..0348c24 100755 --- a/entrypoint.py +++ b/entrypoint.py @@ -19,6 +19,7 @@ def run(): files = local.env.get('INPUT_FILES', '') email = local.env.get('INPUT_EMAIL', f'{github_actor}@users.noreply.github.com') name = local.env.get('INPUT_NAME', github_actor) + remote = local.env.get('INPUT_REMOTE', 'origin') with open(netrc_path, 'w') as f: f.write( f'machine github.com\n' @@ -44,8 +45,8 @@ def run(): debug(f"Files: {files}") add_args.extend(files.strip("'").split()) if rebase == 'true': - debug(git(['pull', '--rebase', '--autostash', 'origin', branch])) - push_args = ['push', '--follow-tags', '--set-upstream', 'origin', branch] + debug(git(['pull', '--rebase', '--autostash', remote, branch])) + push_args = ['push', '--follow-tags', '--set-upstream', remote, branch] if force_push == 'true': push_args.append('--force') debug(git(['checkout', '-B', branch])) From 138a1348cb07113754291b73a965441185b82ae1 Mon Sep 17 00:00:00 2001 From: Michel Boudreau Date: Fri, 30 Jul 2021 09:32:47 +1000 Subject: [PATCH 2/6] Update action.yml Adding `push-remote` input --- action.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/action.yml b/action.yml index 245fc68..8e2cbe4 100644 --- a/action.yml +++ b/action.yml @@ -11,6 +11,9 @@ inputs: push-branch: description: 'Override branch to push to' required: false + push-remote: + description: 'Override remote to push to' + required: false commit-message: description: 'Specify commit message' required: false From 3b0d2a815d910739940123c0ceb84f106fe24fca Mon Sep 17 00:00:00 2001 From: Michel Boudreau Date: Fri, 30 Jul 2021 09:33:57 +1000 Subject: [PATCH 3/6] Update entrypoint.py Updating remote to push-remote --- entrypoint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.py b/entrypoint.py index 0348c24..9edf594 100755 --- a/entrypoint.py +++ b/entrypoint.py @@ -15,11 +15,11 @@ def run(): force_add = local.env.get('INPUT_FORCE-ADD') force_push = local.env.get('INPUT_FORCE-PUSH') branch = local.env.get('INPUT_PUSH-BRANCH') or "/".join(local.env.get('GITHUB_REF').split('/')[2:]) + remote = local.env.get('INPUT_PUSH-REMOTE', 'origin') rebase = local.env.get('INPUT_REBASE', 'false') files = local.env.get('INPUT_FILES', '') email = local.env.get('INPUT_EMAIL', f'{github_actor}@users.noreply.github.com') name = local.env.get('INPUT_NAME', github_actor) - remote = local.env.get('INPUT_REMOTE', 'origin') with open(netrc_path, 'w') as f: f.write( f'machine github.com\n' From c28f20b6ee788c71d42393231ebf9efa852f1897 Mon Sep 17 00:00:00 2001 From: Michel Boudreau Date: Fri, 30 Jul 2021 10:08:27 +1000 Subject: [PATCH 4/6] Update README.md Adding push-remote config and better explanation of options --- README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c074a10..8b2a9a1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,21 @@ -## commit +## Github Commit & Push Action Git commit and push +### Options + +github-token: *Required.* Github Token with commit access. If pushing to the same repo the action is running on, please use `${{ secrets.GITHUB_TOKEN }}`. If for another repo, create a personal private token, add it to secrets then use it here. +push-branch: Override branch to push to, defaults to the same branch the action is currently running on. +push-remote: Override remote to push to, defaults to the same repo the action is currently running on. Must be in GIT URL format, example below. +commit-message: Specify commit message, defaults to `autocommit`. +force-add: Force add files, useful for adding ignored files. Defaults to `false`. +force-push: Force git push, defaults to `false`. +rebase: Pull and rebase before commiting. Useful when using commit inside matrix. Defaults to `false` +files: Specific files to add. Uses the same format as `git add`. Defaults to all files. +email: Committer email. Default is `${name}@users.noreply.github.com` +name: Committer name. Default is name of the person or app that initiated the workflow. + + ### Example ```yaml @@ -27,6 +41,7 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} push-branch: 'master' + push-remote: https://github.com/some-org/some-repo.git commit-message: 'publish' force-add: 'true' files: a.txt b.txt c.txt dirA/ dirB/ dirC/a.txt @@ -68,5 +83,6 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} push-branch: master commit-message: '${{ matrix.node-version }} adds auto-generated benchmarks and bar graph' + files: a.text build/ rebase: 'true' # pull and rebase before commit ``` From a5a8272f8656cf1a8c94f38bad7e0f7e30047c58 Mon Sep 17 00:00:00 2001 From: Michel Boudreau Date: Fri, 30 Jul 2021 10:58:00 +1000 Subject: [PATCH 5/6] Update entrypoint.py Changing how remote is set --- entrypoint.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/entrypoint.py b/entrypoint.py index 9edf594..fab45da 100755 --- a/entrypoint.py +++ b/entrypoint.py @@ -15,7 +15,7 @@ def run(): force_add = local.env.get('INPUT_FORCE-ADD') force_push = local.env.get('INPUT_FORCE-PUSH') branch = local.env.get('INPUT_PUSH-BRANCH') or "/".join(local.env.get('GITHUB_REF').split('/')[2:]) - remote = local.env.get('INPUT_PUSH-REMOTE', 'origin') + remote = local.env.get('INPUT_PUSH-REMOTE') rebase = local.env.get('INPUT_REBASE', 'false') files = local.env.get('INPUT_FILES', '') email = local.env.get('INPUT_EMAIL', f'{github_actor}@users.noreply.github.com') @@ -37,6 +37,8 @@ def run(): debug(f'username:{github_actor}, branch:{branch}, commit message:{commit_message}') with open(netrc_path) as f: debug(f.read()) + if remote: + debug(git(['remote', 'set-url', 'origin', remote])) add_args = ['add'] if force_add == 'true': add_args.append('-f') @@ -45,8 +47,8 @@ def run(): debug(f"Files: {files}") add_args.extend(files.strip("'").split()) if rebase == 'true': - debug(git(['pull', '--rebase', '--autostash', remote, branch])) - push_args = ['push', '--follow-tags', '--set-upstream', remote, branch] + debug(git(['pull', '--rebase', '--autostash', 'origin', branch])) + push_args = ['push', '--follow-tags', '--set-upstream', 'origin', branch] if force_push == 'true': push_args.append('--force') debug(git(['checkout', '-B', branch])) From 170c8e3f5a61e112db0ec20bf251b0a653daabec Mon Sep 17 00:00:00 2001 From: Michel Boudreau Date: Fri, 30 Jul 2021 11:17:23 +1000 Subject: [PATCH 6/6] Update README.md --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8b2a9a1..46d21cd 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,16 @@ Git commit and push ### Options -github-token: *Required.* Github Token with commit access. If pushing to the same repo the action is running on, please use `${{ secrets.GITHUB_TOKEN }}`. If for another repo, create a personal private token, add it to secrets then use it here. -push-branch: Override branch to push to, defaults to the same branch the action is currently running on. -push-remote: Override remote to push to, defaults to the same repo the action is currently running on. Must be in GIT URL format, example below. -commit-message: Specify commit message, defaults to `autocommit`. -force-add: Force add files, useful for adding ignored files. Defaults to `false`. -force-push: Force git push, defaults to `false`. -rebase: Pull and rebase before commiting. Useful when using commit inside matrix. Defaults to `false` -files: Specific files to add. Uses the same format as `git add`. Defaults to all files. -email: Committer email. Default is `${name}@users.noreply.github.com` -name: Committer name. Default is name of the person or app that initiated the workflow. +* **github-token**: *Required*. Github Token with commit access. If pushing to the same repo the action is running on, please use `${{ secrets.GITHUB_TOKEN }}`. If for another repo, create a personal private token, add it to secrets then use it here. +* **push-branch**: Override branch to push to, defaults to the same branch the action is currently running on. +* **push-remote**: Override remote to push to, defaults to the same repo the action is currently running on. Must be in GIT URL format, example below. +* **commit-message**: Specify commit message, defaults to `autocommit`. +* **force-add**: Force add files, useful for adding ignored files. Defaults to `false`. +* **force-push**: Force git push, defaults to `false`. +* **rebase**: Pull and rebase before commiting. Useful when using commit inside matrix. Defaults to `false` +* **files**: Specific files to add. Uses the same format as `git add`. Defaults to all files. +* **email**: Committer email. Default is `${name}@users.noreply.github.com` +* **name**: Committer name. Default is name of the person or app that initiated the workflow. ### Example