diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 92c7c30..9ee88bc 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -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""" - Current release: __[{name}]({url})__ - - Tag: `{tag}` - """ - - pattern = r".*?" - - 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""" + Current release: __[{name}]({url})__ + + Tag: `{tag}` + """ + + pattern = r".*?" + + 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