name: Deploy Docs to Pages

on:
  # Runs on pushes targeting the default branch
  push:
    branches: ["main"]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write

# Allow one concurrent deployment
concurrency:
  group: "pages"
  cancel-in-progress: true

jobs:
  deploy:
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    container: ghcr.io/ietf-tools/xml2rfc-base:latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        
      - name: Setup Pages
        uses: actions/configure-pages@v5
        
      - name: Generate docs
        run: |
          mkdir docs-dist
          xml2rfc --docfile --out docs.xml
          xml2rfc --html docs.xml --out docs-dist/index.html

      - name: Generate artifact
        run: |
          tar \
            --dereference --hard-dereference \
            --directory docs-dist \
            -cvf artifact.tar \
            --exclude=.git \
            --exclude=.github \
            .
        
      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: github-pages
          path: artifact.tar
          retention-days: 1
        
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4
