【问题标题】:Git Error While Publishing Lerna Monorepo to NPM via GitHub Actions通过 GitHub Actions 将 Lerna Monorepo 发布到 NPM 时出现 Git 错误
【发布时间】:2023-03-18 20:53:02
【问题描述】:

我使用以下 GitHub Actions(新的 YAML 版本)工作流从我的 lernamonorepo 发布包以推送到 master

name: CD

on:
  push:
    branches:
      - master

jobs:

  deployPackages:
    name: Deploy Packages
    runs-on: ubuntu-latest
    steps:

      - uses: actions/checkout@master

      - name: Checkout master
        run: git checkout master

      - name: Install
        uses: nuxt/actions-yarn@master
        with:
          args: install

      - name: Build
        uses: nuxt/actions-yarn@master
        with:
          args: build

      - name: Lint
        uses: nuxt/actions-yarn@master
        with:
          args: lint

      - name: Test
        uses: ianwalter/puppeteer@v1.0.0
        env:
          CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
        with:
          entrypoint: yarn
          args: test:ci

      - name: Deploy Packages
        uses: nuxt/actions-yarn@master
        env:
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
          DEPLOYING_USER_NAME: ${{ secrets.DEPLOYING_USER_NAME }}
          GH_PAT: ${{ secrets.GH_PAT }}
        with:
          args: deploy:ci

      - name: Build Docs
        uses: nuxt/actions-yarn@master
        with:
          args: docs

      - name: Deploy Docs
        uses: maxheld83/ghpages@v0.2.1
        env:
          BUILD_DIR: _site/
          GH_PAT: ${{ secrets.GH_PAT }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

deploy:ci npm 脚本执行以下 bash 脚本:

echo "Authenticating with Registry..."
npm config set registry //registry.npmjs.org/:_authToken=$NPM_TOKEN -q

echo "Adding Git Remote..."
git remote rm origin
git remote add origin "https://$DEPLOYING_USER_NAME:$GH_PAT@github.com/SCOPE/REPO_NAME.git"
git fetch
git tag -d master

echo "Configuring CI Git User..."
git config --global user.email octobot@github.com
git config --global user.name GitHub Actions

echo "Publishing Packages..."
npx lerna publish \
  --message "chore: release new versions" \
  --yes

这会导致以下错误:

lerna info execute Skipping releases
lerna info git Pushing tags...
lerna ERR! Error: Command failed: git push --follow-tags --no-verify origin master
lerna ERR! error: src refspec refs/heads/master matches more than one.
lerna ERR! fatal: The remote end hung up unexpectedly
lerna ERR! error: failed to push some refs to 'https://***:***@github.com/SCOPE/REPO_NAME.git'
lerna ERR! 
lerna ERR!     at makeError (/github/workspace/node_modules/execa/index.js:174:9)
lerna ERR!     at Promise.all.then.arr (/github/workspace/node_modules/execa/index.js:278:16)

是什么导致了上述错误?

【问题讨论】:

    标签: git github npm lerna github-actions


    【解决方案1】:

    您看到的错误“src refspec refs/heads/master 匹配多个”意味着您尝试推送的内容匹配多个修订版。如果给定的 refspec 是 master,那么可能的情况是您同时拥有一个分支和一个名为 master 的标签,而 Git 不知道您要推送哪个。

    在这种情况下,您可能有一个名为master 的分支和标签,或者您有一个refs/heads/mastermaster 分支)和一个refs/heads/refs/heads/master(即refs/heads/master 分支) ) 或refs/tags/refs/heads/master(即refs/heads/master 标记),Git 开始感到困惑。

    您似乎正试图删除脚本中的 master 标记,这可能是您的问题的根源。您可能希望修复导致创建该标签的任何原因,以便您不再遇到此问题。但是,如果没有看到您的 repo,很难确切地知道原因是什么。

    【讨论】:

    • git tag -l | grep master 没有输出,所以我没有master 标签。 git tag -d master 行是避免此错误的幼稚尝试,可以忽略。本质上,为了将标签推送到 repo(lerna 工作流程的一部分),我需要重新建立远程,根据stackoverflow.com/posts/comments/101743224?noredirect=1
    猜你喜欢
    • 2021-11-24
    • 2022-06-22
    • 2022-01-20
    • 2019-12-27
    • 2021-12-24
    • 1970-01-01
    • 1970-01-01
    • 2018-08-10
    • 2020-09-25
    相关资源
    最近更新 更多