Skip to content

Commit 22af426

Browse files
feat(bot): add Webex Space notification with package-tools parsing
Uses yarn package-tools for recursive package detection instead of GitHub API Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent ac9a17f commit 22af426

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: Webex Space Release Notification
2+
run-name: ${{ github.actor }} triggered Webex space notification
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
test_version:
8+
description: 'Test version number (e.g., 3.10.0)'
9+
required: false
10+
default: '3.10.0'
11+
test_pr_number:
12+
description: 'Test PR number (e.g., 123)'
13+
required: false
14+
default: ''
15+
workflow_run:
16+
workflows: ["Deploy CD"]
17+
types:
18+
- completed
19+
branches:
20+
- next
21+
22+
jobs:
23+
notify-webex-space:
24+
name: Send Webex Space Notification
25+
runs-on: ubuntu-latest
26+
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
27+
28+
steps:
29+
- name: Checkout Repository
30+
uses: actions/checkout@v3
31+
with:
32+
fetch-depth: 0
33+
34+
- name: Get Version and PR from Tag
35+
id: tag-info
36+
run: |
37+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
38+
VERSION="${{ github.event.inputs.test_version }}"
39+
PR_NUMBER="${{ github.event.inputs.test_pr_number }}"
40+
echo "🧪 TEST MODE: version=${VERSION}, pr=${PR_NUMBER}"
41+
else
42+
git fetch --tags
43+
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
44+
if [ -z "$VERSION" ]; then
45+
echo "❌ No tags found"
46+
exit 1
47+
fi
48+
TAG_MESSAGE=$(git tag -l --format='%(contents:subject)' "$VERSION")
49+
PR_NUMBER=$(echo "$TAG_MESSAGE" | grep -oE '#[0-9]+' | head -1 | tr -d '#')
50+
COMMIT_HASH=$(echo "$TAG_MESSAGE" | awk '{print $1}')
51+
echo "📦 Tag: ${VERSION}, PR: #${PR_NUMBER}, Commit: ${COMMIT_HASH}"
52+
echo "commit_hash=${COMMIT_HASH}" >> $GITHUB_OUTPUT
53+
fi
54+
55+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
56+
echo "version_number=${VERSION#v}" >> $GITHUB_OUTPUT
57+
echo "pr_number=${PR_NUMBER}" >> $GITHUB_OUTPUT
58+
59+
- name: Build Package Tools
60+
run: |
61+
yarn install
62+
yarn build:tools
63+
64+
- name: Get Packages
65+
id: get-packages
66+
run: |
67+
PR_NUMBER="${{ steps.tag-info.outputs.pr_number }}"
68+
69+
if [ -z "$PR_NUMBER" ]; then
70+
echo "❌ No PR number found, using default package"
71+
echo "packages=[\"webex\"]" >> $GITHUB_OUTPUT
72+
echo "primary_package=webex" >> $GITHUB_OUTPUT
73+
exit 0
74+
fi
75+
76+
echo "✅ Getting packages for PR #${PR_NUMBER}"
77+
78+
# Get packages with --recursive to include dependent packages (like webex)
79+
PACKAGES=$(yarn package-tools list --recursive --since origin/next 2>/dev/null || echo "webex")
80+
81+
echo "📦 Detected packages: ${PACKAGES}"
82+
83+
# Convert comma-separated to JSON array
84+
PACKAGES_JSON=$(echo "$PACKAGES" | tr ',' '\n' | sed 's/.*/"&"/' | tr '\n' ',' | sed 's/,$//' | sed 's/^/[/' | sed 's/$/]/')
85+
86+
echo "packages=${PACKAGES_JSON}" >> $GITHUB_OUTPUT
87+
88+
# Check if webex is in the packages list
89+
if echo "$PACKAGES" | grep -q "webex"; then
90+
echo "primary_package=webex" >> $GITHUB_OUTPUT
91+
echo "✅ webex detected in packages"
92+
else
93+
# Use first package
94+
PRIMARY=$(echo "$PACKAGES" | tr ',' '\n' | head -1)
95+
echo "primary_package=${PRIMARY}" >> $GITHUB_OUTPUT
96+
echo "📦 Primary package: ${PRIMARY}"
97+
fi
98+
99+
- name: Post Webex Space Message
100+
env:
101+
WEBEX_BOT_TOKEN: ${{ secrets.WEBEX_BOT_TOKEN }}
102+
WEBEX_ROOM_ID: ${{ secrets.WEBEX_ROOM_ID }}
103+
run: |
104+
VERSION="${{ steps.tag-info.outputs.version }}"
105+
VERSION_NUMBER="${{ steps.tag-info.outputs.version_number }}"
106+
COMMIT_HASH="${{ steps.tag-info.outputs.commit_hash }}"
107+
PRIMARY_PACKAGE="${{ steps.get-packages.outputs.primary_package }}"
108+
PR_NUMBER="${{ steps.tag-info.outputs.pr_number }}"
109+
110+
# Calculate stable version (strip -next.X suffix)
111+
STABLE_VERSION=$(echo "$VERSION_NUMBER" | sed 's/-next\..*//')
112+
113+
# Build changelog URL
114+
CHANGELOG_URL="https://web-sdk.webex.com/changelog/?stable_version=${STABLE_VERSION}"
115+
116+
# Add package parameter
117+
if [ -n "${PRIMARY_PACKAGE}" ]; then
118+
ENCODED_PACKAGE=$(node -e "console.log(encodeURIComponent(process.argv[1]))" "${PRIMARY_PACKAGE}")
119+
CHANGELOG_URL="${CHANGELOG_URL}&package=${ENCODED_PACKAGE}"
120+
fi
121+
122+
# Add version parameter
123+
if [ -n "${VERSION_NUMBER}" ]; then
124+
CHANGELOG_URL="${CHANGELOG_URL}&version=${VERSION_NUMBER}"
125+
fi
126+
127+
echo "🔗 Changelog URL: ${CHANGELOG_URL}"
128+
129+
# Build the message - simple format: SDK version, PR link, Changelog link
130+
PR_LINK="https://github.com/${{ github.repository }}/pull/${PR_NUMBER}"
131+
132+
MESSAGE="**SDK Version:** ${VERSION}\n\n**PR:** ${PR_LINK}\n\n**Changelog:** ${CHANGELOG_URL}"
133+
134+
echo "📨 Sending message to Webex Space..."
135+
136+
curl -sSf \
137+
-H "Authorization: Bearer ${WEBEX_BOT_TOKEN}" \
138+
-H "Content-Type: application/json" \
139+
-d "{\"roomId\":\"${WEBEX_ROOM_ID}\",\"markdown\":\"${MESSAGE}\"}" \
140+
https://webexapis.com/v1/messages
141+
142+
echo "✅ Message sent successfully!"

0 commit comments

Comments
 (0)