on:
  push:
    branches:
      - '**'
    paths:
      - '**.ronn'
name: Generate man pages
jobs:
  ronn:
    runs-on: ubuntu-latest
    name: Ronn
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Run ronn
        uses: ./.github/workflows/ronn
        id: ronn
      - name: Undo email mangling
        # rdiscount randomizes the output for no good reason, which causes
        # changes to always get committed. Sigh.
        # https://github.com/davidfstr/rdiscount/blob/6b1471ec3/ext/generate.c#L781-L795
        run: |-
          for f in doc/*.html; do
            awk '/Filippo Valsorda/ { $0 = "<p>Filippo Valsorda <a href=\"mailto:age@filippo.io\" data-bare-link=\"true\">age@filippo.io</a></p>" } { print }' "$f" > "$f.tmp"
            mv "$f.tmp" "$f"
          done
      - name: Commit and push if changed
        run: |-
          git config user.name "GitHub Actions"
          git config user.email "actions@users.noreply.github.com"
          git add -A
          git commit -m "doc: regenerate groff and html man pages" || exit 0
          git push
