name: Publish Release to npmjs

on:
  push:
    tags:
      - ams-v**

jobs:
  publish-npmjs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - uses: actions/setup-node@v3
        with:
          node-version: '16.x'
          registry-url: 'https://registry.npmjs.org'
      
      - uses: actions/setup-java@v3
        with:
          java-version: '11'
          distribution: 'adopt'
      
      - name: Get the version
        id: get_version
        run: echo "VERSION=$(echo ${GITHUB_REF##*/} | cut -d v -f 2)" >> $GITHUB_OUTPUT
      
      - run: npm install
      
      - run: npm run compile
      
      - run: npm test
      
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
      
      - name: Update Embedded Player
        if: success()
        run: |
          curl -L \
          -X POST \
          -H "Accept: application/vnd.github.v3+json" \
          -H "Authorization: Bearer ${{ secrets.REPO_COMMUNICATION }}" \
          https://api.github.com/repos/ant-media/StreamApp/actions/workflows/update-embedded-player.yml/dispatches \
          -d '{"ref":"master"}'



