简体   繁体   English

在 GitHub 操作工作流程中未使用语义发布-monorepo 找到存储库

[英]Repo not found using semantic-release-monorepo in GitHub Actions workflow

I am creating a GitHub Actions workflow to build and publish npm packages to GitHub Packages.我正在创建 GitHub 操作工作流来构建 npm 包并将其发布到 GitHub 包。 The repo is a monorepo with several packages, so I am using the semantic-release-monorepo tool. repo 是一个带有多个包的 monorepo,所以我使用了 semantic-release-monorepo 工具。 However, the step to publish is failing and I can't figure out why.但是,发布步骤失败了,我不知道为什么。

My GitHub Actions workflow file is as follows (trimmed down slightly)我的 GitHub Actions 工作流文件如下(略减)

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    env:
      GH_TOKEN: ${{ secrets.MY_PAT }}

    steps:
      - name: Checkout repo
        uses: actions/checkout@v2

        run: |
          yarn install
          yarn build

      - name: Setup node for publishing to Github packages
        uses: actions/setup-node@v2
        env:
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          node-version: "12.x"
          registry-url: "https://npm.pkg.github.com"

      - name: Yarn publish packages
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 
        run: |
          yarn publish-packages

yarn publish-packages runs a script which executes the lerna command for semantic release yarn publish-packages运行一个脚本,该脚本执行 lerna 命令以进行语义发布

lerna exec --concurrency 1 -- npx --no-install semantic-release -e semantic-release-monorepo

I have made sure the repo package.json as well as the package.json for every package has the correct repository url, https://github.com/owner/repo.git . I have made sure the repo package.json as well as the package.json for every package has the correct repository url, https://github.com/owner/repo.git . My personal access token has permissions to repo and write and delete packages.我的个人访问令牌有权回购、写入和删除包。

No matter what configs I change, the step fails with the following messages:无论我更改什么配置,该步骤都会失败并显示以下消息:

The command "git push --dry-run --no-verify https://[secure]@github.com/xxx/xxx.git HEAD:develop" failed with the error message remote: Repository not found.命令“git push --dry-run --no-verify https://[secure]@github.com/xxx/xxx.git HEAD:develop”失败,并显示错误消息 remote: Repository not found。 26 fatal: repository 'https://github.com/xxx/xxx.git/' not found. 26 致命:未找到存储库“https://github.com/xxx/xxx.git/”。

The second message is第二条消息是

EGITNOPERMISSION: ' semantic-release cannot push the version tag to the branch develop on the remote Git repository with URL https://[secure]@github.com/xxx/xxx.git EGITNOPERMISSION: ' semantic-release cannot push the version tag to the branch develop on the remote Git repository with URL https://[secure]@github.com/xxx/xxx.git

Other things I have tried:我尝试过的其他事情:

  • Adding scope="@xxx" to the setup-node step after reading GH docs that says "GitHub Packages only supports scoped npm packages"在阅读GH 文档“GitHub Packages only support scoped npm packages”后,将 scope="@xxx" 添加到 setup-node 步骤
  • According to semantic-release docs , I have tried setting GH_TOKEN, GITHUB_TOKEN and NPM_TOKEN to every combination of my PAT or the GITHUB_TOKEN in secrets.根据语义发布文档,我尝试将 GH_TOKEN、GITHUB_TOKEN 和 NPM_TOKEN 设置为我的 PAT 或秘密中的 GITHUB_TOKEN 的每个组合。 I believe the docs say only PAT is supported.我相信文档说只支持 PAT。 Also, NPM_TOKEN should not be required because using registry-url with the setup-node action creates an.npmrc file that uses NODE_AUTH_TOKEN by default.此外,不应该需要 NPM_TOKEN,因为在 setup-node 操作中使用 registry-url 会创建一个默认使用NODE_AUTH_TOKEN的 .npmrc 文件。
  • There is an almost similar questionhere but adding .git to his repository url seems to have fixed it for him这里有一个几乎类似的问题但是将.git添加到他的存储库 url 似乎已经为他解决了
  • Github docs say that I should be able to use a PAT or the GITHUB_TOKEN as the auth token in the.npmrc file, so that shouldn't be the issue Github 文档说我应该能够使用 PAT 或 GITHUB_TOKEN 作为 .npmrc 文件中的身份验证令牌,所以这不应该是问题

I've looked through the docs for semantic-release, semantic-release-monorepo, GitHub Actions, and GitHub Packages.我查看了语义发布、语义发布-monorepo、GitHub 操作和 GitHub 包的文档。 If there is any additional information I need to include please let me know.如果我需要包含任何其他信息,请告诉我。

After some more trial and error, I discovered the cause.经过更多的尝试和错误,我发现了原因。 If my understanding is correct, a Github workflow will automatically use the available GITHUB_TOKEN secret to authenticate with Github during the step to checkout the repo using actions/checkout .如果我的理解是正确的,那么 Github 工作流程将在使用actions/checkout签出 repo 的步骤中自动使用可用的 GITHUB_TOKEN 密码向 Github 进行身份验证。 It was then persisting the credentials from this step and reusing them for the step to publish packages, even though I was injecting a personal access token as an environment variable to that step.然后,它保留了此步骤中的凭据并将其重新用于发布包的步骤,即使我将个人访问令牌作为环境变量注入该步骤。

In the end, the fix was to use the persist-credentials option in step one like this最后,解决方法是在第一步中使用persist-credentials选项,如下所示

steps:
  - name: Checkout repo
    uses: actions/checkout@v2
    with:
      persist-credentials: false

And then using the personal access token to authenticate with GitHub in the last step like I noted I believed should be the correct method in my question, as semantic-release docs state only PAT authentication is supported.然后使用个人访问令牌在最后一步使用 GitHub 进行身份验证,就像我指出的那样,我认为这应该是我的问题中的正确方法,因为语义发布文档 state 仅支持 PAT 身份验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM