name: Publish documents
on: [push]

env:
  OUTPUT_FILENAME: "document"
  USER_AGENT: "$GITHUB_REPOSITORY ($GITHUB_SERVER_URL/$GITHUB_REPOSITORY)"

jobs:
  prepare-and-build-documents:
    runs-on: ubuntu-latest
    container:
      image: registry.gitlab.com/tibhannover/oer/markdown-pandoc-processor
    steps:
      - uses: actions/checkout@v3
      - run: |
          /build/process.sh
          ls -l
          mkdir .public
          cp -r * .public
          mv .public public
      - uses: actions/upload-pages-artifact@v1
        with:
          path: ./public

  # Deployment job
  deploy:
    if: ${{ github.ref == 'refs/heads/main' }}
    # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
    permissions:
      pages: write
      id-token: write
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    needs: prepare-and-build-documents
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v2
