Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
package

GitHub Action

Create PR Action

v1.1.5

Create PR Action

package

Create PR Action

Run command and create Pull Request

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Create PR Action

uses: technote-space/create-pr-action@v1.1.5

Learn more about this action in technote-space/create-pr-action

Choose a version

Create PR Action

CI Status codecov CodeFactor License: MIT

Read this in other languages: English, 日本語.

This is a GitHub Actions that executes an arbitrary command and commits the changes to the new pull request.
It also has a management function that resolves conflicts and closes pull requests that are no longer needed.

Table of Contents

Details

Screenshots

Run commands

run command

Created Pull Request

pull request

Installation

e.g. Update npm packages

e.g. .github/workflows/update-npm-packages.yml

on:
 schedule:
   - cron: 0 0 * * *
 pull_request:
   types: [opened, synchronize, reopened, closed]

name: Update packages
jobs:
 release:
   name: Update npm packages
   runs-on: ubuntu-latest
   steps:
     - name: Update npm packages
       uses: technote-space/create-pr-action@v1
       with:
         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
         EXECUTE_COMMANDS: |
           npx npm-check-updates -u --packageFile package.json
           yarn install
           yarn upgrade
           yarn audit
         COMMIT_MESSAGE: 'chore: update npm dependencies'
         COMMIT_NAME: 'GitHub Actions'
         COMMIT_EMAIL: 'example@example.com'
         PR_BRANCH_NAME: 'chore-npm-update-${PR_ID}'
         PR_TITLE: 'chore: update npm dependencies'

e.g. Update composer packages

e.g. .github/workflows/update-composer-packages.yml

on:
 schedule:
   - cron: 0 0 * * *
 pull_request:
   types: [opened, synchronize, reopened, closed]

name: Update packages
jobs:
 release:
   name: Update composer packages
   runs-on: ubuntu-latest
   steps:
     - name: Update composer packages
       uses: technote-space/create-pr-action@v1
       with:
         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
         EXECUTE_COMMANDS: |
           rm -f "composer.lock"
           < "composer.json" jq -r '.require | to_entries[] | select(.value | startswith("^")) | select(.key | contains("/")) | .key' | tr '\n' ' ' | xargs -r php -d memory_limit=2G "$(command -v composer)" require --no-interaction --prefer-dist --no-suggest
           < "composer.json" jq -r '."require-dev" | to_entries[] | select(.value | startswith("^")) | select(.key | contains("/")) | .key' | tr '\n' ' ' | xargs -r php -d memory_limit=2G "$(command -v composer)" require --dev --no-interaction --prefer-dist --no-suggest
         COMMIT_MESSAGE: 'chore: update composer dependencies'
         COMMIT_NAME: 'GitHub Actions'
         COMMIT_EMAIL: 'example@example.com'
         PR_BRANCH_NAME: 'chore-composer-update-${PR_ID}'
         PR_TITLE: 'chore: update composer dependencies'

e.g. Mixed

e.g. .github/workflows/update-packages.yml

on:
 schedule:
   - cron: 0 0 * * *
 pull_request:
   types: [opened, synchronize, reopened, closed]

name: Update packages
jobs:
 release:
   name: Update packages
   runs-on: ubuntu-latest
   steps:
     - name: Update packages
       uses: technote-space/create-pr-action@v1
       with:
         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
         EXECUTE_COMMANDS: |
           npx npm-check-updates -u --packageFile package.json
           yarn install
           yarn upgrade
           yarn audit
           rm -f "composer.lock"
           < "composer.json" jq -r '.require | to_entries[] | select(.value | startswith("^")) | select(.key | contains("/")) | .key' | tr '\n' ' ' | xargs -r php -d memory_limit=2G "$(command -v composer)" require --no-interaction --prefer-dist --no-suggest
           < "composer.json" jq -r '."require-dev" | to_entries[] | select(.value | startswith("^")) | select(.key | contains("/")) | .key' | tr '\n' ' ' | xargs -r php -d memory_limit=2G "$(command -v composer)" require --dev --no-interaction --prefer-dist --no-suggest
         COMMIT_MESSAGE: 'chore: update dependencies'
         COMMIT_NAME: 'GitHub Actions'
         COMMIT_EMAIL: 'example@example.com'
         PR_BRANCH_NAME: 'chore-update-${PR_ID}'
         PR_TITLE: 'chore: update dependencies'

More details of target event

Options

GLOBAL_INSTALL_PACKAGES

Packages to be global installed.
default: ''

EXECUTE_COMMANDS

Commands to be executed.

COMMIT_MESSAGE

Commit message.

COMMIT_NAME

Git commit name.
default: '${github.actor}'
About Github Context

COMMIT_EMAIL

Git commit email.
default: '${github.actor}@users.noreply.github.com'
About Github Context

PR_BRANCH_PREFIX

PullRequest branch prefix.
default: 'create-pr-action/'

PR_BRANCH_NAME

PullRequest branch name.
Several variables are available (variables1)

PR_TITLE

PullRequest title.
Several variables are available (variables1)

PR_BODY

PullRequest body.
Several variables are available (variables2)

CHECK_DEFAULT_BRANCH

Whether to check default branch.
default: 'true'

ONLY_DEFAULT_BRANCH

Whether not to check other than default branch.
default: 'false'

Action event details

Target event

eventName action
pull_request opened, synchronize, reopened, labeled, unlabeled
pull_request closed
schedule *
  • The following activity types must be explicitly specified (detail)
    • labeled, unlabeled, closed

Variables

Variables1

name description
PR_NUMBER pull_request.number (e.g. 11)
PR_NUMBER_REF #${pull_request.number} (e.g. #11)
PR_ID pull_request.id (e.g. 21031067)
PR_HEAD_REF pull_request.head.ref (e.g. change)
PR_BASE_REF pull_request.base.ref (e.g. master)
PR_TITLE pull_request.title (e.g. Update the README with new information.)

Variables2

name description
PR_LINK Link to PR
COMMANDS_OUTPUT Results of command
FILES_SUMMARY e.g. Changed 2 files
FILES Changed file list

Addition

The GITHUB_TOKEN that is provided as a part of GitHub Actions doesn't have authorization to create any successive events.
So it won't spawn actions which triggered by push.
This can be a problem if you have branch protection configured.

If you want to trigger actions, use a personal access token instead.

  1. Generate a personal access token with the public_repo or repo scope.
    (repo is required for private repositories).
  2. Save as ACCESS_TOKEN
  3. Use ACCESS_TOKEN instead of GITHUB_TOKEN.
    e.g. .github/workflows/update-packages.yml
    on:
      schedule:
        - cron: 0 0 * * *
      pull_request:
        types: [opened, synchronize, reopened, closed]
    
    name: Update packages
    jobs:
      release:
        name: Update npm packages
        runs-on: ubuntu-latest
        steps:
          - name: Update npm packages
            uses: technote-space/create-pr-action@v1
            with:
              # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
              GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
              EXECUTE_COMMANDS: |
                npx npm-check-updates -u --packageFile package.json
                yarn install
                yarn upgrade
                yarn audit
              COMMIT_MESSAGE: 'chore: update npm dependencies'
              COMMIT_NAME: 'GitHub Actions'
              COMMIT_EMAIL: 'example@example.com'
              PR_BRANCH_NAME: 'chore-npm-update-${PR_ID}'
              PR_TITLE: 'chore: update npm dependencies'

Author

GitHub (Technote)
Blog