name: Update README version references

on:
  release:
    types: [published]

jobs:
  update-readme:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4
        with:
          ref: master

      - name: Update version references in README
        run: |
          TAG="${{ github.event.release.tag_name }}"
          sed -i "s/rev: v[0-9]\+\.[0-9]\+\.[0-9]\+/rev: ${TAG}/" README.md
          sed -i "s|sbryngelson/ffmt@v[0-9]\+\.[0-9]\+\.[0-9]\+|sbryngelson/ffmt@${TAG}|" README.md

      - name: Commit and push
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add README.md
          git diff --cached --quiet || git commit -m "Update README version to ${{ github.event.release.tag_name }}"
          git push
