为了更流畅的CI体验,我已经制作了一个Github操作工作流来发布带有预发布版本的monorepo包,每次任何成员打开一个针对主版的PR时,都会使用特定的标签“发布”。理想情况下,该工作流应该发布自上次使用预the -pr{pr#}发布以来更改的所有包,例如Packe-pr1049.0。也在这里添加了dist标签和predist。
背景:在发布包之前,我还运行了一个MAKE可执行文件(make -j init脚本)来清理和引导所有包。发布后,它将获取回购,签出到所需的分支,并使用PR编号参数运行发布命令。
在这个工作流中,我面临两个问题:
第二次提交之后,只发布更改后的包,这是预期的结果。参考日志
lerna notice cli v3.20.2
lerna info versioning independent
lerna info ci enabled
lerna info Assuming all packages changed
lerna info getChangelogConfig Successfully resolved preset "conventional-changelog-angular"
Changes:
- @swiggy-private/package-1: 1.0.4 => 1.1.0-pr19000.0
- @swiggy-private/package-2: 1.1.4 => 1.2.0-pr19000.0
- @swiggy-private/package-3: 2.41.2 => 2.42.0-pr19000.0 (private)为了加快调试过程,lerna.json中的monorepo包仅限于3个包。
我的GH工作流
name: Branch Publish
on:
pull_request:
types: [opened, synchronize, reopened, labeled]
branches:
- master
jobs:
check:
runs-on: ubuntu-latest
timeout-minutes: 15
outputs:
author: ${{ steps.step1.outputs.author }}
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- id: "step1"
run: |
AUTHOR_NAME=$(git show ${{ github.event.pull_request.head.sha }} | grep Author)
echo "::set-output name=author::$AUTHOR_NAME"
init:
if: "!contains(needs.check.outputs.author, 'GitHub Action Branch') && !contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [check]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: "12.x"
- run: git fetch --prune --unshallow
- run: |
make -j init
env:
NPM_TOKEN: ${{ secrets.GH_TOKEN }}
- uses: actions/cache@v1
id: cache-build
with:
path: "."
key: ${{ github.sha }}
release:
if: "contains(github.event.pull_request.labels.*.name, 'publish')"
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [init]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: "0"
- uses: actions/setup-node@v1
with:
node-version: "12.x"
- uses: actions/cache@v1
id: restore-build
with:
path: "."
key: ${{ github.sha }}
- name: Setup Git
uses: webfactory/ssh-agent@v0.4.1
with:
ssh-private-key: ${{ secrets.GHA_DEPLOY_KEY }}
- name: Lerna Publish
if: success()
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
NODE_ENV: production
run: |
git config user.email "action@github.com"
git config user.name "GitHub Action Branch"
git remote set-url origin "git@github.com:${{ github.repository }}"
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
git checkout -- .
git log --pretty=oneline -n 10
git checkout --track origin/$(echo $GITHUB_HEAD_REF | cut -d'/' -f 3)
NUMBER=${{ github.event.number }} npm run publish-branch
- name: Possible Package lock update
if: success()
run: |
git config user.email "action@github.com"
git config user.name "GitHub Action Branch"
git remote set-url origin "git@github.com:${{ github.repository }}"
npx lerna clean -y
npx lerna exec -- npm i --package-lock-only --ignore-scripts --no-audit
echo `git add . && git commit -m "chore: package lock update" --no-verify && git push`发布命令
"publish-branch": "lerna publish --conventional-prerelease --exact --no-changelog --preid pr$NUMBER --dist-tag beta --pre-dist-tag beta --no-verify-access --yes"Lerna.json
{
"packages": ["*"],
"version": "independent",
"command": {
"publish": {
"npmClient": "npm",
"graphType": "all",
"allowBranch": ["master", "integration", "*"],
"conventionalCommits": true,
"message": "chore(release): publish",
"includeMergedTags": true,
"ignoreChanges": ["**/__tests__/**", "**/*.md"]
}
}
}编写脚本引导包
init: clean-all
$(MAKE) create-npmrc-all
npm ci
npm run bootstrap:ci
NODE_ENV=production npm run prepare:all
create-npmrc-all:
echo $(GITHUB_SCOPE_REGISTRY) >> .npmrc
echo $(GITHUB_REGISTRY_TOKEN) >> .npmrc
$(foreach source, $(DIRECTORY), $(call pass-to-npmrc, $(source), $(GITHUB_SCOPE_REGISTRY)))
$(foreach source, $(DIRECTORY), $(call pass-to-npmrc, $(source), $(GITHUB_REGISTRY_TOKEN)))
clean-all:
rm -rf node_modules
$(foreach source, $(SOURCES), \
$(call clean-source-all, $(source)))
rm -rf .npmrc
rm -rf packages/*/.npmrc
rm -rf coverage
rm -rf packages/*/npm-debug*发布于 2021-11-24 12:00:59
与从.npmrc文件创建脚本不同,您可以直接在管道中提供这些数据,这2行甚至可以与github预定义的令牌完美地工作。不太清楚你在使用什么环境,但我想你会明白的。
name: Setting Up NPM
run: |
npm set@organization:registry=https://npm.pkg.github.com/organization
npm set "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}"https://stackoverflow.com/questions/69875369
复制相似问题