# This is a basic workflow to help you get started with Actions

name: Render User Manual
 
on:
  # Only run when User Manual markdown source changes
  pull_request:
    types:
      - closed
    paths: 
      - 'USER_MANUAL.md'
      
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    if: github.event.pull_request.merged

    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2

      - name: Install pandoc package
        run: |
             sudo apt-get update
             sudo apt-get install pandoc texlive-latex-base texlive-fonts-recommended texlive-fonts-extra
           
      - name: Render User Manual to PDF and HTML
        run: |
             git_hash=$(git describe --always HEAD); date=$(date "+%b %d %Y"); pandoc USER_MANUAL.md -o USER_MANUAL.pdf -fmarkdown-implicit_figures --from=markdown -V geometry:margin=1in --toc --highlight-style=espresso --number-sections -V title:"FreeDV User Manual\linebreak ${date} ${git_hash}" -H disable_float.tex
             pandoc -o USER_MANUAL.html -fmarkdown-implicit_figures --from=markdown --number-sections USER_MANUAL.md
             ls -l USER_MANUAL.*
        
      - name: Update PDF version in repo
        run: |
             git config --local user.email "$(git log --format='%ae' HEAD^!)"
             git config --local user.name "$(git log --format='%an' HEAD^!)"
             git commit -m "latest user manual PDF" USER_MANUAL.pdf USER_MANUAL.html
             git push
