Sync ai-personas releases to KudoAI/ai-personas #18
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Sync ai-personas releases to KudoAI/ai-personas | |
| on: | |
| release: | |
| types: [published, edited] | |
| jobs: | |
| sync-release: | |
| name: Sync release to KudoAI/ai-personas | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| contents: read | |
| env: | |
| REPO_SYNC_PAT: ${{ secrets.REPO_SYNC_PAT }} | |
| steps: | |
| - name: Generate KSB token | |
| id: ksb-token | |
| uses: actions/create-github-app-token@v3.0.0 | |
| with: | |
| app-id: ${{ secrets.KSB_APP_ID }} | |
| private-key: ${{ secrets.KSB_PRIVATE_KEY }} | |
| owner: KudoAI | |
| - name: Sync release to KudoAI/ai-personas | |
| run: | | |
| RELEASE_TITLE="${{ github.event.release.name }}" | |
| RELEASE_TAG="${{ github.event.release.tag_name }}" | |
| echo "Source Title: $RELEASE_TITLE" | |
| echo "Source Tag: $RELEASE_TAG" | |
| RELEASE_JSON=$(curl -s "https://api.github.com/repos/adamlui/python-utils/releases/tags/$RELEASE_TAG") | |
| RELEASE_NOTES=$(echo "$RELEASE_JSON" | sed -nE 's/.*"body": "(.*)".*/\1/p') | |
| if [[ "$RELEASE_NOTES" == *"Auto-synced from"* ]] ; then | |
| echo "Release already auto-synced. Exiting..." ; exit 0 ; fi | |
| # Convert emoji | |
| RELEASE_NOTES=$(echo "$RELEASE_NOTES" | \ | |
| sed 's|📃|:page_with_curl:|g; s|🚀|:rocket:|g; s|🧠|:brain:|g; s|💻|:computer:|g') | |
| TARGET_RELEASE_TITLE=$(echo "$RELEASE_TITLE" | sed -E 's/ (v[0-9]+\.[0-9]+\.[0-9]+)/ (Python) \1/') | |
| TARGET_RELEASE_TAG="python-v$(echo "$RELEASE_TAG" | sed -E 's/^ai-personas-([0-9.]+)$/\1/')" | |
| echo "Target Title: $TARGET_RELEASE_TITLE" | |
| echo "Target Tag: $TARGET_RELEASE_TAG" | |
| # Check release exists in ai-personas | |
| RELEASE_CHECK_RESP=$(curl -s \ | |
| "https://api.github.com/repos/KudoAI/ai-personas/releases/tags/$TARGET_RELEASE_TAG") | |
| TARGET_RELEASE_ID=$(echo "$RELEASE_CHECK_RESP" | sed -nE 's/.*"id":[[:space:]]*([0-9]+).*/\1/p' | head -1) | |
| if [ -n "$TARGET_RELEASE_ID" ] ; then | |
| RELEASE_EXISTS=true | |
| echo "Release exists (ID: $TARGET_RELEASE_ID)" | |
| else | |
| RELEASE_EXISTS=false | |
| echo "Release does not exist" | |
| fi | |
| # Append auto-sync trailer | |
| RELEASE_NOTES+="\n###### _Auto-synced from https://github.com/adamlui/python-utils/releases" | |
| RELEASE_NOTES+=" by_ :robot: [kudo-sync-bot](https://github.com/kudo-sync-bot)" | |
| if [ "$RELEASE_EXISTS" = false ] ; then | |
| echo "Creating new release..." | |
| create_release_url="https://api.github.com/repos/KudoAI/ai-personas/releases" | |
| create_release_payload=$( | |
| printf '{"tag_name": "%s","name": "%s","body": "%s"}' \ | |
| "$TARGET_RELEASE_TAG" "$TARGET_RELEASE_TITLE" "$RELEASE_NOTES") | |
| create_release_resp=$( | |
| curl -s -S -X POST -H "Authorization: Bearer ${{ steps.ksb-token.outputs.token }}" \ | |
| -H "Content-Type: application/json" -d "$create_release_payload" "$create_release_url") | |
| if echo "$create_release_resp" | grep -q '"message"' ; then | |
| echo "ERROR: Failed to create release: $create_release_resp" | |
| exit 1 | |
| fi | |
| upload_url=$(echo "$create_release_resp" | sed -nE 's|.*"upload_url": "(.*)".*|\1|p' | sed 's|{.*}||') | |
| else | |
| echo "Updating existing release..." | |
| update_release_url="https://api.github.com/repos/KudoAI/ai-personas/releases/$TARGET_RELEASE_ID" | |
| update_release_payload=$( | |
| printf '{"name": "%s","body": "%s"}' \ | |
| "$TARGET_RELEASE_TITLE" "$RELEASE_NOTES") | |
| patch_release_resp=$( | |
| curl -s -S -X PATCH -H "Authorization: Bearer ${{ steps.ksb-token.outputs.token }}" \ | |
| -H "Content-Type: application/json" -d "$update_release_payload" "$update_release_url") | |
| if echo "$patch_release_resp" | grep -q '"message"' ; then | |
| echo "ERROR: Failed to update release: $patch_release_resp" | |
| exit 1 | |
| fi | |
| get_release_resp=$(curl -s -S -H "Authorization: Bearer ${{ steps.ksb-token.outputs.token }}" \ | |
| "https://api.github.com/repos/KudoAI/ai-personas/releases/tags/$TARGET_RELEASE_TAG") | |
| upload_url=$(echo "$get_release_resp" | sed -nE 's|.*"upload_url": "(.*)".*|\1|p' | sed 's|{.*}||') | |
| fi | |
| echo "Release synced to KudoAI/ai-personas ($TARGET_RELEASE_TAG)!" |