0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GitHub Actionsを使用してPRの作成を自動化したお話

0
Last updated at Posted at 2026-03-13

経緯

CI/CDを何か実装してみたくなったので、GitHub Actionsを使用してPR作成を自動化してみようと思い、実装した内容を共有します。

目的

  • PRの作成を自動化することで、手動でPRを作成する手間を省く

実装内容

  1. .github/workflows/auto-pr.ymlの作成
    GitHub Actionsを実行するための実行ファイルです。
    developブランチにpushすると、mainブランチへのPRが作成されるようになっています。
    ファイルの中身は以下です。
name: Auto PR on Push

on:
  push:
    branches:
      - develop

jobs:
  create-pull-request:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
    
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      
      - name: Get commit message
        id: commit
        run: echo "msg=$(git log -1 --pretty=%s)" >> $GITHUB_OUTPUT

      - name: Create Pull Request
        run: |
          gh pr create \
            --base main \
            --head ${{ github.ref_name }} \
            --title "${{ steps.commit.outputs.msg }}" \
            --body-file .github/pull_request_template.md \
            --label "automated-pr" || echo "PR already exists."
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

--body-fileで、PRの本文内容は、.github/pull_request_template.mdを使用するようにしています。

  1. .github/pull_request_template.mdの作成
    PRの本文内容を記載するファイルです。

terraformでawsリソースを管理するリポジトリなので、terraformに合わせたレビューチェックリストになっています。

ファイルの中身は以下です。

## 🤖 Auto Pull Request

This pull request was automatically created by GitHub Actions.

---

### Source Branch
<!-- branch name -->

### Target Branch
main

### Triggered By
<!-- actor -->

### Latest Commit
<!-- commit message -->

---

### Review Checklist
- [ ] Code review
- [ ] Terraform plan confirmed
- [ ] No sensitive information included

---

This PR was generated automatically.

以上です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?