在 GitHub 操作工作流程中使用 semantic-release-monorepo 找不到回购协议

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

我正在创建一个 GitHub 操作工作流来构建 npm 包并将其发布到 GitHub 包。 repo 是一个包含多个包的 monorepo,所以我使用的是 semantic-release-monorepo 工具。但是,发布步骤失败了,我不知道为什么。

我的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 运行一个脚本,该脚本执行 lerna 命令以进行语义释放

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

我已确保每个软件包的回购 package.json 和 package.json 都有正确的存储库 url、https://github.com/owner/repo.git。我的个人访问令牌具有回购以及写入和删除包的权限。

无论我更改什么配置,该步骤都会失败并显示以下消息:

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. 26 fatal: repository 'https://github.com/xxx/xxx.git/' not found.

第二条消息是

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

我尝试过的其他事情:

我查看了语义发布、语义发布-monorepo、GitHub 操作和 GitHub 包的文档。如果我需要包含任何其他信息,请告诉我。

经过反复试验,我找到了原因。如果我的理解是正确的,Github 工作流将自动使用可用的 GITHUB_TOKEN 密码在使用 actions/checkout 检出存储库的步骤中通过 Github 进行身份验证。然后它会保留此步骤中的凭据并将它们重新用于发布包的步骤,即使我将个人访问令牌作为环境变量注入该步骤。

最后,解决方法是像这样在第一步中使用 persist-credentials 选项

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

然后在最后一步使用个人访问令牌通过 GitHub 进行身份验证,就像我指出的那样,我相信这应该是我问题中的正确方法,因为语义发布文档声明仅支持 PAT 身份验证。