0.6.0 • Published 2 months ago

npm-semantic-publish-action v0.6.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

GitHub action to publish npm packages with semanantic versioning rules

CI CodeQL Lint Codebase Check Transpiled JavaScript NPM Version Downloads Coverage

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

Once your repository is configured with this action, to generate a new version you have just to add to the commit message one of the following string:

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

Secrets Configuration

This action requires the following Secrets:

  1. ACTION_TOKEN:
    1. generate an access token able to make commits, tags and push them (see Managing your personal access tokens)
    2. add the above generated token in the secret ACTION_TOKEN (see Using secrets in GitHub Actions)
  2. NPM_TOKEN:
    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)

Action configuration

  • Add to the checkout action the ACTION_TOKEN secret:
uses: actions/checkout@v4
    with:
      token: ${{ secrets.ACTION_TOKEN }}
  • 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'
  • populate git config with user and mail:
uses: fregante/setup-git-user@v2
  • add actions/npm-semver-publish step:
name: Run my Action
id: run-action
uses: actions/npm-semver-publish@v1
with:
  target-branch: 'master' #where a new release is applied
env:
  NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

That's it!

Complete job example

on:
  push:
    branches: main

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
      id: checkout
      uses: actions/checkout@v4
      with:
        token: ${{ secrets.ACTION_TOKEN }}
    - uses: fregante/setup-git-user@v2
      uses: actions/setup-node@v4
      with:
        node-version: 20.x
        registry-url: 'https://registry.npmjs.org'
    - name: Run my Action
      id: run-action
      uses: actions/npm-semver-publish@v1
      with:
        target-branch: 'master'
      env:
        NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

Action Parameters

See action.yml

NameTypeDefaultDescription
target-branchstringmasterBranch name new release should be executed

Development

  1. Install the dependencies

    npm install
  2. Package the JavaScript for distribution

    npm run bundle
  3. Run the tests

    npm test

How to develop the GitHub Action

GitHub Actions Toolkit documentation.

  1. Create a new branch
  2. Update the contents of src/
  3. Add tests to __tests__/
  4. Format, test, and build the action

    npm run all

    !WARNING

    This step is important! It will run ncc to build the final JavaScript action code with all dependencies included. If you do not run this step, your action will not work correctly when it is used in a workflow. This step also includes the --license option for ncc, which will create a license file for all of the production node modules used in your project.

  5. Commit your changes

    git add .
    git commit -m "My first action is ready!"
  6. Push them to your repository

    git push -u origin releases/v1
  7. Create a pull request and get feedback on your action

  8. Merge the pull request into the main branch

Validate the Action

You can now validate the action by referencing it in a workflow file. For example, ci.yml demonstrates how to reference an action in the same repository.

steps:
  - name: Checkout
    id: checkout
    uses: actions/checkout@v3

  - name: Test Local Action
    id: test-action
    uses: ./
    with:
      target-branch: 'release'

  - name: Print Output
    id: output
    run: echo "${{ steps.test-action.outputs.version }}"

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
0.5.0

2 months ago

0.4.0

2 months ago

0.6.0

2 months ago

0.5.1

2 months ago

0.1.0

2 months ago

0.3.0

2 months ago

0.2.0

2 months ago

0.0.10

2 months ago

0.0.11

2 months ago

0.0.12

2 months ago

0.0.9

2 months ago

0.0.8

2 months ago

0.0.7

2 months ago

0.0.4

2 months ago