1+ name : Update RELEASENOTES.md
2+
3+ on :
4+ pull_request :
5+ types : [closed]
6+ branches : [main]
7+
8+ permissions :
9+ contents : write
10+
11+ jobs :
12+ update-releasenotes :
13+ if : >-
14+ github.event.pull_request.merged == true &&
15+ !contains(github.event.pull_request.labels.*.name, 'skip-changelog')
16+ runs-on : ubuntu-latest
17+ steps :
18+ - uses : actions/checkout@v4
19+ with :
20+ ref : main
21+ fetch-depth : 0
22+
23+ - name : Get current version
24+ id : version
25+ shell : bash
26+ run : |
27+ FILE="RELEASENOTES.md"
28+ LATEST=$(grep -oP '(?<=^# NuGet Version )\d+\.\d+\.\d+' "$FILE" | head -1)
29+ if [ -z "$LATEST" ]; then
30+ echo "::error::Could not find any version heading in RELEASENOTES.md"
31+ exit 1
32+ fi
33+ echo "latest=$LATEST" >> "$GITHUB_OUTPUT"
34+ echo "Detected latest version: $LATEST"
35+
36+ - name : Determine category from labels
37+ id : category
38+ shell : bash
39+ run : |
40+ LABELS='${{ toJson(github.event.pull_request.labels.*.name) }}'
41+ if echo "$LABELS" | grep -qiE '"breaking-change"'; then
42+ echo "section=__Breaking Changes__" >> "$GITHUB_OUTPUT"
43+ elif echo "$LABELS" | grep -qiE '"bug"|"fix"'; then
44+ echo "section=__Bug Fixes__" >> "$GITHUB_OUTPUT"
45+ elif echo "$LABELS" | grep -qiE '"enhancement"|"api-change"|"Missing Feature"'; then
46+ echo "section=__API Changes__" >> "$GITHUB_OUTPUT"
47+ elif echo "$LABELS" | grep -qiE '"build"|"ci"|"infra"'; then
48+ echo "section=__Build/Infrastructure__" >> "$GITHUB_OUTPUT"
49+ elif echo "$LABELS" | grep -qiE '"issue-fixed"'; then
50+ echo "section=__Issues Fixed__" >> "$GITHUB_OUTPUT"
51+ else
52+ echo "section=__Other Changes__" >> "$GITHUB_OUTPUT"
53+ fi
54+
55+ - name : Update RELEASENOTES.md
56+ shell : bash
57+ env :
58+ PR_NUMBER : ${{ github.event.pull_request.number }}
59+ PR_TITLE : ${{ github.event.pull_request.title }}
60+ SECTION : ${{ steps.category.outputs.section }}
61+ CURRENT_VERSION : ${{ steps.version.outputs.latest }}
62+ run : |
63+ FILE="RELEASENOTES.md"
64+ VERSION_HEADER="# NuGet Version ${CURRENT_VERSION}"
65+
66+ python3 - <<'PYEOF'
67+ import os, sys
68+
69+ file_path = os.environ['FILE']
70+ ver_header = os.environ['VERSION_HEADER']
71+ section = os.environ['SECTION']
72+ pr_number = os.environ['PR_NUMBER']
73+ pr_title = os.environ['PR_TITLE']
74+ entry = f"#{pr_number} {pr_title}<br/>"
75+
76+ with open(file_path, 'r') as f :
77+ content = f.read()
78+ lines = content.splitlines(keepends=True)
79+
80+ # Find the version block and insert the entry
81+ result = []
82+ in_version_block = False
83+ section_found = False
84+ inserted = False
85+
86+ for i, line in enumerate(lines) :
87+ stripped = line.rstrip('\n')
88+
89+ if stripped == ver_header :
90+ in_version_block = True
91+ result.append(line)
92+ continue
93+
94+ if in_version_block and stripped.startswith('# NuGet Version ') and stripped != ver_header:
95+ # Reached next version block without finding/creating section
96+ if not inserted :
97+ result.append('\n' + section + ':\n\n' + entry + '\n\n')
98+ inserted = True
99+ in_version_block = False
100+ result.append(line)
101+ continue
102+
103+ if in_version_block and not inserted and stripped == section + ':' :
104+ section_found = True
105+ result.append(line)
106+ continue
107+
108+ if section_found and not inserted :
109+ # Insert after the blank line following the section heading
110+ if stripped == '' :
111+ result.append(line)
112+ result.append(entry + '\n')
113+ inserted = True
114+ continue
115+
116+ result.append(line)
117+
118+ # If we reached EOF still inside the version block
119+ if in_version_block and not inserted :
120+ result.append('\n' + section + ':\n\n' + entry + '\n')
121+
122+ with open(file_path, 'w') as f :
123+ f.writelines(result)
124+ PYEOF
125+
126+ - name : Commit and push
127+ shell : bash
128+ run : |
129+ git config user.name "github-actions[bot]"
130+ git config user.email "github-actions[bot]@users.noreply.github.com"
131+ git add RELEASENOTES.md
132+ if git diff --cached --quiet; then
133+ echo "No changes to commit"
134+ else
135+ git commit -m "docs: add PR #${{ github.event.pull_request.number }} to RELEASENOTES.md [skip ci]"
136+ git push
137+ fi
0 commit comments