create-pr-action

GitHub Actions to manage PullRequest

MIT License

Stars
31
Committers
3

Create PR Action

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

これは任意のコマンドを実行して変更をプルリクエストにコミットする GitHub Actions です。 コンフリクトを解決したり不要になったプルリクエストをクローズしたりするマネジメント機能も備えています。

Table of Contents

インストール

例:Update npm packages

例:.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@v2
       with:
         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: '[email protected]'
         PR_BRANCH_NAME: 'chore-npm-update-${PR_ID}'
         PR_TITLE: 'chore: update npm dependencies'

例:Update composer packages

例:.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@v2
       with:
         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: '[email protected]'
         PR_BRANCH_NAME: 'chore-composer-update-${PR_ID}'
         PR_TITLE: 'chore: update composer dependencies'

例:Mixed

例:.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@v2
       with:
         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: '[email protected]'
         PR_BRANCH_NAME: 'chore-update-${PR_ID}'
         PR_TITLE: 'chore: update dependencies'

More details of target event

スクリーンショット

コマンドの実行

作成されたプルリクエスト

オプション

name description default required e.g.
GLOBAL_INSTALL_PACKAGES グローバルにインストールするパッケージ imagemin-cli
EXECUTE_COMMANDS 実行するコマンド
COMMIT_MESSAGE コミットメッセージ
COMMIT_NAME コミット時に設定する名前 ${github.actor}
COMMIT_EMAIL コミット時に設定するメールアドレス ${github.actor}@users.noreply.github.com
PR_BRANCH_PREFIX ブランチ名のプリフィックス create-pr-action/ true imagemin/
PR_BRANCH_NAME ブランチ名いくつかの変数が使用可能です (variables1) true imagemin-${PR_ID}
PR_TITLE プルリクエストのタイトルいくつかの変数が使用可能です (variables1) true chore: minify images
PR_BODY プルリクエストの本文いくつかの変数が使用可能です (variables2) true
CHECK_DEFAULT_BRANCH デフォルトブランチをチェックするかどうか true false
ONLY_DEFAULT_BRANCH デフォルトブランチ以外をチェックしないかどうか pull_request: false else: true true
GITHUB_TOKEN アクセストークン ${{github.token}} true ${{secrets.ACCESS_TOKEN}}

Action イベント詳細

対象イベント

eventName action
pull_request opened, synchronize, reopened, labeled, unlabeled
pull_request closed
schedule, repository_dispatch, workflow_dispatch *
  • 次のアクティビティタイプは明示的に指定する必要があります (detail)
    • labeled, unlabeled, closed

変数

Variables1

name description
PR_NUMBER pull_request.number (例:11)
PR_NUMBER_REF #${pull_request.number} (例:#11)
PR_ID pull_request.id (例:21031067)
PR_HEAD_REF pull_request.head.ref (例:change)
PR_BASE_REF pull_request.base.ref (例:main)
PR_TITLE pull_request.title (例:Update the README with new information.)
PATCH_VERSION new patch version (e.g. v1.2.4)
MINOR_VERSION new minor version (e.g. v1.3.0)
MAJOR_VERSION new major version (e.g. v2.0.0)

Variables2

name description
PR_LINK プルリクエストへのリンク
COMMANDS_OUTPUT コマンドの結果
FILES_SUMMARY 例:Changed 2 files
FILES 変更されたファイル一覧

補足

GITHUB_TOKEN

GitHub Actions で提供されるGITHUB_TOKENは連続するイベントを作成する権限がありません。 したがって、プッシュによってトリガーされるビルドアクションなどは実行されません。 これはブランチプロテクションを設定していると問題になる場合があります。

もしアクションをトリガーしたい場合は代わりにpersonal access tokenを使用してください。

  1. public_repo または repo の権限で Personal access token を生成
    (repo はプライベートリポジトリで必要です)
  2. ACCESS_TOKENとして保存
  3. GITHUB_TOKENの代わりにACCESS_TOKENを使用するように設定
    例:.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@v2
            with:
              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: '[email protected]'
              PR_BRANCH_NAME: 'chore-npm-update-${PR_ID}'
              PR_TITLE: 'chore: update npm dependencies'
    

Author

GitHub (Technote) Blog

Package Rankings
Top 3.98% on Github actions
Badges
Extracted from project README's
CI Status codecov CodeFactor License: MIT