Skip to content

Commit db19392

Browse files
committed
Update maven-publish.yml
1 parent aebec3f commit db19392

File tree

1 file changed

+84
-5
lines changed

1 file changed

+84
-5
lines changed

.github/workflows/maven-publish.yml

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ on:
2121
jobs:
2222
build:
2323
runs-on: ubuntu-latest
24+
permissions:
25+
contents: read
2426
if: ${{ inputs.revision }}
2527
steps:
2628
- name: Validate version format
2729
run: |
2830
if ! echo "${{ inputs.revision }}" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
29-
echo "Error: version '${{ inputs.revision }}' does not match the required pattern major.minor.patch"
30-
exit 1
31+
echo "Error: version '${{ inputs.revision }}' does not match the required pattern major.minor.patch"
32+
exit 1
3133
fi
3234
3335
- name: Checkout Source
@@ -64,6 +66,7 @@ jobs:
6466
needs: build
6567
permissions:
6668
contents: write
69+
models: read
6770
steps:
6871
- name: Checkout Source
6972
uses: actions/checkout@v5
@@ -81,14 +84,90 @@ jobs:
8184
git push origin ${{ inputs.revision }}
8285
fi
8386
87+
- name: Generate Release Notes with Copilot
88+
env:
89+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90+
run: |
91+
CURRENT_TAG="${{ inputs.revision }}"
92+
93+
# Find the previous tag (the one before the current tag)
94+
PREV_TAG=$(git describe --tags --abbrev=0 --exclude="${CURRENT_TAG}" HEAD 2>/dev/null || echo "")
95+
96+
# Collect commits between the previous tag and HEAD
97+
if [ -n "$PREV_TAG" ]; then
98+
COMMITS=$(git log --oneline "${PREV_TAG}..HEAD" 2>/dev/null || echo "No commits found")
99+
SINCE_LABEL="$PREV_TAG"
100+
else
101+
COMMITS=$(git log --oneline -50 2>/dev/null || echo "No commits found")
102+
SINCE_LABEL="the beginning"
103+
fi
104+
105+
# Export for Python (avoids shell-escaping issues with multiline content)
106+
export CURRENT_TAG_DATA="$CURRENT_TAG"
107+
export PREV_TAG_DATA="$SINCE_LABEL"
108+
export COMMITS_DATA="$COMMITS"
109+
110+
# Call GitHub Copilot via GitHub Models API and capture the summary
111+
SUMMARY=$(python3 << 'PYEOF'
112+
import json, os, urllib.request, sys
113+
114+
current_tag = os.environ['CURRENT_TAG_DATA']
115+
prev_tag = os.environ['PREV_TAG_DATA']
116+
commits = os.environ['COMMITS_DATA']
117+
token = os.environ['GH_TOKEN']
118+
119+
prompt = (
120+
f"Generate concise release notes for version {current_tag}.\n\n"
121+
f"Commits since {prev_tag}:\n{commits}\n\n"
122+
"Format the output as markdown with sections for New Features, Bug Fixes, "
123+
"and Other Changes (only include sections that have relevant commits). "
124+
"Be concise and clear."
125+
)
126+
127+
payload = json.dumps({
128+
"model": "gpt-4o",
129+
"messages": [{"role": "user", "content": prompt}]
130+
}).encode()
131+
132+
req = urllib.request.Request(
133+
"https://models.inference.ai.azure.com/chat/completions",
134+
data=payload,
135+
headers={
136+
"Content-Type": "application/json",
137+
"Authorization": f"Bearer {token}"
138+
}
139+
)
140+
141+
try:
142+
with urllib.request.urlopen(req) as resp:
143+
data = json.loads(resp.read())
144+
print(data["choices"][0]["message"]["content"])
145+
except Exception as e:
146+
print(f"Failed to generate summary via Copilot: {e}", file=sys.stderr)
147+
print(f"_Release notes generation failed. Raw commits since {prev_tag}:_\n\n```\n{commits}\n```")
148+
PYEOF
149+
)
150+
151+
# Append the summary (with version header) to release-notes.md
152+
NOTES_FILE="release-notes.md"
153+
if [ ! -f "$NOTES_FILE" ]; then
154+
printf "# Release Notes\n\n" > "$NOTES_FILE"
155+
fi
156+
printf "## v%s\n\n%s\n\n" "$CURRENT_TAG" "$SUMMARY" >> "$NOTES_FILE"
157+
158+
# Write the current release notes to a temp file for the Create Release step
159+
printf "%s" "$SUMMARY" > /tmp/current-release-notes.md
160+
161+
echo "Release notes generated and appended to $NOTES_FILE"
162+
84163
- name: Create Release
85164
run: |
86165
if gh release view "v${{ inputs.revision }}" >/dev/null 2>&1; then
87166
echo "Release v${{ inputs.revision }} already exists, skipping."
88167
else
89-
gh release create v${{ inputs.revision }} \
168+
gh release create ${{ inputs.revision }} \
90169
--title "v${{ inputs.revision }}" \
91-
--generate-notes \
170+
--notes-file /tmp/current-release-notes.md \
92171
--latest
93172
fi
94173
env:
@@ -109,7 +188,7 @@ jobs:
109188
run: |
110189
git config user.name "github-actions[bot]"
111190
git config user.email "github-actions[bot]@users.noreply.github.com"
112-
git add pom.xml
191+
git add pom.xml release-notes.md
113192
git diff --cached --quiet && echo "No changes to commit" || \
114193
git commit -m "chore: bump version to next patch after publishing ${{ inputs.revision }}" && git push
115194

0 commit comments

Comments
 (0)