# =============================================================================
# Reusable Workflow: Playground 构建
#
# 构建 cherry-markdown playground 预览产物
# 产物: playground/ 目录 + pr-id.txt
# =============================================================================

name: 'Reusable: Playground Build'

on:
  workflow_call:

jobs:
  build:
    runs-on: ubuntu-latest
    timeout-minutes: 20
    steps:
      - run: echo ${{ github.event.number }} > pr-id.txt
      - uses: actions/upload-artifact@v4
        with:
          name: pr-id
          path: pr-id.txt
          retention-days: 5

      - uses: actions/checkout@v6

      - uses: actions/setup-node@v4
        with:
          node-version-file: .node-version
          cache: 'yarn'

      - run: yarn install

      - run: yarn build

      - run: |
          mkdir -p playground/packages/cherry-markdown
          cp -r packages/cherry-markdown/dist playground/packages/cherry-markdown
          cp -r examples/assets playground
          cp examples/*.html playground
          [ -d examples/config_helper ] && cp -r examples/config_helper playground
          find playground -type f -name "*.html" -exec sed -i 's|\.\./packages|./packages|g' {} +

      - uses: actions/upload-artifact@v4
        with:
          name: playground
          path: playground
          retention-days: 5