From dd00d1f47c582d9a5ce301937b80cea299d5fa7f Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Sat, 6 Sep 2025 18:19:59 +0800 Subject: [PATCH] =?UTF-8?q?ci(workflow):=20=E4=BC=98=E5=8C=96=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=9B=B4=E6=96=B0=E5=8F=91=E5=B8=83=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E7=9A=84=20GitHub=20Actions=20=E5=B7=A5=E4=BD=9C=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重命名工作流名称以更简洁 - 添加 workflow_dispatch 触发器以支持手动触发 - 简化获取上一个标签的逻辑 - 使用 action-gh-release 替代 github-script 来更新发布日志 - 改进提交记录格式,包含作者信息 --- .github/workflows/release-auto-commit.yml | 47 ++++++++++------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/.github/workflows/release-auto-commit.yml b/.github/workflows/release-auto-commit.yml index 915e520..594bc10 100644 --- a/.github/workflows/release-auto-commit.yml +++ b/.github/workflows/release-auto-commit.yml @@ -1,6 +1,7 @@ -name: Auto Add Commits to Release Notes +name: Release on: + workflow_dispatch: release: types: [published] @@ -10,36 +11,28 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Get previous release tag or first commit + - name: Get previous tag 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 + PREV_TAG=$(git describe --tags --abbrev=0 $(git rev-list --tags --skip=1 --max-count=1)) + echo "PREV_TAG=$PREV_TAG" >> $GITHUB_ENV - - name: Generate commit log - id: commit_log + - name: Get commits between tags + id: changelog 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 + git fetch --tags + COMMITS=$(git log $PREV_TAG..${{ github.event.release.tag_name }} --pretty=format:"- %s (%an)") + echo "$COMMITS" > commits.txt + echo "COMMITS<> $GITHUB_ENV + cat commits.txt >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV - - name: Update release notes - uses: actions/github-script@v7 + - name: Update Release Notes + uses: softprops/action-gh-release@v2 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 - }); \ No newline at end of file + tag_name: ${{ github.event.release.tag_name }} + body: | + ${{ env.COMMITS }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file