-
Notifications
You must be signed in to change notification settings - Fork 0
Implement GitHub Actions workflow for auto-listing develop branch merged PRs in release PRs #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
5
commits into
main
Choose a base branch
from
copilot/fix-0ba7da1f-cb40-4a42-800b-861ac74a645b
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1f626e3
Initial plan
Copilot 40231ad
Implement GitHub Actions workflow and PR template for auto-listing me…
Copilot 56c1b5d
Add comprehensive documentation and demo for GitHub Actions workflow
Copilot 63d0379
Convert to composite action and implement all feedback requirements
Copilot 92e309b
Fix workflow structure to properly use composite action
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| name: 'Update Release PR with Merged PRs' | ||
| description: 'Updates release PR description with list of merged PRs from head branch' | ||
| inputs: | ||
| base-branch: | ||
| description: 'Base branch to compare against (e.g., release)' | ||
| required: true | ||
| head-branch: | ||
| description: 'Head branch to get PRs from (e.g., develop)' | ||
| required: true | ||
| exclude-labels: | ||
| description: 'Comma-separated list of labels to exclude (e.g., deploy,test)' | ||
| required: false | ||
| default: '' | ||
| pr-template-file-path: | ||
| description: 'Path to PR template file (e.g., ./.github/release-pr.md)' | ||
| required: false | ||
| default: './.github/pull_request_template.md' | ||
| github-token: | ||
| description: 'GitHub token for API access' | ||
| required: true | ||
|
|
||
| runs: | ||
| using: 'composite' | ||
| steps: | ||
| - name: Get merged PRs from head branch not in base branch | ||
| id: get-merged-prs | ||
| shell: bash | ||
| env: | ||
| GITHUB_TOKEN: ${{ inputs.github-token }} | ||
| run: | | ||
| set -e | ||
| echo "Fetching merged PRs from ${{ inputs.head-branch }} branch not in ${{ inputs.base-branch }}..." | ||
|
|
||
| # Check if head branch exists | ||
| if ! git show-ref --verify --quiet refs/remotes/origin/${{ inputs.head-branch }}; then | ||
| echo "⚠️ ${{ inputs.head-branch }} branch not found. Using main branch as fallback." | ||
| HEAD_BRANCH="main" | ||
| else | ||
| HEAD_BRANCH="${{ inputs.head-branch }}" | ||
| fi | ||
|
|
||
| # Check if base branch exists | ||
| if ! git show-ref --verify --quiet refs/remotes/origin/${{ inputs.base-branch }}; then | ||
| echo "❌ Base branch ${{ inputs.base-branch }} not found." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Using head branch: $HEAD_BRANCH" | ||
| echo "Using base branch: ${{ inputs.base-branch }}" | ||
|
|
||
| # Get commits that are in head branch but not in base branch | ||
| COMMITS_NOT_IN_BASE=$(git log --oneline origin/$HEAD_BRANCH ^origin/${{ inputs.base-branch }} --merges --format="%H" 2>/dev/null || echo "") | ||
|
|
||
| if [ -z "$COMMITS_NOT_IN_BASE" ]; then | ||
| echo "No merge commits found in $HEAD_BRANCH that are not in ${{ inputs.base-branch }}" | ||
| MERGED_PRS="*最近のマージ済みPRはありません*" | ||
| else | ||
| echo "Found merge commits not in base branch:" | ||
| echo "$COMMITS_NOT_IN_BASE" | ||
|
|
||
| # Extract PR numbers from merge commits and get PR details | ||
| MERGED_PRS="" | ||
| for commit in $COMMITS_NOT_IN_BASE; do | ||
| # Get PR number from merge commit message | ||
| PR_NUMBER=$(git show --format="%s" $commit | grep -oE '#[0-9]+' | head -1 | sed 's/#//' || echo "") | ||
|
|
||
| if [ -n "$PR_NUMBER" ]; then | ||
| echo "Processing PR #$PR_NUMBER" | ||
|
|
||
| # Get PR details using GitHub CLI | ||
| PR_DETAILS=$(gh pr view $PR_NUMBER --json number,title,author,labels --jq '{number: .number, title: .title, author: .author.login, labels: [.labels[].name]}' 2>/dev/null || echo "") | ||
|
|
||
| if [ -n "$PR_DETAILS" ]; then | ||
| # Parse PR details | ||
| PR_TITLE=$(echo "$PR_DETAILS" | jq -r '.title') | ||
| PR_AUTHOR=$(echo "$PR_DETAILS" | jq -r '.author') | ||
| PR_LABELS=$(echo "$PR_DETAILS" | jq -r '.labels | join(",")') | ||
|
|
||
| # Check if PR should be excluded based on labels | ||
| SHOULD_EXCLUDE=false | ||
| if [ -n "${{ inputs.exclude-labels }}" ] && [ -n "$PR_LABELS" ]; then | ||
| IFS=',' read -ra EXCLUDE_LABELS <<< "${{ inputs.exclude-labels }}" | ||
| IFS=',' read -ra PR_LABELS_ARRAY <<< "$PR_LABELS" | ||
|
|
||
| for exclude_label in "${EXCLUDE_LABELS[@]}"; do | ||
| for pr_label in "${PR_LABELS_ARRAY[@]}"; do | ||
| if [ "$exclude_label" = "$pr_label" ]; then | ||
| SHOULD_EXCLUDE=true | ||
| echo "Excluding PR #$PR_NUMBER due to label: $exclude_label" | ||
| break 2 | ||
| fi | ||
| done | ||
| done | ||
| fi | ||
|
|
||
| if [ "$SHOULD_EXCLUDE" = false ]; then | ||
| # Format PR line with variables | ||
| PR_LINE="- \$PR_NUMBER #$PR_NUMBER \$PR_TITLE $PR_TITLE \$PR_USER @$PR_AUTHOR" | ||
| if [ -z "$MERGED_PRS" ]; then | ||
| MERGED_PRS="$PR_LINE" | ||
| else | ||
| MERGED_PRS="$MERGED_PRS | ||
| $PR_LINE" | ||
| fi | ||
| fi | ||
| fi | ||
| fi | ||
| done | ||
|
|
||
| if [ -z "$MERGED_PRS" ]; then | ||
| MERGED_PRS="*最近のマージ済みPRはありません*" | ||
| fi | ||
| fi | ||
|
|
||
| # Save the result | ||
| echo "MERGED_PRS<<EOF" >> $GITHUB_OUTPUT | ||
| echo "$MERGED_PRS" >> $GITHUB_OUTPUT | ||
| echo "EOF" >> $GITHUB_OUTPUT | ||
|
|
||
| echo "Found merged PRs:" | ||
| echo "$MERGED_PRS" | ||
|
|
||
| - name: Update PR description | ||
| shell: bash | ||
| env: | ||
| GITHUB_TOKEN: ${{ inputs.github-token }} | ||
| run: | | ||
| set -e | ||
|
|
||
| # Get current PR description | ||
| CURRENT_BODY=$(gh pr view ${{ github.event.number }} --json body --jq '.body') | ||
|
|
||
| # Create the merged PRs section | ||
| MERGED_PRS_SECTION="## ${{ inputs.head-branch }}ブランチからのマージ済みPR一覧 | ||
| ${{ steps.get-merged-prs.outputs.MERGED_PRS }}" | ||
|
|
||
| # Check if the placeholder exists | ||
| if echo "$CURRENT_BODY" | grep -q "<!-- MERGED_PRS_LIST -->"; then | ||
| echo "Updating existing merged PRs section..." | ||
|
|
||
| # Replace the content between the markers | ||
| NEW_BODY=$(echo "$CURRENT_BODY" | sed '/<!-- MERGED_PRS_LIST -->/,/<!-- \/MERGED_PRS_LIST -->/c\ | ||
| <!-- MERGED_PRS_LIST -->\ | ||
| '"$MERGED_PRS_SECTION"'\ | ||
| <!-- /MERGED_PRS_LIST -->') | ||
| else | ||
| echo "Adding merged PRs section to PR description..." | ||
|
|
||
| # Add the section at the beginning of the body | ||
| NEW_BODY="$MERGED_PRS_SECTION | ||
|
|
||
| $CURRENT_BODY" | ||
| fi | ||
|
|
||
| # Update the PR description | ||
| echo "$NEW_BODY" | gh pr edit ${{ github.event.number }} --body-file - | ||
|
|
||
| echo "✅ PR description updated successfully!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Release PR | ||
|
|
||
| ## 概要 | ||
| develop → main → release のリリースPRです。 | ||
|
|
||
| ## developブランチからのマージ済みPR一覧 | ||
| <!-- MERGED_PRS_LIST --> | ||
| *マージ済みPR一覧は自動で更新されます* | ||
| <!-- /MERGED_PRS_LIST --> | ||
|
|
||
| ## チェックリスト | ||
| - [ ] テストが通ることを確認 | ||
| - [ ] ドキュメントの更新が必要な場合は更新済み | ||
| - [ ] リリースノートの準備完了 | ||
|
|
||
| ## その他 | ||
| <!-- 追加の情報があれば記載 --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| name: Update Release PR with Merged PRs | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, edited, synchronize] | ||
| branches: | ||
| - release | ||
| - release-v2 | ||
| pull_request_target: | ||
| types: [opened, edited, synchronize] | ||
| branches: | ||
| - release | ||
| - release-v2 | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| issues: write | ||
|
|
||
| jobs: | ||
| update-release-pr: | ||
| runs-on: ubuntu-latest | ||
| # Only run for PRs from main to release branches | ||
| if: > | ||
| (github.head_ref == 'main' || startsWith(github.head_ref, 'main')) && | ||
| (github.base_ref == 'release' || github.base_ref == 'release-v2') | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Update Release PR with Merged PRs | ||
| uses: ./.github/actions/update-release-pr | ||
| with: | ||
| base-branch: ${{ github.base_ref }} | ||
| head-branch: 'develop' | ||
| exclude-labels: 'deploy,test' | ||
| pr-template-file-path: './.github/pull_request_template.md' | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
release)develop)deploy,testのようなカンマ区切り)./.github/release-pr.md)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converted to composite action with all requested inputs: base-branch, head-branch, exclude-labels, and pr-template-file-path. The action is now located at
.github/actions/update-release-pr/action.ymland can be reused with different configurations. Commit: 63d0379