github - 如何设置 GitHub 操作以发布 Lerna Monorepo

标签 github lerna github-actions

我维护一个 lerna/yarn monorepo。我正在将 CI/CD 从 circle 迁移到新的 GitHuba Actions 发布测试版。我创建了以下工作流程:

name: CD

on:
  push:
    branches:
      - master

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@master

      - name: Checkout master
        run: git checkout master

      - name: Install rsync
        run: sudo apt install rsync

      - name: Install yarn
        run: |
          curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
          echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
          sudo apt-get update
          sudo apt-get install yarn

      - name: Install Packages
        run: yarn install

      - name: Test
        run: yarn test

      - name: Upload coverage results to Code Climate
        run: sh ./scripts/upload-coverage.sh
        env:
          CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}

      - name: Authenticate with Registry
        run: echo "registry=//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
        env:
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

      - name: Configure CI Git User
        run: |
          git config --global user.email octobot@github.com
          git config --global user.name GitHub Actions

      - name: Publish package
        run: yarn deploy --yes
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Build Docs
        run: yarn docs

      - name: Deploy Docs
        run: |
          echo "apolloelements.dev" > docs/CNAME
          npx gh-pages --dist docs

它在 Publish Packages 步骤失败并显示以下消息:
lerna info git Pushing tags...
lerna ERR! Error: Command failed: git push --follow-tags --no-verify origin master
lerna ERR! fatal: could not read Username for 'https://github.com': No such device or address
lerna ERR! 
lerna ERR!     at makeError (/home/runner/work/apollo-elements/apollo-elements/node_modules/execa/index.js:174:9)
lerna ERR!     at Promise.all.then.arr (/home/runner/work/apollo-elements/apollo-elements/node_modules/execa/index.js:278:16)
lerna ERR! Error: Command failed: git push --follow-tags --no-verify origin master
lerna ERR! fatal: could not read Username for 'https://github.com': No such device or address
lerna ERR! 
lerna ERR!     at makeError (/home/runner/work/apollo-elements/apollo-elements/node_modules/execa/index.js:174:9)
lerna ERR!     at Promise.all.then.arr (/home/runner/work/apollo-elements/apollo-elements/node_modules/execa/index.js:278:16)
lerna ERR! lerna Command failed: git push --follow-tags --no-verify origin master
lerna ERR! lerna fatal: could not read Username for 'https://github.com': No such device or address
lerna ERR! lerna 
error Command failed with exit code 128.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

将 Remote 更改为使用 HTTPS 并且 github token 没有帮助:
git remote rm origin
git remote add origin "https://$USER_NAME:$GITHUB_PERSONAL_ACCESS_TOKEN@github.com/apollo-elements/apollo-elements.git"

在哪里 GITHUB_PERSONAL_ACCESS_TOKEN是通过 secret 传递的 PAT。

在这种情况下,我收到了这个错误:
lerna ERR! ENOREMOTEBRANCH Branch 'master' doesn't exist in remote 'origin'.

我应该如何设置项目以便能够将标签和提交从 CD 推送回存储库?

最佳答案

现在可以通过使用 checkout@v2 来使用更简单的配置。和 setup-node@v2

jobs:
  build:

    runs-on: ubuntu-latest
    env:
      NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
    steps:

    # 1. provide Personal Access Token for checkout@v2
    - name: Checkout
      uses: actions/checkout@v2
      with:
          submodules: recursive
          token: ${{ secrets.PUBLISH_PAT }}

    # 2. setup .npmrc it uses NODE_AUTH_TOKEN
    - name: Setup .npmrc file for publish
      uses: actions/setup-node@v2
      with:
        node-version: '12.x'
        registry-url: 'https://registry.npmjs.org'

    # 3. configure git user used to push tag
    - name: Configure Git User
      run: |
        git config --global user.email "ci@your-site.com"
        git config --global user.name "ci@$GITHUB_ACTOR"

    - name: Install dependencies
      run: yarn install

    - name: Publish
      run: |
        lerna publish --yes
设置 repository secret与以下:NPM_TOKEN是带有 publish 的 NPM token 许可,more infoPUBLISH_PAT是带有 repo 的 github 个人访问 token 许可,more info

关于github - 如何设置 GitHub 操作以发布 Lerna Monorepo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57597367/

相关文章:

github - 提交后将问题与提交联系起来

reactjs - 如何在使用 Next.js 完成的外部项目中使用 Storybook 组件(和 Lerna)?

GitHub 操作 : how to target all branches EXCEPT master?

java - GitHub Actions : "Could not find a valid Docker environment. Please see logs and check configuration" 上 Windows 环境中的测试容器

django - Azure 上 Django 的 GitHub : Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'

github - Github 中的 CODEOWNERS 没有按预期工作

Git 从 TeamCity 9.0.3 构建推送

git - "git remote -v"显示 (fetch) 和 (push) 两次,一次用于 'github',一次用于 'origin' 这意味着什么?

node.js - 在 Windows 上运行 lerna bootstrap -- hoist 命令时出现操作不允许错误 npm

node.js - Bazel 与 lerna 和 yarn 工作区一起使用