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.
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. .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. .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'
Packages to be global installed.
default: ''
Commands to be executed.
Commit message.
Git commit name.
default: '${github.actor}'
About Github Context
Git commit email.
default: '${github.actor}@users.noreply.github.com'
About Github Context
PullRequest branch prefix.
default: 'create-pr-action/'
PullRequest branch name.
Several variables are available (variables1)
PullRequest title.
Several variables are available (variables1)
PullRequest body.
Several variables are available (variables2)
Whether to check default branch.
default: 'true'
Whether not to check other than default branch.
default: 'false'
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
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. ) |
name | description |
---|---|
PR_LINK | Link to PR |
COMMANDS_OUTPUT | Results of command |
FILES_SUMMARY | e.g. Changed 2 files |
FILES | Changed file list |
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.
- Generate a personal access token with the public_repo or repo scope.
(repo is required for private repositories). - Save as ACCESS_TOKEN
- Use
ACCESS_TOKEN
instead ofGITHUB_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'