无法通过GitHub Actions发布包至npm与GitHub Packages的问题
GitHub Actions发布npm与GitHub Packages失败排查
核心错误
- npm发布失败:提示需要登录到
https://registry.npmjs.org/,错误码ENEEDAUTH - GitHub Packages发布失败:返回404 Not Found,提示包不在注册表中
publish-npm任务完整日志
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 📦 code-diagnose@1.1.1 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.
publish-gpr任务完整日志
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 'code-diagnose@1.1.1' 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
配置文件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 }}
补充说明
已在仓库中添加GitHub和npm令牌作为秘密变量,但错误依旧出现。
内容的提问来源于stack exchange,提问作者Suren Poghosyan
相关产品推荐
相关产品推荐

