semantic-release: How do you publish a repository that doesn't output a node.js module?

Current behavior

When attempting to publish a javascript project that outputs a bundle instead of a node package, the script requires an NPM token.

Basically I want to publish some built assets to a cdn, but semantic-release is requiring an NPM token.

Expected behavior

The build shouldn’t require an NPM token.

Environment

{
  "release": {
    "publish": [
      {
        "path": "@semantic-release/exec",
        "cmd": "echo ${nextRelease.version}.min.js"
      },
      {
        "path": "@semantic-release/github"
      }
    ],
    "verifyConditions": "condition-circle"
  }
}
  • CI logs:

Current behavior

When attempting to publish a javascript project that outputs a bundle instead of a node package, the script requires an NPM token.

Expected behavior

The build shouldn’t require an NPM token.

Environment

  • semantic-release version: 15.0.2
  • CI environment: CircleCI
  • Plugins used: @semantic-release/exec, condition-circle
  • semantic-release configuration: .releaserc.json
{
  "release": {
    "publish": [
      {
        "path": "@semantic-release/exec",
        "cmd": "echo ${nextRelease.version}.min.js"
      },
      {
        "path": "@semantic-release/github"
      }
    ],
    "verifyConditions": "condition-circle"
  }
}
  • CI logs:
circleci build -e GH_TOKEN=<redacted> -e NPM_TOKEN=000000000000-0000-0000-000000000000

INFO: There's a newer version of CircleCI build-agent available. Run 'circleci update' for update
====>> Spin up Environment
Build-agent version 0.0.4710-44beb0a (2018-02-27T20:05:34+0000)
Starting container circleci/node:8.9.4
  using image circleci/node@sha256:b0fa2a8158710ba49cf4f42fe5b31715694026517207ff141fffb6ab45b24ab0

Using build environment variables:
  BASH_ENV=/tmp/.bash_env-localbuild-1520892408
  CI=true
  CIRCLECI=true
  CIRCLE_BRANCH=master
  CIRCLE_BUILD_NUM=
  CIRCLE_JOB=build
  CIRCLE_NODE_INDEX=0
  CIRCLE_NODE_TOTAL=1
  CIRCLE_REPOSITORY_URL=<redacted>
  CIRCLE_SHA1=3a78a4324a14578eaf523887d7f35e5178b3f395
  CIRCLE_SHELL_ENV=/tmp/.bash_env-localbuild-1520892408
  CIRCLE_WORKING_DIRECTORY=~/repo

====>> Checkout code
  #!/bin/sh
mkdir -p /home/circleci/repo && cp -r /tmp/_circleci_local_build_repo/. /home/circleci/repo
====>> Restoring Cache
Error: Skipping cache - error checking storage: not supported

Step failed
====>> Run semantic-release
  #!/bin/bash -eo pipefail
sudo npm i -g semantic-release@15.0.2
/usr/local/bin/semantic-release -> /usr/local/lib/node_modules/semantic-release/bin/semantic-release.js
+ semantic-release@15.0.2
added 387 packages in 10.944s
====>> Run semantic-release
  #!/bin/bash -eo pipefail
semantic-release
[Semantic release]: Running semantic-release version 15.0.2
Username for 'https://<redacted>': [Semantic release]: Load plugin verifyConditions from @semantic-release/npm
[Semantic release]: Load plugin verifyConditions from @semantic-release/github
[Semantic release]: Load plugin analyzeCommits from @semantic-release/commit-analyzer
[Semantic release]: Load plugin generateNotes from @semantic-release/release-notes-generator
[Semantic release]: Load plugin prepare from @semantic-release/npm
[Semantic release]: Load plugin publish from @semantic-release/npm
[Semantic release]: Load plugin publish from @semantic-release/github
[Semantic release]: Load plugin success from @semantic-release/github
[Semantic release]: Load plugin fail from @semantic-release/github
[Semantic release]: Run automated release from branch master
[Semantic release]: Call plugin verify-conditions
[Semantic release]: Verify authentication for registry https://registry.npmjs.org/
[Semantic release]: Wrote NPM_TOKEN to .npmrc.
[Semantic release]: Verify GitHub authentication
DEPRECATED: protocol option is no longer supported
DEPRECATED: host option is no longer supported
DEPRECATED: port option is no longer supported
DEPRECATED: pathPrefix option is no longer supported
[Semantic release]: Verify GitHub authentication
DEPRECATED: protocol option is no longer supported
DEPRECATED: host option is no longer supported
DEPRECATED: port option is no longer supported
DEPRECATED: pathPrefix option is no longer supported
[Semantic release]: EINVALIDGHTOKEN Invalid GitHub token.
The GitHub token (https://github.com/semantic-release/github/blob/master/README.md#github-authentication) configured in the GH_TOKEN or GITHUB_TOKEN environment variable must be a valid personnal token (https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line) allowing to push to the repository <redacted>.

Please make sure to set the GH_TOKEN or GITHUB_TOKEN environment variable in your CI with the exact value of the GitHub personnal token.


[Semantic release]: EINVALIDNPMTOKEN Invalid npm token.
The npm token (https://github.com/semantic-release/npm/blob/master/README.md#npm-registry-authentication) configured in the NPM_TOKEN environment variable must be a valid token (https://docs.npmjs.com/getting-started/working_with_tokens) allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level (https://docs.npmjs.com/getting-started/using-two-factor-authentication#levels-of-authentication) is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


[Semantic release]: EINVALIDGHTOKEN Invalid GitHub token.
The GitHub token (https://github.com/semantic-release/github/blob/master/README.md#github-authentication) configured in the GH_TOKEN or GITHUB_TOKEN environment variable must be a valid personnal token (https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line) allowing to push to the repository <redacted>.

Please make sure to set the GH_TOKEN or GITHUB_TOKEN environment variable in your CI with the exact value of the GitHub personnal token.


{ AggregateError: 
    SemanticReleaseError: Invalid npm token.
        at module.exports (/usr/local/lib/node_modules/semantic-release/node_modules/@semantic-release/npm/lib/get-error.js:6:10)
        at module.exports (/usr/local/lib/node_modules/semantic-release/node_modules/@semantic-release/npm/lib/verify-auth.js:23:33)
        at <anonymous>
    SemanticReleaseError: Invalid GitHub token.
        at module.exports (/usr/local/lib/node_modules/semantic-release/node_modules/@semantic-release/github/lib/get-error.js:6:10)
        at module.exports (/usr/local/lib/node_modules/semantic-release/node_modules/@semantic-release/github/lib/verify.js:86:21)
        at <anonymous>
    at Object.verifyConditions (/usr/local/lib/node_modules/semantic-release/lib/plugins/pipeline.js:52:45)
    at <anonymous> name: 'AggregateError' }
Error: Exited with code 1
Step failed

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

I’ll submit some pull requests per each repo vs trying to delineate what can be improved further. Thanks again! Love the tooling.

Just want to say thank you for your help. At the end of the day, it came down to to major roadblocks:

  • npmPublish: false at top level in your release configuration
  • configuring the semantic-release/github plugin correctly
    • specifically githubUrl and githubApiPathPrefix

At the end of the day it was in regards to my previous comment:

The only thing that I can think would impact this would be something in regards to my repo being on a github enterprise account.

Here’s the .releaserc.json configuration that I used:

{
  "npmPublish": false,
  "githubUrl": "https://github.intuit.com",
  "githubApiPathPrefix": "/api/v3",
  "publish": [
    {
      "path": "@semantic-release/github"
    },
    {
      "path": "@semantic-release/exec",
      "cmd": "yarn version-assets -d ./dist -r ${nextRelease.version}"
    }
  ],
  "analyzeCommits": {
    "preset": "angular",
    "releaseRules": [
      {
        "type": "docs",
        "scope": "README",
        "release": "patch"
      },
      {
        "type": "refactor",
        "release": "patch"
      },
      {
        "type": "style",
        "release": "patch"
      }
    ],
    "parserOpts": {
      "noteKeywords": [
        "BREAKING CHANGE",
        "BREAKING CHANGES",
        "BREAKING"
      ]
    }
  }
}

Feedback

I found a few things that I may end up sending a pull request for:

  • It’s unclear that if you want to set a configuration to override all aspects you have to set that at the top level of the configuration object (e.g. "npmPublish: false) or setting it for every single plugin config.
  • The semantic-release-cli does not take a private github url into account when creating a gh token
  • The required configurations for the github token are not super clear, they’re defined in the semantic-release-cli as:

    Creates (and saves for later use) a GitHub Personal Access Token with the following permissions: repo, read:org, repo:status, repo_deployment, user:email, write:repo_hook

However, I find that this is pretty buried and should probably be surfaced somewhere else outside of just the semanti-release-cli

The npm plugin is used for the publish, the verifyConditons and the prepare step. You need to set npmPublish in the 3 of them. Or for more simplicity you can set npmPublish directly in the release object.

Even if you don’t publish on npm, you still need to configure GH_TOKEN to publish on GitHub. This is why you get an error message.

I think this FAQ should answer your exact question.

Also you shouldn’t use condition-circle as CI related verify plugins are not required since several version of semantic-release.