A simple GitHub action that, given some file(s), commits any changes and submits a pull request to the target repository, on the specified branch and directory.
A use case for this is to generate some files (eg. TypeScript definitions) during a build in one repo (eg. API service), and commit them to another (eg. web app).
Note: Although this action can be quite useful, it likely will not always be the best approach. I recommend you have a look at the Alternative Options section just in case.
- uses: actions/checkout@v2
- name: Create PR to my-org/target-repo
uses: TickX/[email protected]
with:
token: ${{ secrets.GH_TOKEN }}
item: path/to/file.ext
repo: target-repo
repo_owner: my-org
Here's the full list of inputs:
Input | Description | Default |
---|---|---|
token |
A GitHub access token (see section) | |
item |
The file or directory to commit | |
repo |
The target repository | |
repo_owner |
The target repository owner | |
repo_base_branch |
A new branch will be created from this one before submitting the PR | master |
repo_target_dir |
The chosen item will be committed to this directory | auto-update/${REPO_BASE_BRANCH} |
commit_author |
The author of the commit | "Auto Cross Pull Requester" |
commit_email |
The email associated with the commit | [email protected] |
commit_message |
The commit message | "Auto update" |
pr_title |
The PR title | "Auto Update" |
pr_body |
The PR body content | "This is an automatic update." |
The token
input requires a scoped Personal Access Token; You can use GitHub's GITHUB_TOKEN
environment
variable for that. However, if you do, PRs created by this action will not trigger other on: [push]
and on: [pull_request]
workflows.
For more information about this limitation and its workarounds, see this action's brilliant documentation.
If you just want a solid workaround, use a GitHub App for the sole purpose of creating a token:
- Create an app:
- This can be minimal; Enter any valid URL value for the
Homepage URL
field, eg. your repo's github pages URLmy-org.github.io/my-repo
, and uncheckActive
underWebhook
. - Under
Repository permissions: Contents
selectAccess: Read & write
. - Under
Repository permissions: Pull requests
selectAccess: Read & write
.
- This can be minimal; Enter any valid URL value for the
- Create and download a Private Key from the app's settings page.
- Install the app on the repositories involved in this action.
- In your workflow, obtain a token by using tibdex/github-app-token, which takes your app's ID and private key and generates a temporary auth token.
- Pass the generated token to this action's
token
input.
Depending on your case, you may want to look at alternative options that can achieve similar results, and potentially be better.
Some of these options are:
- Git Submodules (here's a GitHub article about this)
- GitHub
repository_dispatch
event (here's another great action by peter-evans) - GitHub packages