name: Publish

on:
  push:
    tags:
      - "v*"

permissions:
  contents: write
  id-token: write

jobs:
  publish:
    if: github.repository == 'sirmalloc/ccstatusline'
    name: Publish to npm
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: oven-sh/setup-bun@v2
      - uses: actions/setup-node@v6
        with:
          node-version: 24
          registry-url: "https://registry.npmjs.org"
          package-manager-cache: false
      - run: bun install
      - run: bun run lint
      - run: bun test
      - run: npm publish
      - name: Create GitHub release
        run: >
          gh release create "$GITHUB_REF_NAME"
          --title "$GITHUB_REF_NAME"
          --generate-notes
          --notes "Published to npm: https://www.npmjs.com/package/ccstatusline"
        env:
          GH_TOKEN: ${{ github.token }}
