Skip to content

Commit b3d9af2

Browse files
Merge pull request #104 from datavisyn/vdelev_auto_releasenotes
generate release notes with github api
2 parents dd3d298 + 0f62869 commit b3d9af2

File tree

1 file changed

+15
-28
lines changed

1 file changed

+15
-28
lines changed

.github/workflows/release-source.yml

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -223,38 +223,26 @@ jobs:
223223
- name: push all changes
224224
run: |
225225
git push origin release-"$RELEASE_VERSION"
226-
- name: get latest release date
227-
id: get-release-date
228-
run: |
229-
LATEST_RELEASE=$(curl -s -H "Accept: application/vnd.github+json" \
230-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
231-
"https://api.github.com/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/releases/latest")
232-
233-
LATEST_RELEASE_DATE=$(echo "$LATEST_RELEASE" | jq -r '.published_at')
234-
235-
echo "RELEASE_DATE=$LATEST_RELEASE_DATE" >> "$GITHUB_ENV"
236226
237-
- name: fetch merged PRs since last release
238-
id: fetch-prs
227+
- name: Generate release notes
228+
id: generate-release-notes
239229
run: |
240-
PRS=$(curl -s -H "Accept: application/vnd.github+json" \
241-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
242-
-H "X-GitHub-Api-Version: 2022-11-28" \
243-
"https://api.github.com/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/pulls?state=closed&base=${{ github.ref_name }}&sort=updated&direction=desc")
230+
response=$(curl -s -X POST \
231+
-H "Accept: application/vnd.github+json" \
232+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
233+
-H "X-GitHub-Api-Version: 2022-11-28" \
234+
https://api.github.com/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/releases/generate-notes \
235+
-d "$(jq -n --arg tag_name "${{ env.RELEASE_VERSION }}" \
236+
--arg target_commitish "${{ github.ref_name }}" \
237+
'{tag_name: $tag_name, target_commitish: $target_commitish}')")
238+
239+
RELEASE_NOTES=$(echo "$response" | jq -r '.body')
244240
245-
if echo "$PRS" | jq -e . > /dev/null 2>&1; then
246-
PR_NOTES=$(echo "$PRS" | jq -r --arg since "$RELEASE_DATE" '.[] | select(.merged_at != null and .merged_at > $since) | "* \(.title) ([#\(.number)](\(.html_url)))"')
247-
else
248-
PR_NOTES="could not fetch release notes"
249-
fi
250-
echo "$PR_NOTES" > pr_notes.txt
241+
echo "$RELEASE_NOTES" > release_notes.txt
251242
252243
- name: create pr
253-
id: create-pr
254244
run: |
255-
PR_NOTES=$(cat pr_notes.txt)
256-
PR_NOTES=$(printf "## What's changed\n\n%s" "$PR_NOTES")
257-
# Create a pull request with release notes
245+
PR_NOTES=$(cat release_notes.txt)
258246
curl -L \
259247
-X POST \
260248
-H "Accept: application/vnd.github+json" \
@@ -266,5 +254,4 @@ jobs:
266254
--arg body "$PR_NOTES" \
267255
--arg head "release-${{ env.RELEASE_VERSION }}" \
268256
--arg base "${{ inputs.base_branch }}" \
269-
--argjson draft false \
270-
'{title: $title, body: $body, head: $head, base: $base, draft: $draft}')"
257+
'{title: $title, body: $body, head: $head, base: $base}')"

0 commit comments

Comments
 (0)