npm-semantic-publish

1.34.0 • Public • Published

GitHub action to publish npm packages with semanantic versioning rules

CI CodeQL Lint Codebase Check Transpiled JavaScript NPM Version Downloads Coverage

Marketplace

Follow me, and consider starring the project to show your ❤️ and support.

Table of Contents

This action allow your project to create a new release, based on semantic versionig principles, and publish it to your npm registry.

Semantic versioning over commit message

To generate a new version (git tag and npm package publishing), you have just to add to the commit message one of the following key:

  • [MAJOR] or [major]: new major release, e.g. v1.0.0 -> v2.0.0 will be executed
    • git commit -m "add best feature ever [major]"
  • [PATCH] or [patch]: new patch release, e.g. v1.0.0 -> v1.0.1 will be executed
    • git commit -m "fix best feature ever [patch]"
  • without any of the above keywords a new minor release will be executed, e.g. v1.0.0 -> v1.1.0
    • git commit -m "update best feature ever"

An new release is only exeuted on the defined target-branch (see Action Usage)

Action usage

Action Parameters

See action.yml

Name Type Default Description
target-branch string master Branch name new release should be executed
provenance string false NPM package provenance

❗ When the Action Parameter provenance is set to true the id-token permission must be set to write:

permissions:
  id-token: write

Complete action example

on:
  push:
    branches: master #the branch name must be the same of **target-branch**

jobs:
  publish:
    runs-on: ubuntu-latest
    permissions:
      contents: write #allow to push on git repo
      id-token: write #allow to publish npm package
    steps:
      - name: Checkout
      id: checkout
      uses: actions/checkout@v4 #checkout git repo
      uses: actions/setup-node@v4 #setup node env
      with:
        node-version: 20.x
        registry-url: 'https://registry.npmjs.org'
    - name: Run my Action
      id: run-action
      uses: iuccio/npm-semver-publish-action@v1.0.0 #execute npm semver publish
      with:
        target-branch: master
        provenance: true
      env:
        NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} #npm token

Action configuration Step-by-Step

Step1 - Secrets Configuration

This action requires the NPM_TOKEN secret configuretion:

  1. generate a new npm token able to publish Creating and viewing access tokens
  2. add the above generated token in the secret NPM_TOKEN (see Using secrets in GitHub Actions)

Step 2

Add permissions to to push on git and publish on npm

permissions:
  contents: write
  id-token: write

Step 3

Add to the checkout action:

uses: actions/checkout@v4

Step 4

Add an actions/setup-node step to your workflow. If you have one already, ensure that the registry-url input is set (e.g. to https://registry.npmjs.org) so that this action can populate your .npmrc with authentication info:

uses: actions/setup-node@v4
with:
  node-version: 20.x
  registry-url: 'https://registry.npmjs.org'

Step 5

add actions/npm-semver-publish step:

name: Run my Action
id: run-action
uses: iuccio/npm-semver-publish-action@v1.0.0
with:
  target-branch: 'master' #where a new release is applied
  provenance: true #if you want to publish on npm registry the provenance
env:
  NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

That's it!

Development

See Development for more information.

License

CSVtoJSON is licensed under the GNU General Public License v3.0 License.

Buy me a Coffee

Just if you want to support this repository:

  • BTC tip address: 37vdjQhbaR7k7XzhMKWzMcnqUxfw1njBNk

Package Sidebar

Install

npm i npm-semantic-publish

Weekly Downloads

54

Version

1.34.0

License

MIT

Unpacked Size

233 kB

Total Files

35

Last publish

Collaborators

  • iuccio