diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c4c9ce92b..80873d637 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,6 +42,7 @@ jobs: uses: actions/checkout@v5 with: ref: ${{ inputs.source_ref || inputs.release_tag || github.ref }} + fetch-depth: 0 - name: Set up Node.js uses: actions/setup-node@v5 @@ -111,10 +112,55 @@ jobs: sha256sum * > SHA256SUMS.txt ) + - name: Prepare release notes + shell: bash + run: | + set -euo pipefail + + notes_file="$RUNNER_TEMP/codex2api-release-notes.md" + homepage_readme="$RUNNER_TEMP/codex2api-homepage-readme.md" + homepage_readme_zh="$RUNNER_TEMP/codex2api-homepage-readme-zh.md" + version="$VERSION" + previous_tag="$(git tag --sort=-version:refname \ + | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \ + | grep -Fxv "$version" \ + | head -n 1 || true)" + + git show origin/main:README.md > "$homepage_readme" + git show origin/main:README.zh-CN.md > "$homepage_readme_zh" + + awk ' + /^## Custom maintenance$/ { in_section=1 } + in_section && /^## / && $0 != "## Custom maintenance" { exit } + in_section { print } + ' "$homepage_readme" > "$notes_file" + + printf '\n---\n\n' >> "$notes_file" + awk ' + /^## 自定义维护内容$/ { in_section=1 } + in_section && /^## / && $0 != "## 自定义维护内容" { exit } + in_section { print } + ' "$homepage_readme_zh" >> "$notes_file" + + printf '\n## Custom changes in this release\n\n' >> "$notes_file" + custom_commits="" + if [[ -n "$previous_tag" ]]; then + custom_commits="$(git log --first-parent --format='- %s' \ + "$previous_tag..$SOURCE_REF" -- \ + ':!CHANGELOG.md' ':!docs/**' ':!.github/**' \ + | grep -Ev '^- (Merge pull request|chore: sync upstream release|ci:)' || true)" + fi + if [[ -n "$custom_commits" ]]; then + printf '%s\n' "$custom_commits" >> "$notes_file" + else + printf '%s\n' '- No additional custom code changes were recorded for this release.' >> "$notes_file" + fi + - name: Create GitHub Release uses: softprops/action-gh-release@v2 with: tag_name: ${{ inputs.release_tag || github.ref_name }} + body_path: ${{ runner.temp }}/codex2api-release-notes.md generate_release_notes: true files: | dist/*.tar.gz