name: Publish AI SDK

on:
    push:
        branches:
            - main
        paths: 
            - "packages/ai-sdk/package.json"

jobs:
    publish:
        runs-on: ubuntu-latest
        permissions: 
            contents: read
            id-token: write
        defaults:
            run:
                working-directory: ./packages/ai-sdk
        steps:
            - name: Checkout
              uses: actions/checkout@v4

            - name: Setup Node
              uses: actions/setup-node@v4
              with:
                registry-url: 'https://registry.npmjs.org'

            - name: Setup Bun
              uses: oven-sh/setup-bun@v2
            
            - name: Setup pnpm
              uses: pnpm/action-setup@v4

            - name: Install dependencies
              run: bun install

            - name: Build
              run: bun run build

            - name: Publish
              run: pnpm publish --access public --verbose
              env:
                NPM_CONFIG_PROVENANCE: true
                NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}