/force-push-branch-action

Force push to an orphan branch from GitHub Actions

Primary LanguageShellMIT LicenseMIT

Force push branch action

This GitHub action simplifies the process of force pushing an orphan branch to your GitHub repository. You might want to use this to, for example, track an up-to-date set of files generated by your action, but making them more easily accessible than if you used artifacts. For example, I generally use this for providing access to compiled PDFs for scientific papers that I'm working on.

A warning

As it says on the box, this action will force push to your repository, overwriting the history of the target branch. This is always dangerous and you should only use this at your own risk!

Inputs

github-token

Required A token for access to GitHub. The best thing to use here is ${{secrets.GITHUB_TOKEN}} because this action doesn't need any other access and then you won't risk start a terrible never ending loop. You can use a personal access token if you must (but don't).

path

Required A file, directory or wildcard pattern that describes what to upload.

target-branch

Be careful with this parameter. The entire history of this branch will be overwritten! The name of the branch that you want to push to. Either this or branch-suffix must be provided.

branch-suffix

A suffix to add to the current branch name if target-branch is not provided. Either this or target-branch must be provided.

commit-message

The text for a custom commit message. Default: "Automatic commit on GitHub Actions"

Example usage

The following is a basic example of how you can use this action in your workflow:

on: [push]
jobs:
  tests:
    runs-on: ubuntu-latest
    name: Tests
    steps:
      - uses: actions/checkout@v2
      - uses: dfm/force-push-branch-action@v1
        with:
          branch-suffix: "-auto"
          commit-message: "Committing automatically from GitHub Actions"
          path: |
            path/to/a/generated/file
            directories/work/too
            as/to/wildcards/*