Skip to content

Commit 5bb4ffb

Browse files
committed
fix: 修复切换默认分支导致的工作流异常问题
1 parent 1b2cb53 commit 5bb4ffb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

.github/workflows/auto-changelog.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ jobs:
4141
echo "base=$base_branch" >> $GITHUB_OUTPUT
4242
exit 0
4343
fi
44-
git checkout "$base_branch"
45-
if grep -q "^$version$" docs/change_log.md; then
44+
# Check remote file content without checkout to avoid ambiguity/detached HEAD issues
45+
if git show "origin/$base_branch:docs/change_log.md" | grep -q "^$version$"; then
4646
echo "Already present in changelog."; upd=false
4747
else
4848
upd=true
@@ -64,10 +64,15 @@ jobs:
6464
set -e
6565
git config user.name 'github-actions[bot]'
6666
git config user.email 'github-actions[bot]@users.noreply.github.com'
67-
branch=chore/changelog-${{ steps.detect.outputs.version }}
68-
git checkout -b "$branch"
67+
branch="chore/changelog-${{ steps.detect.outputs.version }}"
68+
base="${{ steps.detect.outputs.base }}"
69+
70+
# Create new branch from remote base
71+
git checkout -b "$branch" "origin/$base"
72+
6973
git add docs/change_log.md
7074
git commit -m "chore: add changelog for ${{ steps.detect.outputs.version }}"
75+
git push origin "$branch" --force
7176
7277
- name: Create Pull Request
7378
if: ${{ steps.detect.outputs.update == 'true' }}

0 commit comments

Comments
 (0)