@@ -140,19 +140,37 @@ jobs:
140140 env :
141141 GH_TOKEN : ${{ github.token }}
142142 run : |
143- tag="${{ needs.package.outputs.tag }}"
143+ current_tag="${{ needs.package.outputs.tag }}"
144+
145+ # Determine the base for the changelog: the version currently on the
146+ # target repo's main branch. This represents what was last merged, so
147+ # the changelog spans every release since then — correctly accumulating
148+ # unmerged versions if a prior sync PR is still open.
149+ #
150+ # Read the old SKILL.md from git (it's been overwritten on disk by the
151+ # sync step) via `git show origin/main:...`.
152+ target_version=$(git -C target-repo show "origin/main:${{ matrix.target_path }}/SKILL.md" 2>/dev/null \
153+ | grep '^version:' | sed 's/version:[[:space:]]*//' || echo "")
154+
155+ if [ -n "$target_version" ]; then
156+ base_tag="v${target_version}"
157+ else
158+ base_tag=""
159+ fi
144160
145- # Prefer the release body (auto-generated notes). Fall back to git log
146- # if no release exists for this tag (e.g. manual re-sync of an older version).
147- if body=$(gh release view "$tag" --repo "${{ github.repository }}" --json body --jq '.body' 2>/dev/null) && [ -n "$body" ]; then
148- echo "$body" > /tmp/changelog.md
161+ # Prefer GitHub's auto-generated notes for the range (nicely formatted
162+ # with PR links and contributors). Fall back to git log if unavailable.
163+ if [ -n "$base_tag" ] && notes=$(gh api \
164+ --method POST \
165+ "/repos/${{ github.repository }}/releases/generate-notes" \
166+ -f tag_name="${current_tag}" \
167+ -f previous_tag_name="${base_tag}" \
168+ --jq '.body' 2>/dev/null) && [ -n "$notes" ]; then
169+ echo "$notes" > /tmp/changelog.md
170+ elif [ -n "$base_tag" ]; then
171+ git log --oneline "${base_tag}..HEAD" > /tmp/changelog.md
149172 else
150- prev_tag=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
151- if [ -n "$prev_tag" ]; then
152- git log --oneline "${prev_tag}..HEAD" > /tmp/changelog.md
153- else
154- git log --oneline -20 > /tmp/changelog.md
155- fi
173+ git log --oneline -20 > /tmp/changelog.md
156174 fi
157175
158176 - name : Create or update PR
0 commit comments