mirror of
https://github.com/CCLeonOS/LeonOS.git
synced 2026-03-03 06:47:00 +00:00
53 lines
1.9 KiB
YAML
53 lines
1.9 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
|
||
id: prev_tag
|
||
run: |
|
||
# 获取上一个标签或初始commit
|
||
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || git rev-list --max-parents=0 HEAD)
|
||
|
||
# 按照建议:清理值中的换行和回车符,使用printf确保格式正确
|
||
printf "prev_tag=%s\n" "$(echo "$PREV_TAG" | tr -d '\n' | tr -d '\r')" >> "$GITHUB_OUTPUT"
|
||
|
||
- name: Generate commit log
|
||
id: commit_log
|
||
run: |
|
||
if [ "${{ steps.prev_tag.outputs.prev_tag }}" = "initial-commit" ]; then
|
||
COMMIT_LOG=$(git log --pretty=format:"- [%h] %s" --reverse)
|
||
else
|
||
COMMIT_LOG=$(git log ${{ steps.prev_tag.outputs.prev_tag }}..HEAD --pretty=format:"- [%h] %s" --reverse)
|
||
fi
|
||
COMMIT_LOG="${COMMIT_LOG//$'\n'/\\n}"
|
||
printf "commit_log=%s\n" "$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
|
||
});
|