name: Deploy Astro site to GitHub Pages

on:
  push:
    branches:
      - main
    paths:
      - ".github/workflows/pages.yml"
      - "landing-page/**"
      - "skills/**"
      - "plugin.json"
      - "gemini-extension.json"
  pull_request:
    paths:
      - ".github/workflows/pages.yml"
      - "landing-page/**"
      - "skills/**"
      - "plugin.json"
      - "gemini-extension.json"
  workflow_dispatch:

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

      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm
          cache-dependency-path: landing-page/package-lock.json

      - name: Setup Pages
        if: github.event_name != 'pull_request'
        uses: actions/configure-pages@v5
        with:
          enablement: true

      - name: Install dependencies
        working-directory: landing-page
        run: npm ci

      - name: Build
        working-directory: landing-page
        run: npm run build

      - name: Upload artifact
        if: github.event_name != 'pull_request'
        uses: actions/upload-pages-artifact@v3
        with:
          path: landing-page/dist

  deploy:
    if: github.event_name != 'pull_request'
    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@v4
