name: Arena Core

on:
  push:
    branches:
      - 'master'
    paths-ignore:
      - 'package.json'

jobs:
  publish-new-version:
    runs-on: ubuntu-latest
    steps:
      - name: 'Checkout'
        uses: actions/checkout@v4
        with:
          token: ${{ secrets.ACCESS_TOKEN }}
      - name: Temporarily disable "include administrators" branch protection
        uses: benjefferies/branch-protection-bot@master
        if: always()
        with:
          access_token: ${{ secrets.ACCESS_TOKEN }}
      - name: 'Automated Version Bump'
        uses: 'phips28/gh-action-bump-version@master'
        env:
          GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
        with:
          tag-prefix: 'v'
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          registry-url: https://npm.pkg.github.com/
          scope: '@openforis'

      - run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.ACCESS_TOKEN }}" > .npmrc
      - run: echo "\"@openforis:registry\"" "\"https://npm.pkg.github.com\"" > .yarnrc
      - run: cat .npmrc
      - run: cat .yarnrc
      - run: npm install
      - run: npm publish
      - name: Enable "include administrators" branch protection
        uses: benjefferies/branch-protection-bot@master
        if: always() # Force to always run this step to ensure "include administrators" is always turned back on
        with:
          access_token: ${{ secrets.ACCESS_TOKEN }}
          owner: openforis
          repo: arena-core