Skip to content

Commit b095439

Browse files
authored
Merge pull request #17 from CodingWithCalvin/feature/bluesky-reusable-workflow
Use shared Bluesky workflow from .github repo
2 parents 273b682 + 21c72d1 commit b095439

File tree

1 file changed

+13
-101
lines changed

1 file changed

+13
-101
lines changed

.github/workflows/publish.yml

Lines changed: 13 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ permissions:
1010
jobs:
1111
publish:
1212
runs-on: windows-latest
13+
outputs:
14+
version: ${{ steps.artifact_manifest.outputs.version }}
1315
steps:
1416
- name: Checkout
1517
uses: actions/checkout@v4
@@ -44,106 +46,16 @@ jobs:
4446
publish-manifest-path: ./resources/extension.manifest.json
4547
vsix-path: ./artifact/CodingWithCalvin.OpenInNotepadPlusPlus.vsix
4648

47-
- name: 5. Post to BlueSky
48-
if: success()
49-
run: |
50-
VERSION="${{ steps.artifact_manifest.outputs.version }}"
51-
RELEASE_URL="https://github.com/${{ github.repository }}/releases/tag/$VERSION"
52-
MARKETPLACE_URL="https://marketplace.visualstudio.com/items?itemName=CodingWithCalvin.VS-OpenInNotepadPlusPlus"
53-
54-
# Authenticate with BlueSky
55-
echo "Authenticating with BlueSky..."
56-
AUTH_RESPONSE=$(curl -s -X POST https://bsky.social/xrpc/com.atproto.server.createSession \
57-
-H "Content-Type: application/json" \
58-
-d "{\"identifier\": \"${{ secrets.BLUESKY_USERNAME }}\", \"password\": \"${{ secrets.BLUESKY_APP_PASSWORD }}\"}")
59-
60-
ACCESS_TOKEN=$(echo "$AUTH_RESPONSE" | jq -r '.accessJwt')
61-
DID=$(echo "$AUTH_RESPONSE" | jq -r '.did')
62-
63-
if [ -z "$ACCESS_TOKEN" ] || [ "$ACCESS_TOKEN" == "null" ]; then
64-
echo "Error: Failed to authenticate with BlueSky"
65-
echo "Response: $AUTH_RESPONSE"
66-
exit 1
67-
fi
68-
69-
echo "✓ Authenticated as $DID"
70-
71-
# Create post text
72-
POST_TEXT="🚀 Open in Notepad++ v${VERSION} for #VisualStudio has been released!"
73-
POST_TEXT="${POST_TEXT}"$'\n\n'"Check out the release notes here!"
74-
POST_TEXT="${POST_TEXT}"$'\n\n'"Marketplace: ${MARKETPLACE_URL}"
75-
76-
echo "Post text: $POST_TEXT"
77-
78-
# Get current timestamp in ISO 8601 format
79-
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
80-
81-
# Calculate facets (byte positions for hashtags and links)
82-
echo "Calculating facets for links and hashtags..."
83-
export POST_TEXT
84-
export RELEASE_URL
85-
FACETS=$(python3 -c "
86-
import json, re, os
87-
text = os.environ['POST_TEXT']
88-
release_url = os.environ['RELEASE_URL']
89-
facets = []
90-
# Add hashtag facets
91-
for m in re.finditer(r'#(\w+)', text):
92-
facets.append({
93-
'index': {'byteStart': len(text[:m.start()].encode('utf-8')), 'byteEnd': len(text[:m.start()+len(m.group(0))].encode('utf-8'))},
94-
'features': [{'\$type': 'app.bsky.richtext.facet#tag', 'tag': m.group(1)}]
95-
})
96-
# Add link facets for URLs
97-
for m in re.finditer(r'https?://[^\s]+', text):
98-
facets.append({
99-
'index': {'byteStart': len(text[:m.start()].encode('utf-8')), 'byteEnd': len(text[:m.start()+len(m.group())].encode('utf-8'))},
100-
'features': [{'\$type': 'app.bsky.richtext.facet#link', 'uri': m.group()}]
101-
})
102-
# Add link facet for 'Check out the release notes here!'
103-
release_text = 'Check out the release notes here!'
104-
idx = text.find(release_text)
105-
if idx >= 0:
106-
facets.append({
107-
'index': {'byteStart': len(text[:idx].encode('utf-8')), 'byteEnd': len(text[:idx+len(release_text)].encode('utf-8'))},
108-
'features': [{'\$type': 'app.bsky.richtext.facet#link', 'uri': release_url}]
109-
})
110-
print(json.dumps(facets))
111-
")
112-
113-
echo "Facets: $FACETS"
114-
115-
# Create the post using jq to properly escape JSON
116-
echo "Creating BlueSky post..."
117-
POST_RESPONSE=$(jq -n \
118-
--arg did "$DID" \
119-
--arg text "$POST_TEXT" \
120-
--arg timestamp "$TIMESTAMP" \
121-
--argjson facets "$FACETS" \
122-
'{
123-
repo: $did,
124-
collection: "app.bsky.feed.post",
125-
record: {
126-
text: $text,
127-
facets: $facets,
128-
createdAt: $timestamp,
129-
"$type": "app.bsky.feed.post"
130-
}
131-
}' | curl -s -X POST https://bsky.social/xrpc/com.atproto.repo.createRecord \
132-
-H "Content-Type: application/json" \
133-
-H "Authorization: Bearer $ACCESS_TOKEN" \
134-
-d @-)
135-
136-
POST_URI=$(echo "$POST_RESPONSE" | jq -r '.uri')
137-
138-
if [ -z "$POST_URI" ] || [ "$POST_URI" == "null" ]; then
139-
echo "Error: Failed to create BlueSky post"
140-
echo "Response: $POST_RESPONSE"
141-
exit 1
142-
fi
49+
notify:
50+
needs: publish
51+
uses: CodingWithCalvin/.github/.github/workflows/bluesky-post.yml@main
52+
with:
53+
post_text: |
54+
🚀 Open in Notepad++ v${{ needs.publish.outputs.version }} for #VisualStudio has been released!
14355
144-
# Extract the post ID from the URI
145-
POST_ID=$(echo "$POST_URI" | sed 's|.*/||')
146-
POST_URL="https://bsky.app/profile/${{ secrets.BLUESKY_USERNAME }}/post/$POST_ID"
56+
[Check out the release notes here!](https://github.com/${{ github.repository }}/releases/tag/${{ needs.publish.outputs.version }})
14757
148-
echo "✓ Posted to BlueSky: $POST_URL"
149-
shell: bash
58+
Marketplace: https://marketplace.visualstudio.com/items?itemName=CodingWithCalvin.VS-OpenInNotepadPlusPlus
59+
secrets:
60+
BLUESKY_USERNAME: ${{ secrets.BLUESKY_USERNAME }}
61+
BLUESKY_APP_PASSWORD: ${{ secrets.BLUESKY_APP_PASSWORD }}

0 commit comments

Comments
 (0)