feat: 适配新版Karin #57
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PR | |
# 监听 PR 相关事件 | |
on: | |
pull_request: | |
# 监听 PR 被打开、重新打开和推送事件 | |
types: [opened, reopened, synchronize] | |
# 赋予 release-please-action 权限 | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
# 设置 release-please 任务 | |
release-please: | |
# 设置任务运行环境为 ubuntu-latest | |
runs-on: ubuntu-latest | |
steps: | |
- name: 检出代码 | |
uses: actions/checkout@v4 | |
# 设置 Node.js 环境 | |
- name: 设置 Node.js 环境 | |
uses: actions/setup-node@v4 | |
with: | |
# 设置 Node.js 版本 | |
node-version: 21 | |
# 设置 npm 源 | |
registry-url: "https://registry.npmjs.org" | |
# 安装依赖 不安装对等依赖 | |
- name: 安装依赖 | |
run: npm install --config.auto-install-peers=false --ignore-scripts --omit=peer | |
# 构建输出 | |
- name: 构建输出 | |
id: build | |
run: npm run build > build.log 2>&1 | |
continue-on-error: true # 捕获失败并允许后续步骤运行 | |
# 获取当前 PR 编号并设置环境变量 | |
- name: 获取 PR 编号 | |
run: echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV | |
# 自动修改 package.json 的版本号、删除开发、对等依赖 | |
- name: 修订版本号 | |
run: npm run pr all | |
if: success() | |
- name: 检查路径是否需要发布 | |
id: check-paths | |
run: | | |
if git diff --name-only HEAD^ | grep -v '^.github/'; then | |
echo "SHOULD_PUBLISH=true" >> $GITHUB_ENV | |
else | |
echo "SHOULD_PUBLISH=false" >> $GITHUB_ENV | |
fi | |
# 发布到 npm | |
- name: 发布到 npm | |
run: npm run pub-beta | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
if: env.SHOULD_PUBLISH == 'true' && success() | |
# 在 PR 上发布构建完成或失败信息 | |
- name: 发布评论 | |
run: | | |
if [ "${{ steps.build.outcome }}" = "failure" ]; then | |
# 捕获构建失败日志 | |
ERROR_MESSAGE=$(cat build.log || echo "未找到详细的构建日志。") | |
# 发布构建失败评论 | |
gh pr comment ${{ env.PR_NUMBER }} --body $'❌ 构建失败!以下是错误日志:\n\n<details>\n<summary>展开查看错误日志</summary>\n\n```\n'"${ERROR_MESSAGE}"$'\n```\n\n</details>' | |
else | |
# 构建成功评论 | |
INSTALL_COMMAND="pnpm install ${{ env.PKG_NAME }}@${{ env.PKG_VERSION }} -w" | |
gh pr comment ${{ env.PR_NUMBER }} --body $'🎉 构建完成!您可以通过以下命令安装此版本:\n\n```\n'"${INSTALL_COMMAND}"$'\n```' | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |