A GitHub Action to create or update a pull request based on local changes
Minimal workflow example
name: Nightly update
on:
schedule:
# https://crontab.guru/every-night-at-midnight
- cron: "0 0 * * *"
jobs:
update_routes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
persist-credentials: false
- run: "date > datetime.txt" # create or update a test.txt file
- uses: gr2m/create-or-update-pull-request-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}Customizations
uses: gr2m/create-or-update-pull-request-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
title: "My pull request title"
body: "My pull request body"
branch: "my-pull-request-base-branch"
path: "lib/"
commit-message: "My commit message for uncommitted changes in lib/ folder"
author: "Lorem J. Ipsum <[email protected]>"
labels: label1, label2
assignees: user1, user2
auto-merge: squashNote: auto-merge is optional. It can be set to merge, squash, or rebase. If auto-merging is disabled in the repository, a warning will be logged, but the action will not fail.
To create multiple commits for different paths, use the action multiple times
- uses: gr2m/create-or-update-pull-request-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
title: "My pull request title"
body: "My pull request body"
branch: "my-pull-request-base-branch"
author: "Lorem J. Ipsum <[email protected]>"
path: "cache/"
commit-message: "build: cache"
- uses: gr2m/create-or-update-pull-request-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
branch: "my-pull-request-base-branch"
author: "Lorem J. Ipsum <[email protected]>"
path: "data/"
commit-message: "feat: data updated"To see additional debug logs, create a secret with the name: ACTIONS_STEP_DEBUG and value true. There is no need to pass it as env to steps, it will work globally.
The actions checks for local changes which can be
- Uncommitted changes such as created, updated or deleted files as shown by
git status - Local commits
If there are none, the action concludes with the "neutral" status
If there are changes, it does the following
- Sets
user.nameanduser.emailwithgit config --globalbased on theauthorinput, unless it has been already set before. - Looks for local changes with
git status. - Adds a new commit using the
commit-messageinput if there are uncommitted changes. - Pushes the local changes to remote using the branch configured in the
branchinput. - Creates a pull request using the
titleandbodyinputs. If a pull request exists for the branch, it's checked out locally, rebased with-XTheirsand pushed with--forceto update the pull request with the new changes.
The action is written in JavaScript. Learn how to create your own.
- @octokit/routes
- @octokit/rest.js
- @sinchang/cn-starbucks-stores-data
ergebnis/composer-normalize- nodejs/node
Please send a pull request to add yours :)
Inspired by the Create Pull Request action by @peter-evans