Files
LeonOS/.github/workflows/release-auto-commit.yml
Leonmmcoset 434b21c32a ci(workflows): 简化release-auto-commit.yml中的脚本逻辑
移除不必要的条件判断和格式处理,直接使用git log命令生成commit记录
2025-09-06 18:18:37 +08:00

45 lines
1.5 KiB
YAML

name: Auto Add Commits to Release Notes
on:
release:
types: [published]
jobs:
build-release-notes:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get previous release tag or first commit
id: prev_tag
run: |
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || git rev-list --max-parents=0 HEAD)
printf "prev_tag=%s\n" "$PREV_TAG" >> $GITHUB_OUTPUT
- name: Generate commit log
id: commit_log
run: |
COMMIT_LOG=$(git log ${{ steps.prev_tag.outputs.prev_tag }}..HEAD --pretty=format:"- [%h] %s" --reverse)
COMMIT_LOG="${COMMIT_LOG//$'\n'/\\n}"
echo "commit_log=$COMMIT_LOG" >> $GITHUB_OUTPUT
- name: Update release notes
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: release } = await github.rest.repos.getRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: context.payload.release.id
});
const newBody = `${release.body}\n\n## 本次更新 Commit 记录\n${{ steps.commit_log.outputs.commit_log }}`;
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: context.payload.release.id,
body: newBody
});