bitliner / handi-js

Gradio for NodeJS. Quickly building form-based applications eg Machine Learning applications.
2 stars 0 forks source link

Add publish to NPM #6

Open bitliner opened 1 month ago

bitliner commented 1 month ago

Build CI workflow with:

bitliner commented 1 month ago

ChatGPT proposal below

Using semantic-release with GitHub Actions to automatically publish a pre-release version to npm from a secondary branch (like develop) is a great way to automate your release process. Here's how you can set it up:

Step 1: Install semantic-release

First, make sure semantic-release and its related plugins are installed in your project:

npm install --save-dev semantic-release @semantic-release/npm @semantic-release/git @semantic-release/github

Step 2: Configure semantic-release

Create or update the .releaserc file in your project root with the following configuration. This configuration is set up to handle pre-releases from the develop branch:

{
  "branches": [
    "main",
    {
      "name": "develop",
      "prerelease": true
    }
  ],
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "@semantic-release/changelog",
    "@semantic-release/npm",
    "@semantic-release/github",
    "@semantic-release/git"
  ]
}

Explanation:

Step 3: Set Up GitHub Actions

Create a GitHub Action workflow file at .github/workflows/release.yml:

name: Release

on:
  push:
    branches:
      - main
      - develop

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '16'
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Run semantic-release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: npx semantic-release

Explanation:

Step 4: Set Up Secrets in GitHub

  1. NPM Token:
    • Go to your npm account.
    • Create a new access token with the necessary permissions (read/write access).
    • In your GitHub repository, navigate to Settings > Secrets and variables > Actions > New repository secret.
    • Create a secret named NPM_TOKEN and paste the npm access token into the value field.

Step 5: Push to Your Branches

Summary

With this setup:

This automation leverages semantic-release to manage versioning, changelog generation, and publishing to npm, simplifying the release process and reducing manual intervention.