name: release_checks

on:
  push:
    branches:
      - release
  pull_request:
    branches:
      - release

permissions: read-all

jobs:
  verify-manual:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v3

      - name: Save current manual
        run: mv doc/zstd_manual.html doc/zstd_manual_saved.html

      - name: Generate new manual
        run: make manual

      - name: Compare manuals
        run: |
          if ! cmp -s doc/zstd_manual.html doc/zstd_manual_saved.html; then
            echo "The API manual was not updated before release !"
            exit 1
          fi

  verify-man-pages:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v3

      - name: Install dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y ruby ruby-dev
          sudo gem install ronn

      - name: Display ronn version
        run: ronn --version

      - name: Save current man pages
        run: |
          mv programs/zstd.1 programs/zstd.1.saved
          mv programs/zstdgrep.1 programs/zstdgrep.1.saved
          mv programs/zstdless.1 programs/zstdless.1.saved

      - name: Generate new manual pages
        run: make -C programs man

      - name: Compare man pages
        run: |
          for file in zstd.1 zstdgrep.1 zstdless.1; do
            if ! cmp -s programs/$file programs/$file.saved; then
              echo "The man page $file should have been updated."
              exit 1
            fi
          done
