name: Release Packager

on:
  push:
    branches:
      - main
    paths:
      - "packages/**"
  workflow_dispatch:

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
  release:
    name: Release
    runs-on: ubuntu-latest
    if: github.repository == 'fontsource/fontsource'
    steps:
      - name: checkout
        uses: actions/checkout@v4

      - uses: oven-sh/setup-bun@v2
        with:
          bun-version: latest

      - name: Install
        run: bun install

      - name: Create Release Pull Request or Publish to npm
        id: cs
        uses: changesets/action@v1
        with:
          version: "bun run ci:version"
          publish: "bun run ci:publish"
          commit: "chore: release versions"
          title: "Release 🎉"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

      - name: Dispatch Dependency Update PR to font-files
        if: steps.cs.outputs.published == 'true'
        uses: peter-evans/repository-dispatch@v2
        with:
          token: ${{ secrets.DISPATCH_PAT }}
          repository: fontsource/font-files
          event-type: update-deps
