name: CI

on:
  push:
    branches: [main, master]
    tags: ['v*']
  pull_request:

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Validate package.json
        run: node -e "JSON.parse(require('fs').readFileSync('Packages/rudder.sdk/package.json', 'utf8'))"

      - name: Verify bundled Rudder.Core.dll
        run: test -f Packages/rudder.sdk/Runtime/Plugins/Rudder.Core.dll

  publish:
    if: startsWith(github.ref, 'refs/tags/v')
    needs: check
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Node
        uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Configure registry auth
        run: echo "//hub.rudder.build/api/packages/rudder/npm/:_authToken=${{ secrets.GITEA_TOKEN }}" > Packages/rudder.sdk/.npmrc

      - name: Pack
        run: make pack

      - name: Publish
        run: make publish
