Skip to content

Commit c4cb8a0

Browse files
committed
Create sync-ai-personas-releases-to-project-repo.yml
1 parent 471de5d commit c4cb8a0

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Sync ai-personas releases to KudoAI/ai-personas
2+
3+
on:
4+
release:
5+
types: [published, edited, released]
6+
7+
jobs:
8+
sync-release:
9+
name: Sync release to KudoAI/ai-personas
10+
runs-on: ubuntu-24.04
11+
permissions:
12+
contents: read
13+
env:
14+
REPO_SYNC_PAT: ${{ secrets.REPO_SYNC_PAT }}
15+
steps:
16+
- name: Sync release to KudoAI/ai-personas
17+
run: |
18+
RELEASE_TITLE="${{ github.event.release.name }}"
19+
RELEASE_TAG="${{ github.event.release.tag_name }}"
20+
echo "Source Title: $RELEASE_TITLE"
21+
echo "Source Tag: $RELEASE_TAG"
22+
23+
RELEASE_JSON=$(curl -s "https://api.github.com/repos/adamlui/python-utils/releases/tags/$RELEASE_TAG")
24+
RELEASE_NOTES=$(echo "$RELEASE_JSON" | sed -nE 's/.*"body": "(.*)".*/\1/p')
25+
26+
if [[ "$RELEASE_NOTES" == *"Auto-synced from"* ]] ; then
27+
echo "Release already auto-synced. Exiting..." ; exit 0 ; fi
28+
29+
# Convert emoji
30+
RELEASE_NOTES=$(echo "$RELEASE_NOTES" | \
31+
sed 's|📃|:page_with_curl:|g; s|🚀|:rocket:|g; s|🧠|:brain:|g; s|💻|:computer:|g')
32+
33+
TARGET_RELEASE_TITLE="${RELEASE_TITLE} (Python)"
34+
TARGET_RELEASE_TAG="python-v$(echo "$RELEASE_TAG" | sed -E 's/^ai-personas-([0-9.]+)$/\1/')"
35+
echo "Target Title: $TARGET_RELEASE_TITLE"
36+
echo "Target Tag: $TARGET_RELEASE_TAG"
37+
38+
# Check release exists in ai-personas
39+
RELEASE_CHECK_RESP=$(curl -s \
40+
"https://api.github.com/repos/KudoAI/ai-personas/releases/tags/$TARGET_RELEASE_TAG")
41+
TARGET_RELEASE_ID=$(echo "$RELEASE_CHECK_RESP" | sed -nE 's/.*"id":[[:space:]]*([0-9]+).*/\1/p' | head -1)
42+
if [ -n "$TARGET_RELEASE_ID" ] ; then
43+
RELEASE_EXISTS=true
44+
echo "Release exists (ID: $TARGET_RELEASE_ID)"
45+
else
46+
RELEASE_EXISTS=false
47+
echo "Release does not exist"
48+
fi
49+
50+
# Append auto-sync trailer
51+
RELEASE_NOTES+="\n\n###### _Auto-synced from https://github.com/adamlui/python-utils/releases"
52+
RELEASE_NOTES+=" by_ :robot: [kudo-sync-bot](https://github.com/kudo-sync-bot)"
53+
54+
if [ "$RELEASE_EXISTS" = false ] ; then
55+
echo "Creating new release..."
56+
create_release_url="https://api.github.com/repos/KudoAI/ai-personas/releases"
57+
create_release_payload=$(
58+
printf '{"tag_name": "%s","name": "%s","body": "%s"}' \
59+
"$TARGET_RELEASE_TAG" "$TARGET_RELEASE_TITLE" "$RELEASE_NOTES")
60+
create_release_resp=$(
61+
curl -s -S -X POST -H "Authorization: token $REPO_SYNC_PAT" \
62+
-H "Content-Type: application/json" -d "$create_release_payload" "$create_release_url")
63+
if echo "$create_release_resp" | grep -q '"message"' ; then
64+
echo "ERROR: Failed to create release: $create_release_resp"
65+
exit 1
66+
fi
67+
upload_url=$(echo "$create_release_resp" | sed -nE 's|.*"upload_url": "(.*)".*|\1|p' | sed 's|{.*}||')
68+
else
69+
echo "Updating existing release..."
70+
update_release_url="https://api.github.com/repos/KudoAI/ai-personas/releases/$TARGET_RELEASE_ID"
71+
update_release_payload=$(
72+
printf '{"name": "%s","body": "%s"}' \
73+
"$TARGET_RELEASE_TITLE" "$RELEASE_NOTES")
74+
patch_release_resp=$(
75+
curl -s -S -X PATCH -H "Authorization: token $REPO_SYNC_PAT" \
76+
-H "Content-Type: application/json" -d "$update_release_payload" "$update_release_url")
77+
if echo "$patch_release_resp" | grep -q '"message"' ; then
78+
echo "ERROR: Failed to update release: $patch_release_resp"
79+
exit 1
80+
fi
81+
get_release_resp=$(curl -s -S -H "Authorization: token $REPO_SYNC_PAT" \
82+
"https://api.github.com/repos/KudoAI/ai-personas/releases/tags/$TARGET_RELEASE_TAG")
83+
upload_url=$(echo "$get_release_resp" | sed -nE 's|.*"upload_url": "(.*)".*|\1|p' | sed 's|{.*}||')
84+
fi
85+
86+
echo "Release synced to KudoAI/ai-personas ($TARGET_RELEASE_TAG)!"

0 commit comments

Comments
 (0)