【问题标题】:How to setup semantic-release without the need for npm?如何在不需要 npm 的情况下设置语义发布?
【发布时间】:2021-08-23 07:40:06
【问题描述】:

我有一个 C# 项目并想向它添加语义版本控制。因此,每当我推送到main 分支时,我都想创建一个新版本并根据提交类型自动生成一个新版本号。我认为semantic-release 做得很好,因为我已经在使用commitlinthusky

复制:

.

name: Release

on:
  push:
    branches:
      - `main`

jobs:
  release:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Setup Node
        uses: actions/setup-node@v2
        with:
          node-version: 14.x

      - name: Install dependencies
        run: npm install

      - name: Release
        env:
          GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE }}
        run: npx semantic-release
  • 推送后,工作流应该会失败并显示以下错误消息

[2:51:48 PM] [semantic-release] › ✔ 插件的完成步骤“失败” “@semantic-release/github” 一个 npm 令牌 (https://github.com/semantic-release/npm/blob/master/README.md#npm-registry-authentication) 必须在您的 NPM_TOKEN 环境变量中创建和设置 CI 环境。

请确保创建一个 npm 令牌 (https://docs.npmjs.com/getting-started/working_with_tokens#how-to-create-new-tokens) 并将其设置在 CI 的 NPM_TOKEN 环境变量中 环境。令牌必须允许发布到注册表 https://registry.npmjs.org/.

聚合错误: SemanticReleaseError:未指定 npm 令牌。 在 module.exports (/home/runner/.npm/_npx/1561/lib/node_modules/semantic-release/node_modules/@semantic-release/npm/lib/get-error.js:6:10) 在 module.exports (/home/runner/.npm/_npx/1561/lib/node_modules/semantic-release/node_modules/@semantic-release/npm/lib/set-npmrc-auth.js:45:31) 在 module.exports (/home/runner/.npm/_npx/1561/lib/node_modules/semantic-release/node_modules/@semantic-release/npm/lib/verify-auth.js:17:9) 在 verifyConditions (/home/runner/.npm/_npx/1561/lib/node_modules/semantic-release/node_modules/@semantic-release/npm/index.js:36:13) 在异步验证器(/home/runner/.npm/_npx/1561/lib/node_modules/semantic-release/lib/plugins/normalize.js:34:24) 在异步/home/runner/.npm/_npx/1561/lib/node_modules/semantic-release/lib/plugins/pipeline.js:37:34 在异步 Promise.all(索引 0) 在异步下一个(/home/runner/.npm/_npx/1561/lib/node_modules/semantic-release/node_modules/p-reduce/index.js:16:18) 在/home/runner/.npm/_npx/1561/lib/node_modules/semantic-release/lib/plugins/pipeline.js:54:11 在异步 Object.pluginsConf。 [作为 verifyConditions] (/home/runner/.npm/_npx/1561/lib/node_modules/semantic-release/lib/plugins/index.js:80:11) 在异步运行(/home/runner/.npm/_npx/1561/lib/node_modules/semantic-release/index.js:95:3) 在 async module.exports (/home/runner/.npm/_npx/1561/lib/node_modules/semantic-release/index.js:260:22) 在异步 module.exports (/home/runner/.npm/_npx/1561/lib/node_modules/semantic-release/cli.js:55:5) 错误:进程已完成,退出代码为 1。

我不想发布到 npm 注册表,它应该只是创建一个新的发布版本。

我是否遗漏了什么,或者为我的项目语义发布了错误的工具?

【问题讨论】:

标签: c# git npm semantic-versioning semantic-release


【解决方案1】:

您不必发布到 npm 注册表。您可以在.releaserc 中进行设置。

{
  "plugins": [
    ["@semantic-release/npm", {
      "npmPublish": false,
    }],
  ]
}

【讨论】:

    【解决方案2】:

    我意识到这是一个老问题,但也许有人会发现我的解决方案很有用。我改编自这篇博文by Sohrab Hosseini

    \\ .gitlab-ci.yml
    cut-version:
      image: node:16-alpine3.13
      stage: publish
        - npm i -g semantic-release @semantic-release/gitlab
      artifacts:
        reports:
          dotenv: vars.env
      script:
        - |-
          cat > .releaserc <<RELEASERC
          {
            "plugins": [
              "@semantic-release/commit-analyzer",
              "@semantic-release/release-notes-generator",
              "@semantic-release/gitlab",
              [
                "@semantic-release/exec", {
                  "successCmd": "echo \"VERSION=\${nextRelease.version}\" >> vars.env"
                }
              ]
            ]
          }
          RELEASERC
        - semantic-release
      only:
        - main
    
    publish-build:
      stage: publish
      needs:
        - job: cut-version
      script:
        - echo "$VERSION"
    

    【讨论】:

      【解决方案3】:

      我建议不要使用 hack 来实现您想要的用途,而是使用语义释放的替代方法 叫atomic-release。 它是一个用于创建原子发布的 SDK,可确保发布期间的失败回滚之前采取的任何操作。

      您可以create your own release strategy 和使用gitSemanticRelease

      免责声明:我是 atomic-release 的作者。

      【讨论】:

        猜你喜欢
        • 2018-10-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多