Home

Awesome

action-npm-publish

This is a GitHub action that handles publishing to NPM for a project that represents a single package (in the case of a polyrepo) or a collection of packages (in the case of a monorepo).

Requirements

This action assumes that Yarn is installed and that the package is using Yarn v3. It may fail for other Yarn versions or other package managers.

If your project is configured to use the node-modules linker and defines a prepack script for any releasable packages, you will need to ensure that the file node_modules/.yarn-state.yml is present before this action is invoked. This file is generated automatically when installing dependencies. If you want to publish without dependencies present, you can instantiate an empty state file or restore one from a cache.

This action depends upon the action slackapi/slack-github-action@007b2c3c751a190b6f0f040e47ed024deaa72844. This action is authored by a Marketplace "verified creator". If your repository or organization restricts which actions can be used and does not allow Marketplace verified creators by default, ensure that this action is listed as an allowed action.

Usage

Quick start

If you're in a hurry, take a look at the publish-release workflow from the module template, which uses this action to publish appropriate packages whenever a release commit is merged, once in dry-run mode and once in "real" mode. (A release commit is a commit that changes the version of the primary package within the project, whether that is the sole package in the case of a polyrepo package, or the root package in the case of a monorepo.) Note that in order to use this workflow file in your project, you will need to create an npm-publish environment via your repository's settings and set the NPM_TOKEN secret within this environment to the authentication token for the MetaMask organization on npmjs.com.

Publish mode

Add the following to a job's list of steps. This requires that you set the NPM_TOKEN secret in your repository's settings to an appropriate NPM authentication token:

- uses: MetaMask/action-npm-publish@v2
  with:
    npm-token: ${{ secrets.NPM_TOKEN }}

Dry run mode

If you omit npm-token, then packages will be prepared for publishing, but no publishing will actually occur:

- uses: MetaMask/action-npm-publish@v4

Slack announce

You can optionally send deployment announcements to Slack by providing a slack-webhook-url input:

The absolute minimum configuration for this is:

- uses: MetaMask/action-npm-publish@v4
  with:
    slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}

We've added the ability to customize the message posted in Slack and those optional inputs are as follows:

example:

- uses: MetaMask/action-npm-publish@v4
  with:
    slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
    icon-url: https://ricky.codes/me.jpg
    username: rickybot
    # re subteam, see: https://api.slack.com/reference/surfaces/formatting#mentioning-groups
    subteam: S042S7RE4AE # @metamask-npm-publishers
    channel: dev-channel

You can read more about these option in the API section below

image

API

Inputs

The following inputs only apply if slack-webhook-url is set...