Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 74 additions & 70 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
@@ -1,71 +1,75 @@
name: Update README release section
on:
release:
types: [published]
permissions:
contents: write
pull-requests: write
jobs:
update-readme:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
name: Update README release section

on:
release:
types: [published]

permissions:
contents: write
pull-requests: write

jobs:
update-readme:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: main

- name: Update README release section
shell: bash
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_NAME: ${{ github.event.release.name }}
RELEASE_URL: ${{ github.event.release.html_url }}
run: |
python <<'PY'
from pathlib import Path
import os
import re

readme = Path("README.md")
text = readme.read_text(encoding="utf-8")

tag = os.environ["RELEASE_TAG"]
name = os.environ["RELEASE_NAME"] or tag
url = os.environ["RELEASE_URL"]

replacement = f"""<!-- BEGIN LATEST_RELEASE -->
Current release: __[{name}]({url})__

Tag: `{tag}`
<!-- END LATEST_RELEASE -->"""

pattern = r"<!-- BEGIN LATEST_RELEASE -->.*?<!-- END LATEST_RELEASE -->"

updated, count = re.subn(
pattern,
replacement,
text,
flags=re.DOTALL,
)

if count == 0:
raise SystemExit("README release markers were not found.")

if updated != text:
readme.write_text(updated, encoding="utf-8")
PY

- name: Create pull request
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8
with:
commit-message: "Update README latest release section"
title: "Update README latest release section"
body: |
Updates the README latest release section after publishing `${{ github.event.release.tag_name }}`.
branch: docs/update-latest-release
base: main
delete-branch: true
with:
ref: main
fetch-depth: 0
clean: true

- name: Update README release section
shell: bash
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_NAME: ${{ github.event.release.name }}
RELEASE_URL: ${{ github.event.release.html_url }}
run: |
python <<'PY'
from pathlib import Path
import os
import re

readme = Path("README.md")
text = readme.read_text(encoding="utf-8")

tag = os.environ["RELEASE_TAG"]
name = os.environ["RELEASE_NAME"] or tag
url = os.environ["RELEASE_URL"]

replacement = f"""<!-- BEGIN LATEST_RELEASE -->
Current release: __[{name}]({url})__

Tag: `{tag}`
<!-- END LATEST_RELEASE -->"""

pattern = r"<!-- BEGIN LATEST_RELEASE -->.*?<!-- END LATEST_RELEASE -->"

updated, count = re.subn(
pattern,
replacement,
text,
flags=re.DOTALL,
)

if count == 0:
raise SystemExit("README release markers were not found.")

if updated != text:
readme.write_text(updated, encoding="utf-8")
PY

- name: Create pull request
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8
with:
commit-message: "Update README latest release section"
title: "Update README latest release section"
body: |
Updates the README latest release section after publishing `${{ github.event.release.tag_name }}`.
branch: docs/update-latest-release
base: main
delete-branch: true
add-paths: |
README.md
Loading