name: Update website docs

on:
  push:
    branches:
      - main
    paths:
      - "doc/**"

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

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Clone rosenpass-website repository
        uses: actions/checkout@v3
        with:
          repository: rosenpass/rosenpass-website
          ref: main
          path: rosenpass-website
          token: ${{ secrets.PRIVACC }}

      - name: Copy docs to website repo
        run: |
          cp -R doc/* rosenpass-website/static/docs/

      - name: Install mandoc
        run: |
          sudo apt-get update
          sudo apt-get install -y mandoc

      - name: Compile man pages to HTML
        run: |
          cd rosenpass-website/static/docs/
          for file in *.1; do
            mandoc -Thtml "$file" > "${file%.*}.html"
          done

      - name: Commit changes to website repo
        uses: EndBug/add-and-commit@v9
        with:
          author_name: GitHub Actions
          author_email: actions@github.com
          message: Update docs
          cwd: rosenpass-website/static/docs
          github_token: ${{ secrets.PRIVACC }
