# GitHub Actions workflow for generating project pages
# Copy this file to your project at .github/workflows/pages.yml

name: Deploy Pages

on:
  push:
    branches: [main]
    paths:
      - 'README.md'
      - 'docs/pages/**'
  workflow_dispatch:  # Allow manual trigger

permissions:
  contents: read
  pages: write
  id-token: write

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

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      # Checkout your project
      - uses: actions/checkout@v6
        with:
          path: project

      # Checkout the generator
      - uses: actions/checkout@v6
        with:
          repository: jakobwesthoff/project-page-starter
          path: generator

      # Setup Bun
      - uses: oven-sh/setup-bun@v2

      # Install generator dependencies
      - name: Install dependencies
        run: cd generator/generator && bun install

      # Create output directories
      - name: Create output directories
        run: mkdir -p dist/styles dist/assets

      # Generate the pages
      - name: Generate pages
        run: |
          bun run generator/generator/bin/generate.ts \
            --docs project/docs/pages \
            --readme project/README.md \
            --output dist \
            --templates generator/templates

      # Setup GitHub Pages
      - name: Setup Pages
        uses: actions/configure-pages@v6

      # Upload artifact
      - name: Upload artifact
        uses: actions/upload-pages-artifact@v5
        with:
          path: dist

  deploy:
    needs: build
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v5
