mirror of
https://github.com/CCLeonOS/LeonOS.git
synced 2026-03-03 15:17:01 +00:00
Update release-auto-commit.yml
This commit is contained in:
26
.github/workflows/release-auto-commit.yml
vendored
26
.github/workflows/release-auto-commit.yml
vendored
@@ -1,55 +1,49 @@
|
|||||||
name: Auto Add Commits to Release Notes
|
name: Auto Add Commits to Release Notes
|
||||||
|
|
||||||
# 触发条件:当手动创建 Release 时运行
|
|
||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
types: [published] # 仅在 Release 正式发布时执行(也可改为 drafted 测试草稿)
|
types: [published]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-release-notes:
|
build-release-notes:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
# 1. 拉取当前仓库代码(需获取完整 Git 历史)
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # 必须设置为 0,否则无法获取完整 Commit 历史
|
fetch-depth: 0
|
||||||
|
|
||||||
# 2. 获取上一个 Release 标签(用于确定 Commit 范围)
|
|
||||||
- name: Get previous release tag
|
- name: Get previous release tag
|
||||||
id: prev_tag
|
id: prev_tag
|
||||||
run: |
|
run: |
|
||||||
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || git rev-list --max-parents=0 HEAD)
|
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null)
|
||||||
echo "prev_tag=${PREV_TAG}" >> $GITHUB_OUTPUT
|
if [ -z "$PREV_TAG" ]; then
|
||||||
|
PREV_TAG="initial-commit"
|
||||||
|
fi
|
||||||
|
echo "prev_tag=${PREV_TAG//$'\n'/}" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
# 3. 生成当前 Release 与上一个版本间的 Commit 记录(格式:哈希 + 标题)
|
|
||||||
- name: Generate commit log
|
- name: Generate commit log
|
||||||
id: commit_log
|
id: commit_log
|
||||||
run: |
|
run: |
|
||||||
# 区分首次 Release 和历史 Release 的 Commit 范围
|
|
||||||
if [ "${{ steps.prev_tag.outputs.prev_tag }}" = "initial-commit" ]; then
|
if [ "${{ steps.prev_tag.outputs.prev_tag }}" = "initial-commit" ]; then
|
||||||
COMMIT_LOG=$(git log --pretty=format:"- [%h] %s" --reverse)
|
COMMIT_LOG=$(git log --pretty=format:"- [%h] %s" --reverse)
|
||||||
else
|
else
|
||||||
COMMIT_LOG=$(git log ${{ steps.prev_tag.outputs.prev_tag }}..HEAD --pretty=format:"- [%h] %s" --reverse)
|
COMMIT_LOG=$(git log ${{ steps.prev_tag.outputs.prev_tag }}..HEAD --pretty=format:"- [%h] %s" --reverse)
|
||||||
fi
|
fi
|
||||||
# 处理特殊字符(避免 YAML 解析错误)
|
|
||||||
COMMIT_LOG="${COMMIT_LOG//$'\n'/\\n}"
|
COMMIT_LOG="${COMMIT_LOG//$'\n'/\\n}"
|
||||||
echo "commit_log=$COMMIT_LOG" >> $GITHUB_OUTPUT
|
echo "commit_log=$COMMIT_LOG" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
# 4. 更新 Release 说明(将 Commit 记录追加到原说明后)
|
|
||||||
- name: Update release notes
|
- name: Update release notes
|
||||||
uses: actions/github-script@v7
|
uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }} # 自动生成的 Token,无需手动配置
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
script: |
|
script: |
|
||||||
const { data: release } = await github.rest.repos.getRelease({
|
const { data: release } = await github.rest.repos.getRelease({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
release_id: context.payload.release.id
|
release_id: context.payload.release.id
|
||||||
});
|
});
|
||||||
// 原 Release 说明 + 新 Commit 记录
|
const newBody = `${release.body || ''}\n\n## 本次更新 Commit 记录\n${{ steps.commit_log.outputs.commit_log }}`;
|
||||||
const newBody = `${release.body}\n\n## 本次更新 Commit 记录\n${{ steps.commit_log.outputs.commit_log }}`;
|
|
||||||
// 覆盖 Release 说明
|
|
||||||
await github.rest.repos.updateRelease({
|
await github.rest.repos.updateRelease({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
|
|||||||
Reference in New Issue
Block a user