LoginSignup
0
0

More than 1 year has passed since last update.

【Lerna】PR中のコードをGithub Packagesにcanary releaseする

Posted at

Lernaで管理しているmonorepoのパッケージをPR中でも実際のアプリケーションで動作確認したかったので、canary releaseできるようにGithub Actionsを作成したのでメモ。

name: Canary Release
on:
  issue_comment:
    types: [created]

jobs:
  canary-release:
    name: canary-release
    runs-on: ubuntu-latest
    if: |
      github.event_name == 'issue_comment' && startsWith(github.event.comment.body, '/canary-release')
    steps:
      - name: checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: '0'

      - name: setup Node
        uses: actions/setup-node@v3
        with:
          node-version: 16.x
          registry-url: 'https://npm.pkg.github.com'
          scope: '@<scope_package>'
        env:
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Cache dependencies
        uses: actions/cache@v3
        with:
          path: ./node_modules
          key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-node-

      - name: Install packages
        run: yarn install --frozen-lockfile

      - name: Publish
        run: yarn lerna publish --canary --preid next --dist-tag next --force-publish='*' --no-push --no-git-tag-version --yes --registry=https://npm.pkg.github.com
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - uses: actions/github-script@v6
        with:
          script: |
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: '🎉 Canary Release. You can install canary version via `npm install package@next`'
            })

PRに /canary-releaseとコメントするとcanary releaseを公開します。

スクリーンショット 2022-12-27 16.33.32.png

参考

monorepoでPR中のコードをnpmパッケージとしてcanary releaseするGitHub Actions
lerna/commands/publish at main · lerna/lerna

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0