Git Product home page Git Product logo

publish's Introduction

primer/publish

This GitHub Action publishes to npm with the following conventions:

  1. If we're on the default branch, the version field is used as-is and we just run npm publish --access public.
    • After publishing a new version on the default branch, we tag the commit SHA with v{version} via the GitHub API.
    • If the version in package.json is already published, we exit with a 0 code. Previously, we exited with a 78 code, which was Actions v1-speak for "neutral", but this has been removed from Actions v2.
  2. If we're on a release-<version> branch, we publish a release candidate to the next npm dist-tag with the version in the form: <version>-rc.<sha>.
    • A status check is created with the context npm version noting whether the version field in package.json matches the <version> portion of the branch. If it doesn't, the check's status is marked as pending.
  3. Otherwise, we publish a "canary" release, which has a version in the form: 0.0.0-<sha>.

Status checks

Depending on the branch, a series of statuses will be created by this action in your checks: publish is the action's check, and publish {package-name} is a commit status created by the action that reports the version published and links to unpkg.com via "Details":

image

If you're on a release branch (release-<version>) and the <version> portion of the branch name doesn't match the version field in package.json, you'll get a pending status reminding you to update it:

image

Usage

You will need to provide an npm access token with publish permissions via the NPM_AUTH_TOKEN secret in the Actions visual editor if you haven't already. The GITHUB_TOKEN secret is also required to create tags after releasing on the master branch.

We suggest that you place this action after any linting and/or testing actions to catch as many errors as possible before publishing.

Actions

To use this in an Actions workflow, add the following YAML to one or more of your steps:

- uses: primer/publish@v3
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

You can pass additional inputs via the with key:

- name: Publish to the npm registry
  uses: "primer/[email protected]"
  with:
    npm-args: "--unsafe-perm --allow-same-version"
    default-branch: "main"

Inputs

dry_run

Does everything publish would do except actually publishing to the registry. Reports the details of what would have been published.

Default: false

Example

- name: Publish to the npm registry
  uses: "primer/[email protected]"
  with:
    dry_run: true

dir

Accepts a path to the directory that contains the package.json to publish.

Default: .

Example

- name: Publish to the npm registry
  uses: "primer/[email protected]"
  with:
    dir: "packages/example"
}

npm_args

It's possible to pass additional arguments to npm via the npm_args input in your workflow action.

- name: Publish to the npm registry
  uses: "primer/[email protected]"
  with:
    npm_args: "--unsafe-perm --allow-same-version"

default_branch

The branch you'd like to use to trigger releases. Typically this is main or master.

Default: master

- name: Publish to the npm registry
  uses: "primer/[email protected]"
  with:
    default_branch: "main"

release_tag

The release_tag input can be used to override the auto-generated release tag.

Default: latest

- name: Publish to the npm registry
  uses: "primer/[email protected]"
  with:
    release_tag: "1.0.0"

publish's People

Contributors

colebemis avatar dependabot[bot] avatar jay-oswald avatar joelhawksley avatar jonrohan avatar shawnbot avatar smockle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

publish's Issues

NPM 401 Error

This recent change to the npm registry url causes npm ERR! 401 Unauthorized - PUT https://registry.npmjs.org/<package-name> - You must be logged in to publish packages.

Although the url looks correct it doesn't seem to work anymore when using and NPM_AUTH_TOKEN.

Unable to read package.json

Hey, It doesn't seem like "--dir" is not working with actions or am I using it wrong?

The package file is at swagger/generator/package.json

Action:

    - name: Publish
      uses: primer/publish@master
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        NPM_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
        args: "--dir=swagger/generator"

I have tried to put --dir=../../swagger/generator too but it doesn't do any difference.

Action Logs:

/usr/bin/docker run --name HIDDEN--label 04bb81 --workdir /github/workspace --rm -e GITHUB_TOKEN -e NPM_AUTH_TOKEN -e args -e HOME -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/e-commerce-backend/e-commerce-backend":"/github/workspace" HIDDEN
user.email=HIDDEN
user.name=erictuvesson
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=https://github.com/erictuvesson/e-commerce-backend
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
gc.auto=0
[publish] options: {
  "dir": ".",
  "$0": "/primer-publish/cli.js"
}
[publish] npm args: []
/primer-publish/src/context.js:17
    throw new Error(`Unable to read package.json in ${path.join(process.cwd(), dir)}!`)
    ^

Error: Unable to read package.json in /github/workspace!
    at getContext (/primer-publish/src/context.js:17:11)
    at publish (/primer-publish/src/publish.js:15:10)
    at Object.<anonymous> (/primer-publish/cli.js:29:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
##[error]Docker run failed with exit code 1

Support publishing to the GitHub Package Registry

There are several ways to do this, but if we're going to support publishing to both npm and GPM (sorry) automatically we'll need to do one of the following:

  1. Add instructions for publishing to GPM. Luckily, our entrypoint started as a copy of the one from actions/npm, so we already support custom values for NPM_REGISTRY_URL. In other words, all you should have to do is add this to your workflow:

    action "gpm publish" {
      uses = "primer/publish"
      env = {
        NPM_REGISTRY_URL = "<gpm registry url here>",
      }
      secrets = [
        "NPM_AUTH_TOKEN" # your GitHub access token w/necessary permissions
      ]
    }
  2. Update this action to publish to GPM. We would need to add a level of abstraction around publishing to multiple registries, each with their own auth token. For instance: we might only publish to npm if NPM_AUTH_TOKEN is set, and/or to GPM if GPM_AUTH_TOKEN is set.

  3. Write a new CLI that runs both of them, then call that from the action. In other words, every instance of npm publish becomes gpm publish here. I haven't looked yet, but this may already exist.

Fail when trying to publish existing version

Similar to #10

I am using this package to publish other things to the NPM, at the moment if you try to publish without a version bump the package runs, and in the log it says something like

[publish] skipping "npm version" because "0.1.4" matches package.json
[publish] 0.1.4 is already published

It would be great if when this happened the action failed, so you know it didn't publish, and you forgot a version bump or something.

Tests Failing

the test suite for this library needs to be updated, leaving a note so that I remember to circle back ❤️

Neutral status exit stops other Actions from running

I ran into the situation where I didn't want to publish anything on merge to master, but I did want to redeploy the docs using primer/deploy, but because the version in package.json for the package hadn't changed, the publish Action exited with a neutral status, which stopped the primer/deploy Action from running.

Is it possible to exit with a status that doesn't stop any other Actions from running? I figured that was the point of neutral statuses but I guess not!

https://github.com/primer/blueprints/runs/66380774

Avoid trying to publish over existing versions

The issue with duplicate Actions runs is biting us here: both the canary and latest versions fail to publish on one of the builds whenever repos merge to master. It's not preventing publishing because one of the builds "wins" by getting to npm publish first, but it is causing the check runs to fail and making it hard to find the logs for the run that actually published in repos' Actions view.

I think it makes sense to double-check whether the version we're about to publish has been published, regardless of what version it is. Force-pushing, for instance, causes problems because Actions run but there's already a version published for the already-pushed commit's version (0.0.0-{sha}).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.