DEV Community

dreamcodestudio
dreamcodestudio

Posted on

Automating publishing Unity packages to npm registry

🎯 Why npmjs registry?

  • Ready up to Open Source projects
  • In-box GitHub Actions solution
  • CLI support
  • Allows tracking changes history via Unity Package Manager
  1. Generate Access Token in npmjs registry
    generation npm access token

  2. Select Access Token type
    access token type

  3. Add npm Access Token to GitHub repository secrets
    filling in github repository secrets

  4. Config GitHub workflow using a yml template as follows

name: npm

on:
  release:
    types: [published]

jobs:
  publish-npm:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v3
        with:
          node-version: '20.x'
          registry-url: https://registry.npmjs.org
      - run: npm install --package-lock-only
      - run: npm ci
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
Enter fullscreen mode Exit fullscreen mode

πŸŽ‰ Now GitHub Actions will automatically upload package to npmjs registry

github workflows example

🎁 Sample project

Unity AutoKeystore

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay