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:
1
name: publish
2
3
on:
4
release:
5
types: [created]
6
7
jobs:
8
publish-npm:
9
runs-on: ubuntu-latest
10
steps:
11
- uses: actions/[email protected]
12
- uses: actions/[email protected]
13
with:
14
node-version: 12
15
registry-url: https://registry.npmjs.org/
16
- name: Set version from tag
17
run: npm --no-git-tag-version version ${GITHUB_REF#refs/*/}
18
- run: npm publish
19
env:
20
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
Copied!
  1. 1.
    I'm running only on release creation
  2. 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. 3.
    Finally you'll need to create that secret in GH for the publish step.
Last modified 1mo ago
Copy link