1

The GitHub actions fails with this output:

npm error need auth This command requires you to be logged in to https://registry.npmjs.org/
npm error need auth You need to authorize this machine using npm adduser

here is the log for publish-npm job:

npm warn publish npm auto-corrected some errors in your package.json when publishing.  Please run "npm pkg fix" to address these errors.
npm warn publish errors corrected:
npm warn publish "bin[analyze-project]" script name was cleaned
npm notice
npm notice 📦  [email protected]
npm notice Tarball Contents
npm notice 32B .diagnoseignore
npm notice 604B .github/workflows/ci.yaml
npm notice 1.4kB .github/workflows/release-package.yaml
npm notice 67B README.md
npm notice 736B dist/AnalyzerEngine.js
npm notice 599B dist/AnalyzerEngine.js.map
npm notice 208B dist/Analyzers/BaseAnalyzer.js
npm notice 164B dist/Analyzers/BaseAnalyzer.js.map
npm notice 2.8kB dist/Analyzers/TypeScriptAnalyzer.js
npm notice 1.2kB dist/Analyzers/TypeScriptAnalyzer.js.map
npm notice 776B dist/index.js
npm notice 677B dist/index.js.map
npm notice 203B dist/Patterns/BasePattern.js
npm notice 161B dist/Patterns/BasePattern.js.map
npm notice 2.1kB dist/Patterns/CodeDuplicationPattern.js
npm notice 1.8kB dist/Patterns/CodeDuplicationPattern.js.map
npm notice 2.6kB dist/ProjectAnalyzer.js
npm notice 1.3kB dist/ProjectAnalyzer.js.map
npm notice 233B dist/Reports/Hint.js
npm notice 196B dist/Reports/Hint.js.map
npm notice 1.3kB dist/Reports/Report.js
npm notice 1.2kB dist/Reports/Report.js.map
npm notice 1.4kB dist/Utils/FileReader.js
npm notice 289B dist/Utils/FileReader.js.map
npm notice 1.6kB dist/Utils/ignorePatterns.js
npm notice 643B dist/Utils/ignorePatterns.js.map
npm notice 1.7kB dist/Utils/isIgnored.js
npm notice 618B dist/Utils/isIgnored.js.map
npm notice 143B docs/.nojekyll
npm notice 510B docs/assets/highlight.css
npm notice 15.5kB docs/assets/icons.js
npm notice 14.9kB docs/assets/icons.svg
npm notice 43.4kB docs/assets/main.js
npm notice 379B docs/assets/navigation.js
npm notice 1.2kB docs/assets/search.js
npm notice 36.5kB docs/assets/style.css
npm notice 10.6kB docs/classes/optimization_AnalysisStrategy.DuplicatedCodeAnalyzer.html
npm notice 10.5kB docs/classes/optimization_AnalysisStrategy.LongMethodAnalyzer.html
npm notice 12.4kB docs/classes/optimization_CodeAnalyzer.default.html
npm notice 12.3kB docs/classes/optimization_CompositeAnalyzer.default.html
npm notice 4.9kB docs/hierarchy.html
npm notice 3.8kB docs/index.html
npm notice 9.0kB docs/interfaces/optimization_AnalysisStrategy.AnalysisStrategy.html
npm notice 4.1kB docs/modules/index.html
npm notice 5.4kB docs/modules/optimization_AnalysisStrategy.html
npm notice 4.7kB docs/modules/optimization_CodeAnalyzer.html
npm notice 4.7kB docs/modules/optimization_CompositeAnalyzer.html
npm notice 290B jest.config.cjs
npm notice 1.2kB package.json
npm notice 683B src/AnalyzerEngine.ts
npm notice 173B src/Analyzers/BaseAnalyzer.ts
npm notice 2.2kB src/Analyzers/TypeScriptAnalyzer.ts
npm notice 597B src/index.ts
npm notice 372B src/Patterns/BasePattern.ts
npm notice 2.0kB src/Patterns/CodeDuplicationPattern.ts
npm notice 1.1kB src/Patterns/CodeSmellPattern.ts
npm notice 1.1kB src/Patterns/GodeObjectPattern.ts
npm notice 829B src/Patterns/GodObjectASTPattern.ts
npm notice 1.1kB src/Patterns/LargeClassPattern.ts
npm notice 819B src/Patterns/LazyClassPattern.ts
npm notice 717B src/Patterns/LongParameterListPattern.ts
npm notice 1.0kB src/Patterns/MagicNumbersPattern.ts
npm notice 601B src/Patterns/MiddleManPattern.ts
npm notice 881B src/Patterns/PrimitiveObsessionPattern.ts
npm notice 1.4kB src/Patterns/ShotgunSurgeryPattern.ts
npm notice 751B src/Patterns/SpeculativeGeneralityPattern.ts
npm notice 735B src/Patterns/SwitchStatementOverusePattern.ts
npm notice 1.4kB src/ProjectAnalyzer.ts
npm notice 62B src/Reports/Hint.ts
npm notice 1.2kB src/Reports/Report.ts
npm notice 155B src/Utils/FileReader.ts
npm notice 425B src/Utils/ignorePatterns.ts
npm notice 492B src/Utils/isIgnored.ts
npm notice 97B test-file.ts
npm notice 3.0kB tests/CodeDuplicationPattern.test.ts
npm notice 1.2kB tests/GodObjectPattern.test.ts
npm notice 1.1kB tests/MagicNumbersDetenctionPateern.test.ts
npm notice 1.8kB tests/ShotgunSurgeryPattern.test.ts
npm notice 1.6kB tests/TypeScriptAnalyzer.test.ts
npm notice 273B tsconfig.json
npm notice 215B typedoc.json
npm notice Tarball Details
npm notice name: code-diagnose
npm notice version: 1.1.1
npm notice filename: code-diagnose-1.1.1.tgz
npm notice package size: 46.6 kB
npm notice unpacked size: 253.1 kB
npm notice shasum: 4c82609720a8d541a88142b9f501957f12def87a
npm notice integrity: sha512-kj7tcxheJtTbu[...]2iKFYL4R9Y0Jg==
npm notice total files: 81
npm notice
npm error code ENEEDAUTH
npm error need auth This command requires you to be logged in to https://registry.npmjs.org/
npm error need auth You need to authorize this machine using `npm adduser`
npm error A complete log of this run can be found in: /home/runner/.npm/_logs/2024-08-23T18_00_02_564Z-debug-0.log
Error: Process completed with exit code 1.

here is the log for publish-gpr job:

npm notice 215B typedoc.json
npm notice Tarball Details
npm notice name: code-diagnose
npm notice version: 1.1.1
npm notice filename: code-diagnose-1.1.1.tgz
npm notice package size: 46.6 kB
npm notice unpacked size: 253.1 kB
npm notice shasum: 4c82609720a8d541a88142b9f501957f12def87a
npm notice integrity: sha512-kj7tcxheJtTbu[...]2iKFYL4R9Y0Jg==
npm notice total files: 81
npm notice
npm notice Publishing to https://npm.pkg.github.com/ with tag latest and default access
npm error code E404
npm error 404 Not Found - PUT https://npm.pkg.github.com/code-diagnose
npm error 404
npm error 404  '[email protected]' is not in this registry.
npm error 404
npm error 404 Note that you can also install from a
npm error 404 tarball, folder, http url, or git url.
npm error A complete log of this run can be found in: /home/runner/.npm/_logs/2024-08-23T18_00_03_336Z-debug-0.log

here is my release-package.yaml:

name: Release and Publish

on:
  release:
    types: [created]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Install dependencies
        run: npm install

      - name: Run tests
        run: npm test

  publish-npm:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Publish to npm
        run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

  publish-gpr:
    needs: build
    runs-on: ubuntu-latest
    permissions:
      packages: write
      contents: read
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20
          registry-url: https://npm.pkg.github.com/

      - name: Configure npm to use GitHub Packages registry
        run: npm config set registry https://npm.pkg.github.com/

      - name: Publish to GitHub Packages
        run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.GIT_TOKEN }}

I've added the GitHub and npm tokens to the repo as secret variables, unfortunately it did not help and the errors still appear.

1 Answer 1

0

In order to publish to npm registry you need to make two small changes to your step. Instead of setting environment variable NODE_AUTH_TOKEN, explicitly configure access token for registry.npmjs.org in .npmrc Make the package public, unless you have a payment plan with npm. The package name would be in the form @name/package, where name is any name you choose:

  - name: Publish to npm
    run: |
      echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
      npm publish --access public

In order to publish to GitHub packages, you simply need to use default GITHUB_TOKEN, provided by GitHub to your workflow. Your workflow already configured GITHUB_TOKEN for read/write permission for packages. The package name would be in the form @name/package, where name is your GitHub user name:

  - name: Publish to GitHub Packages
    run: npm publish
    env:
      NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Sign up to request clarification or add additional context in comments.

6 Comments

I have followed your suggestion related to publish-npm job. But actually don't want to modify the package name, is there any workaround for that ?
You should be able to keep your package name
Unfortunately I'm getting this error npm notice npm notice Publishing to https://registry.npmjs.org/ with tag latest and public access npm error code E404 npm error 404 Not Found - PUT https://registry.npmjs.org/code-diagnose - Not found npm error 404 npm error 404 '[email protected]' is not in this registry. npm error 404 npm error 404 Note that you can also install from a npm error 404 tarball, folder, http url, or git url.
This is unexpected if you are publishing a new version. The error says that '[email protected]' is not in this registry. However, I see this version npmjs.com/package/code-diagnose?activeTab=versions. How did you publish those versions? Did you use a different identity? Or different node version? Also, unlikely but perhaps there is an issue with specifying —access public for global namespace?
I've published it manually from terminal by using npm publish, also I suspect that it fails to publish via workflow because of 2FA, what do you think ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.