Update version and publish npm from GH

Setting up CI with GitHub Actions to update a node.js package version from GitHub release tag and publish it to npm

Super proud of this, since it's my first node.js package ever (created brand-new account on https://www.npmjs.com/ and all 😁), for doing syntax highlighting for dotnetconfig that works in docfx.

Assuming you already have a package.json in the root repo dir, add the .github\workflows\npm.yml as follows:

name: publish

    types: [created]

    runs-on: ubuntu-latest
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
          node-version: 12
          registry-url: https://registry.npmjs.org/
      - name: Set version from tag
        run: npm --no-git-tag-version version ${GITHUB_REF#refs/*/}
      - run: npm publish
          NODE_AUTH_TOKEN: ${{secrets.npm_token}}
  1. I'm running only on release creation

  2. Using the GitHub envvar for the checked out tag, I'm updating the version but opting out of the git behavior (which fails on CI because it's a detached head at that point)

  3. Finally you'll need to create that secret in GH for the publish step.

Last updated