Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RupertBarrow/27954de7d90e7e1cd05dbbfedfc82da0 to your computer and use it in GitHub Desktop.
Save RupertBarrow/27954de7d90e7e1cd05dbbfedfc82da0 to your computer and use it in GitHub Desktop.
Publishing to Github Packages NPM registry.md

Publishing to the Github Packages registry for npm

Introduction

This is about :

  • publishing to an NPM registry
  • ... which is the Github Packaged registry (for NPM)
  • ... with semantic-release
  • ... in a Github Actions CI workflow

Configuration for publishing

  • in package.json, the package must be named "@context/repo-name", where context is either a Github username (in lowercase) or a Github organization (in lowercase). Eg :
  "name": "@rupertbarrow/rapido-sf-plugin"
  • in package.json, the repository must be named with an url, like this :
  "repository": {
    "url": "git+https://github.com/RupertBarrow/rapido-sf-plugin.git"
  }
  • in package.json, the publishConfig entry must follow the following syntax (note, NO username) :
  "publishConfig": {
    "registry": "https://npm.pkg.github.com/"
  }
  • in Github Actions workflow, call run the semantic release like this :
    - run: npx semantic-release
      env:
        NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
        # Github personal access token (classic, not fine-grained) with these permissions :
        # repo, write:packages, read:packages and delete:packages
  • in Github, create a personal access token as described above and paste its value into the repository or organization secret called NPM_TOKEN
  • I use this NPM_TOKEN, and not the GITHUB_TOKEN

Configuration for using

I am publishing to a private repository. This is why I will need to authenticate to be able to install use my npm package in my work environment.

For this, I have created a file named ~/.npmrc with :

//npm.pkg.github.com/:_authToken=ghp_myGithubPersonalAccessToken
@rupertbarrow:registry=https://npm.pkg.github.com
  • the Github Personal Access token I created and used in NPM_TOKEN is placed in the first line
  • my username appears on the second line, WITH an @

I can now install my sf plugin like this, for example :

sf plugin install @rupertbarrow/rapido-sf-plugin@1.8.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment