name: Deploy to GitHub Pages
on:
  workflow_call:
    inputs:
      settings:
        required: true
        description: "The path to your Pelican settings file (`pelican`'s `--settings` option), for example: 'publishconf.py'"
        type: string
      requirements:
        required: false
        default: "pelican"
        description: "The Python requirements to install, for example to enable markdown and typogrify use: 'pelican[markdown] typogrify' or if you have a requirements file use: '-r requirements.txt'"
        type: string
      output-path:
        required: false
        default: "output/"
        description: "Where to output the generated files (`pelican`'s `--output` option)"
        type: string
permissions:
  contents: read
  pages: write
  id-token: write
concurrency:
  group: "pages"
  cancel-in-progress: false
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: "3.11"
      - name: Configure GitHub Pages
        id: pages
        uses: actions/configure-pages@v3
      - name: Install requirements
        run: pip install ${{ inputs.requirements }}
      - name: Build Pelican site
        run: |
          pelican \
            --settings "${{ inputs.settings }}" \
            --extra-settings SITEURL='"${{ steps.pages.outputs.base_url }}"' \
            --output "${{ inputs.output-path }}"
      - name: Upload artifact
        uses: actions/upload-pages-artifact@v2
        with:
          path: ${{ inputs.output-path }}
  deploy:
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v2
