Auto update package.json on publishing

Hello folks,
I am playing with github actions and gpr for a while. By far, I have successfully published a package to gpr but on the next change (pr), publishing failed if I dont update the version in package.json.
I am looking for a way to update my version in package.json automatically whenever a PR got merged to master.

Below is the current yml I am using, it is however updating the version of package and publishing it, but the version on package.json remains the same.

name: Node CI
on: [push, pull_request]
jobs:

  publish-gpr:
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/master'
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-node@v1
        with:
          node-version: 12
          registry-url: https://npm.pkg.github.com/
          scope: '@something'
      - name: Setup GIT
        run: |
          git switch -c master
          git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
          git config user.name "$GITHUB_ACTOR"
      - name: Install and Publish
        run: |
          yarn
          npm version patch -m "Upgrade to %s"
          git push && git push --tags
          yarn publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

Hi @vipulrawat ,

We can execute the command npm version [major | minor | patch] to update the package version in _ package.json _. I noticed you have used this command in the steps, and it seems does not work.
There has a point you need to pay attention to is that when you executing the npm command, the work directory should be the package root directory where the _ package.json _ is located. So please check if the work directory is correct.
And please also share the complete debug logs of the failed run, so that we can investigate this issue further and analyze the root cause.
To view the debug logs, you need to add two Secrets ( ACTIONS_RUNNER_DEBUG and ACTIONS_STEP_DEBUG , set their value to be true ) on the Settings page of the repository. Then trigger a new workflow run, or re-run the failed one.

@brightran Thanks for the info.
I couldn’t paste the whole log due to its size and lines, however I found something that I suspect is an error.
To rephrase my issue: The Actions to publish to gpr run successfully and it publishes with the new verison but the version field in package.json remains the same.

fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push origin HEAD:<name-of-remote-branch>