name: Deploy Skill Playground

# Rebuilds web/skills.json from the SKILL.md files and publishes web/ to
# GitHub Pages. Runs on every push to main that touches skills or the web app,
# so the live site always reflects the current skill library.

on:
  push:
    branches: [main]
    paths:
      - 'skills/**'
      - 'web/**'
      - '.github/workflows/deploy-playground.yml'
  workflow_dispatch:

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

# Allow one concurrent deployment; cancel in-progress runs for the same ref.
concurrency:
  group: pages
  cancel-in-progress: true

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Node
        uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: Rebuild skills.json from SKILL.md files
        run: node web/build-skills.mjs

      - name: Configure Pages
        uses: actions/configure-pages@v5

      - name: Upload web/ as Pages artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: web

  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@v4
