Merge pull request #59 from devakone/release-please--branches--develop #114
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
| name: Sync Release Pull Request | |
| on: | |
| push: | |
| branches: | |
| - develop | |
| jobs: | |
| sync-release-pr: | |
| name: Create or update develop → main PR | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Open or update release PR | |
| env: | |
| GH_TOKEN: ${{ secrets.RELEASE_PR_TOKEN }} | |
| DEFAULT_GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| PR_TITLE: "Release: develop → main" | |
| GITHUB_REPOSITORY: ${{ github.repository }} | |
| run: | | |
| set -euo pipefail | |
| export GH_TOKEN="${GH_TOKEN:-$DEFAULT_GH_TOKEN}" | |
| git fetch origin main --prune | |
| COMMIT_COUNT="$(git rev-list --count origin/main..HEAD)" | |
| if [ "$COMMIT_COUNT" -eq 0 ]; then | |
| echo "No commits to merge from develop into main. Skipping release PR sync." | |
| exit 0 | |
| fi | |
| BODY_FILE="$(mktemp)" | |
| export BODY_FILE | |
| python3 - <<'PY' | |
| import os | |
| import subprocess | |
| body_file_path = os.environ["BODY_FILE"] | |
| repository = os.environ["GITHUB_REPOSITORY"] | |
| # Get commits that are in develop but not in main | |
| log = subprocess.check_output( | |
| ["git", "log", "--pretty=format:%s (%h)", "origin/main..HEAD", "--no-merges"], | |
| text=True, | |
| ).strip().splitlines() | |
| # Filter out empty lines | |
| log = [line for line in log if line.strip()] | |
| max_items = 60 | |
| items = log[:max_items] | |
| extra = max(len(log) - len(items), 0) | |
| if items: | |
| bullets = [f"- {line}" for line in items] | |
| if extra: | |
| bullets.append(f"- ...and {extra} more commits") | |
| else: | |
| bullets = ["- No new changes since last release"] | |
| summary_lines = [ | |
| "This PR syncs `develop` into `main` for the next production release.", | |
| f"It includes **{len(log)}** commit(s) ahead of `main`.", | |
| ] | |
| compare_url = f"https://github.com/{repository}/compare/main...develop" | |
| final_lines = [ | |
| "## Release Notes", | |
| "", | |
| *summary_lines, | |
| "", | |
| "## Changes", | |
| "", | |
| *bullets, | |
| "", | |
| "## Compare", | |
| "", | |
| f"- Full diff: {compare_url}", | |
| ] | |
| with open(body_file_path, "w", encoding="utf-8") as f: | |
| f.write("\n".join(final_lines).rstrip() + "\n") | |
| # Debug: print the generated body | |
| print("Generated PR body:") | |
| print("-" * 40) | |
| with open(body_file_path, "r") as f: | |
| print(f.read()) | |
| print("-" * 40) | |
| PY | |
| PR_NUMBER="$(gh pr list --base main --head develop --state open --json number --jq '.[0].number // empty')" | |
| if [ -n "$PR_NUMBER" ]; then | |
| echo "Updating existing PR #$PR_NUMBER" | |
| gh pr edit "$PR_NUMBER" \ | |
| --title "$PR_TITLE" \ | |
| --body-file "$BODY_FILE" | |
| else | |
| echo "Creating new release PR" | |
| gh pr create \ | |
| --base main \ | |
| --head develop \ | |
| --title "$PR_TITLE" \ | |
| --body-file "$BODY_FILE" | |
| fi |