|
| 1 | +name: Release Please |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + release-please: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + outputs: |
| 15 | + release_created: ${{ steps.release.outputs.release_created }} |
| 16 | + tag_name: ${{ steps.release.outputs.tag_name }} |
| 17 | + version: ${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}.${{ steps.release.outputs.patch }} |
| 18 | + steps: |
| 19 | + - uses: googleapis/release-please-action@v4 |
| 20 | + id: release |
| 21 | + with: |
| 22 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 23 | + config-file: release-please-config.json |
| 24 | + manifest-file: .release-please-manifest.json |
| 25 | + |
| 26 | + update-readme: |
| 27 | + needs: release-please |
| 28 | + if: needs.release-please.outputs.release_created == 'true' |
| 29 | + runs-on: ubuntu-latest |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + ref: main |
| 34 | + fetch-depth: 0 |
| 35 | + |
| 36 | + - name: Update README What's New from CHANGELOG |
| 37 | + env: |
| 38 | + VERSION: ${{ needs.release-please.outputs.version }} |
| 39 | + run: | |
| 40 | + python3 << 'PYEOF' |
| 41 | + import os, re |
| 42 | +
|
| 43 | + version = os.environ["VERSION"] |
| 44 | +
|
| 45 | + with open("CHANGELOG.md") as f: |
| 46 | + changelog = f.read() |
| 47 | +
|
| 48 | + match = re.search(r'(## \[' + re.escape(version) + r'\].*?\n)(.*?)(?=\n## \[|\Z)', changelog, re.DOTALL) |
| 49 | + if not match: |
| 50 | + print(f"No changelog entry found for {version}, skipping") |
| 51 | + exit(0) |
| 52 | +
|
| 53 | + body = match.group(2).strip() |
| 54 | +
|
| 55 | + with open("README.md") as f: |
| 56 | + readme = f.read() |
| 57 | +
|
| 58 | + whats_new_match = re.search(r'## What\'s New\n', readme) |
| 59 | + if not whats_new_match: |
| 60 | + print("No What's New section found in README, skipping") |
| 61 | + exit(0) |
| 62 | +
|
| 63 | + start = whats_new_match.start() |
| 64 | + next_heading = re.search(r'\n## (?!What\'s New)', readme[start + 1:]) |
| 65 | + end = start + 1 + next_heading.start() if next_heading else len(readme) |
| 66 | +
|
| 67 | + new_section = f"## What's New\n\n### v{version}\n\n{body}\n\nSee [CHANGELOG.md](CHANGELOG.md) for the full release history.\n\n" |
| 68 | + new_readme = readme[:start] + new_section + readme[end:] |
| 69 | +
|
| 70 | + with open("README.md", "w") as f: |
| 71 | + f.write(new_readme) |
| 72 | +
|
| 73 | + print(f"Updated README What's New to v{version}") |
| 74 | + PYEOF |
| 75 | +
|
| 76 | + - name: Commit and push README changes |
| 77 | + run: | |
| 78 | + git config user.name "github-actions[bot]" |
| 79 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 80 | + git add README.md |
| 81 | + git diff --staged --quiet && echo "No changes to commit" && exit 0 |
| 82 | + git commit -m "docs: update README What's New for ${{ needs.release-please.outputs.tag_name }} [skip ci]" |
| 83 | + git push |
0 commit comments