From e850ff6ce5695afe5fd00e55cd1db2223845c3c9 Mon Sep 17 00:00:00 2001 From: Erik Bylund Date: Wed, 18 Dec 2024 14:00:23 +0100 Subject: [PATCH] meta: Add workflow that generates changelogs from patch notes --- .github/scripts/generate-changelog.sh | 52 ++++++++++++++++++++++++ .github/workflows/generate-changelog.yml | 29 +++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 .github/scripts/generate-changelog.sh create mode 100644 .github/workflows/generate-changelog.yml diff --git a/.github/scripts/generate-changelog.sh b/.github/scripts/generate-changelog.sh new file mode 100644 index 00000000..7cec89bd --- /dev/null +++ b/.github/scripts/generate-changelog.sh @@ -0,0 +1,52 @@ +#!/bin/bash +sdk=$1 +sdkname=$2 +openAIApiKey=$3 + +latestRelease=$(curl -s -X GET "https://api.github.com/repos/lootlocker/$sdk/releases/latest") + +version=$(echo "$latestRelease" | jq .tag_name) +version=${version//\"/} +patchnotes=$(echo "$latestRelease" | jq .body) +patchnotes=${patchnotes//\\r\\n/\\n} + +prompt="Condense these patch notes (but dont mention the version number) to a short message (max 255 character) naming the important changes and crucial information in a helpful, informative, but punchy way: $patchnotes" +prompt=${prompt//\"/} +body='{ + "model": "gpt-4o-mini", + "messages": [ + { + "role": "system", + "content": "You are the chief tech communicator of LootLocker and a marketing Genius" + }, + { + "role": "user", + "content": "'$prompt'" + } + ] + }' + +jsonResponse=$(curl -s "https://api.openai.com/v1/chat/completions" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $openAIApiKey" \ + -d "$body") + +shortPatchNotes=$(echo "$jsonResponse" | jq .choices[0].message.content) +shortPatchNotes=${shortPatchNotes//\"/} + +filename="$sdk-$version" +filename=${filename//./-} +filename="$filename.md" +echo "---" > $filename +echo "title: \"$sdkname $version\"" >> $filename +echo "author: Erik Bylund" >> $filename +dt=`date '+%Y-%m-%dT%H:%M:%SZ'` +echo "date: $dt" >> $filename +echo "---" >> $filename + +echo "" >> $filename + +echo "**🎉 $sdkname $version is released 🎉**" >> $filename +echo "$shortPatchNotes" >> $filename +echo "" >> $filename +echo "[Find it here](https://github.com/lootlocker/$sdk/releases/tag/$version)" >> $filename \ No newline at end of file diff --git a/.github/workflows/generate-changelog.yml b/.github/workflows/generate-changelog.yml new file mode 100644 index 00000000..a6509f14 --- /dev/null +++ b/.github/workflows/generate-changelog.yml @@ -0,0 +1,29 @@ +name: Generate changelog from release +run-name: generate-changelog +on: + release: + types: [published] + workflow_dispatch: {} + +jobs: + generate-changelog: + name: Generate changelog from release + runs-on: [ubuntu-latest] + steps: + - name: Install jq + run: | + sudo apt install jq + - name: Checkout this repository + uses: actions/checkout@v4 + with: + path: ./sdk + - name: Generate changelog from latest release + run: | + ./sdk/.github/scripts/generate-changelog.sh unreal-sdk "Unreal SDK" "${{ SECRETS.OPEN_AI_API_KEY }}" + - name: Cat changelog so you can get it without downloading + run: cat ./*.md + - name: Expose changelog + uses: actions/upload-artifact@v4 + with: + name: changelog + path: ./*.md