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を公開します。
参考
monorepoでPR中のコードをnpmパッケージとしてcanary releaseするGitHub Actions
lerna/commands/publish at main · lerna/lerna