name: Check and Release

# to run tasks that would need to run before releasing

on:
  push:
    branches:
      - master # run on pushed commits to `master`
  pull_request:
    branches:
      - master # run on pull requests to `master`

jobs:
  release:
    runs-on: ubuntu-latest
    name: Run release scripts
#    needs: prerelease
    steps:
      - uses : actions/checkout@v3
        with:
          submodules: true
          fetch-depth: 1
      - name : Use Node.js version ${{ matrix.node-version }}
        uses : actions/setup-node@v3
        with :
          registry-url: https://registry.npmjs.org/

      - name : Install dependencies
        run  : 'npm install'

      - name: Check if version has been updated
        id: check
        uses: EndBug/version-check@v1
        with:
          file-url: https://unpkg.com/@indic-transliteration/common_maps/package.json
          static-checking: localIsNew
      - name: Log when changed
        if: steps.check.outputs.changed == 'true'
        run: 'echo "Version change found in commit ${{ steps.check.outputs.commit }}! New version: ${{ steps.check.outputs.version }} (${{ steps.check.outputs.type }})"'

      - run: npm publish --access public
        if: ${{ steps.check.outputs.changed == 'true' && github.event_name != 'pull_request'}}
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
