Skip to content

Commit

Permalink
Generate automatic PR summaries for submodule bumps (#62)
Browse files Browse the repository at this point in the history
Generate automatic PR summaries for submodule bumps
  • Loading branch information
lava authored Jan 30, 2025
1 parent 26371da commit 75e2152
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
20 changes: 13 additions & 7 deletions .github/workflows/update-submodules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,19 @@ jobs:
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.TENZIR_APP_DEPLOY_KEY }}
- name: Authenticate with google cloud
id: gcloud-login
uses: 'google-github-actions/auth@v2'
with:
credentials_json: ${{ secrets.GCS_SERVICE_ACCOUNT_CREDENTIALS }}
token_format: "access_token"
- name: Update app submodule
if: ${{ inputs.bump-app }}
env:
LOCATION: europe-west3
MODEL: gemini-1.5-pro
PROJECT_ID: ${{ steps.gcloud-login.outputs.project_id }}
GCLOUD_ACCESS_TOKEN: ${{ steps.gcloud-login.outputs.access_token }}
run: |
git submodule update --init components/app
current_sha=$(git -C components/app rev-parse HEAD)
Expand All @@ -60,14 +71,9 @@ jobs:
upstream_sha_short=$(git -C components/app rev-parse --short origin/main)
if [ ${current_sha} != ${upstream_sha} ]; then
# Collect all files in the `changelog` directory that
# were added since the last bump.
names=$(git -C components/app diff --name-status HEAD origin/main -- changelog/ | grep -E '^(A|M)' | awk '{print $2}')
git -C components/app checkout origin/main
echo -e "Bump app component from ${current_sha_short} to ${upstream_sha_short}\n\nChanges:\n" > commitmsg
for name in ${names}; do
cat components/app/${name} >> commitmsg
done
echo -e "Bump app component from ${current_sha_short} to ${upstream_sha_short}\n\n" > commitmsg
./scripts/describe-component-bump components/app ${current_sha} ${upstream_sha} >> commitmsg ||:
git add components/app
git commit -F commitmsg
git push -u origin main:main
Expand Down
28 changes: 28 additions & 0 deletions scripts/describe-component-bump
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

SUBMODULE_PATH="$1"
FROM_COMMIT="$2"
TO_COMMIT="$3"

CHANGELOG_BASE64=$(git -C ${SUBMODULE_PATH} log --stat ${FROM_COMMIT}..${TO_COMMTI} | base64 -w 0)

REQUEST_JSON=$(cat <<EOF
{
"contents": {
"role": "user",
"parts": [
{"text": "Please output a brief summary of the changes that were made in the attached PR. Use roughly one sentence per independent feature or bugfix introduced. Focus on on the user-visible effect and not the technical implementation details."},
{"inlineData": {"mimeType": "text/plain", "data": "${CHANGELOG_BASE64}"}},
],
}
}
EOF
)

RESPONSE=$(curl -s -X POST \
-H "Authorization: Bearer ${GCLOUD_ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
https://${LOCATION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${LOCATION}/publishers/google/models/${MODEL}:generateContent \
-d "${REQUEST_JSON}")

echo ${RESPONSE} | jq -r .candidates[0].content.parts[0].text

0 comments on commit 75e2152

Please sign in to comment.