Home > Enterprise >  EINVALIDGHTOKEN Invalid GitHub token
EINVALIDGHTOKEN Invalid GitHub token

Time:10-13

config.yml

version: 2.1
orbs:
  node: circleci/[email protected]
jobs:
  test-build-and-publish:
    executor:
      name: node/default
    steps:
      - checkout
      - node/with-cache:
          steps:
            - run:
                name: Install nvm
                command: |
                  cd ..
                  curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
                  echo 'export NVM_DIR=$HOME/.nvm' >> $BASH_ENV
                  echo 'source $NVM_DIR/nvm.sh' >> $BASH_ENV
            - run:
                name: Set node to version required by application for future circleci steps
                command: |
                  cd ..
                  nvm install 16.17.1
                  NODE_VERSION=$(node -v)
                  nvm alias default ${NODE_VERSION//v}
            - run: yarn install            #  Install dependencies
            - run: yarn semantic-release   #  Release to npm
workflows:
  test-build-and-publish:
    jobs:
      - test-build-and-publish

release.config.js

{
    "branches": [
        {name: 'main'},
      ],
    "plugins": [
      "@semantic-release/commit-analyzer",
      "@semantic-release/release-notes-generator",
      ["@semantic-release/github", {
        "assets": ["dist/**"]
        }],
      ["@semantic-release/exec", {
        "prepareCmd": "./update-version.sh ${nextRelease.version}",
       }],
      "@semantic-release/git"
    ],
    "preset": "react"
  }

package.json

{ ...
"release": {
    "branches": [
      "main",
      "next"
    ],
    "tagFormat": "v${version}",
    "verifyConditions": [
      "@semantic-release/changelog",
      "@semantic-release/github",
      "@semantic-release/npm"
    ],
    "prepare": [
      "@semantic-release/changelog",
      "@semantic-release/npm"
    ],
    "publish": [
      "@semantic-release/github",
      "@semantic-release/npm"
    ],
    "fail": [
      "@semantic-release/github"
    ],
    "githubUrl": "https://github.ibm.com",
    "githubApiPathPrefix": "/api/v3"
  }
 }

Here is the error which I am getting

yarn run v1.22.15
$ semantic-release
[8:46:42 AM] [semantic-release] › ℹ  Running semantic-release version 19.0.5
[8:46:42 AM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/changelog"
[8:46:42 AM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/github"
[8:46:42 AM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/npm"
[8:46:42 AM] [semantic-release] › ✔  Loaded plugin "analyzeCommits" from "@semantic-release/commit-analyzer"
[8:46:42 AM] [semantic-release] › ✔  Loaded plugin "generateNotes" from "@semantic-release/release-notes-generator"
[8:46:42 AM] [semantic-release] › ✔  Loaded plugin "prepare" from "@semantic-release/changelog"
[8:46:42 AM] [semantic-release] › ✔  Loaded plugin "prepare" from "@semantic-release/npm"
[8:46:42 AM] [semantic-release] › ✔  Loaded plugin "publish" from "@semantic-release/github"
[8:46:42 AM] [semantic-release] › ✔  Loaded plugin "publish" from "@semantic-release/npm"
[8:46:42 AM] [semantic-release] › ✔  Loaded plugin "addChannel" from "@semantic-release/npm"
[8:46:42 AM] [semantic-release] › ✔  Loaded plugin "addChannel" from "@semantic-release/github"
[8:46:42 AM] [semantic-release] › ✔  Loaded plugin "success" from "@semantic-release/github"
[8:46:42 AM] [semantic-release] › ✔  Loaded plugin "fail" from "@semantic-release/github"
[8:46:43 AM] [semantic-release] › ✔  Run automated release from branch main on repository https://github.com/dhaval1624/dp-react.git
[8:46:43 AM] [semantic-release] › ✔  Allowed to push to the Git repository
[8:46:43 AM] [semantic-release] › ℹ  Start step "verifyConditions" of plugin "@semantic-release/changelog"
[8:46:43 AM] [semantic-release] › ✔  Completed step "verifyConditions" of plugin "@semantic-release/changelog"
[8:46:43 AM] [semantic-release] › ℹ  Start step "verifyConditions" of plugin "@semantic-release/github"
[8:46:43 AM] [semantic-release] [@semantic-release/github] › ℹ  Verify GitHub authentication (https://github.ibm.com/api/v3)
[8:46:43 AM] [semantic-release] › ✖  Failed step "verifyConditions" of plugin "@semantic-release/github"
[8:46:43 AM] [semantic-release] › ℹ  Start step "verifyConditions" of plugin "@semantic-release/npm"
[8:46:43 AM] [semantic-release] [@semantic-release/npm] › ℹ  Verify authentication for registry https://registry.npmjs.org/
[8:46:43 AM] [semantic-release] [@semantic-release/npm] › ℹ  Reading npm config from /home/circleci/project/.npmrc
[8:46:43 AM] [semantic-release] [@semantic-release/npm] › ℹ  Wrote NPM_TOKEN to /tmp/c6eeec1742267b199ff3674c478e84bb/.npmrc
dhaval164
[8:46:44 AM] [semantic-release] › ✔  Completed step "verifyConditions" of plugin "@semantic-release/npm"
[8:46:44 AM] [semantic-release] › ℹ  Start step "fail" of plugin "@semantic-release/github"
[8:46:44 AM] [semantic-release] [@semantic-release/github] › ℹ  Verify GitHub authentication (https://github.ibm.com/api/v3)
[8:46:44 AM] [semantic-release] › ✖  Failed step "fail" of plugin "@semantic-release/github"
[8:46:44 AM] [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 personal token (https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line) allowing to push to the repository dhaval1624/dp-react.

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

[8:46:44 AM] [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 personal token (https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line) allowing to push to the repository dhaval1624/dp-react.

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

AggregateError: 
    SemanticReleaseError: Invalid GitHub token.
        at module.exports (/home/circleci/project/node_modules/@semantic-release/github/lib/get-error.js:6:10)
        at module.exports (/home/circleci/project/node_modules/@semantic-release/github/lib/verify.js:87:21)
        at async verifyConditions (/home/circleci/project/node_modules/@semantic-release/github/index.js:27:3)
        at async validator (/home/circleci/project/node_modules/semantic-release/lib/plugins/normalize.js:34:24)
        at async /home/circleci/project/node_modules/semantic-release/lib/plugins/pipeline.js:37:34
        at async Promise.all (index 0)
        at async next (/home/circleci/project/node_modules/p-reduce/index.js:16:18)
    at /home/circleci/project/node_modules/semantic-release/lib/plugins/pipeline.js:54:11
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.pluginsConf.<computed> [as verifyConditions] (/home/circleci/project/node_modules/semantic-release/lib/plugins/index.js:80:11)
    at async run (/home/circleci/project/node_modules/semantic-release/index.js:103:3)
    at async module.exports (/home/circleci/project/node_modules/semantic-release/index.js:269:22)
    at async module.exports (/home/circleci/project/node_modules/semantic-release/cli.js:55:5)error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Exited with code exit status 1

I have generated personal token from github and added in circle ci environment variable and also added npm environment variable.

After setting env variable still I am getting above error for github token and for npm token look like its setted well. so, github token is causing issue.

CodePudding user response:

Got the issue. In package.json Previously in publishConfig access is restricted

"publishConfig": {
    "access": "restricted"
  }

updated it to access to public .

"publishConfig": {
    "access": "public"
  }
  • Related