Skip to content

Copy npm publishing strategy from another project #9

Copy npm publishing strategy from another project

Copy npm publishing strategy from another project #9

name: Node.js Package
on: push
jobs:
publish-gpr:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
registry-url: https://npm.pkg.github.com/
- run: npm ci
- run: npm run build
- name: Modify package.json for local context
if: steps.version.outputs.is_valid == 'true'
# Values in package.json must match the current GitHub repository to
# publish to it.
run: |
npm exec -- json -I -f package.json -e "this.name='@$GITHUB_REPOSITORY'"
npm exec -- json -I -f package.json -e "this.repository='https://github.com/$GITHUB_REPOSITORY'"
- name: Release NPM package
if: steps.version.outputs.is_valid == 'true'
# The latest tag follows tagged versions to follow NPM conventions.
run: |
npm version ${{ env.NPM_VERSION }} --no-git-tag-version
cat package.json
npm publish --tag latest
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}