-
Notifications
You must be signed in to change notification settings - Fork 395
96 lines (81 loc) · 3.45 KB
/
webex-space-notification.yml
File metadata and controls
96 lines (81 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
name: Webex Space Release Notification
run-name: ${{ github.actor }} triggered Webex space notification
on:
workflow_dispatch:
workflow_run:
workflows: ["Deploy CD"]
types:
- completed
branches:
- next
jobs:
notify-webex-space:
name: Send Webex Space Notification
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get Version and PR from Tag
id: tag-info
run: |
git fetch --tags
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$VERSION" ]; then
echo "❌ No tags found"
exit 1
fi
TAG_MESSAGE=$(git tag -l --format='%(contents:subject)' "$VERSION")
PR_NUMBER=$(echo "$TAG_MESSAGE" | grep -oE '#[0-9]+' | head -1 | tr -d '#')
echo "📦 Tag: ${VERSION}, PR: #${PR_NUMBER}"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "version_number=${VERSION#v}" >> $GITHUB_OUTPUT
echo "pr_number=${PR_NUMBER}" >> $GITHUB_OUTPUT
- name: Get Changelog URL from PR Comment
id: get-changelog
uses: actions/github-script@v7
with:
script: |
const prNumber = '${{ steps.tag-info.outputs.pr_number }}';
if (!prNumber) {
console.log('❌ No PR number, skipping changelog fetch');
core.setOutput('changelog_url', '');
return;
}
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: parseInt(prNumber)
});
const botComment = comments.data.find(c =>
c.user.type === 'Bot' &&
c.body.includes('Your changes are now available')
);
if (botComment) {
const match = botComment.body.match(/\[View full changelog[^\]]*\]\(([^)]+)\)/);
const url = match ? match[1] : '';
console.log(`✅ Found changelog URL: ${url}`);
core.setOutput('changelog_url', url);
} else {
console.log('⚠️ No bot comment found on PR');
core.setOutput('changelog_url', '');
}
- name: Post Webex Space Message
env:
WEBEX_BOT_TOKEN: ${{ secrets.WEBEX_BOT_TOKEN }}
WEBEX_ROOM_ID: ${{ secrets.WEBEX_ROOM_ID }}
run: |
VERSION="${{ steps.tag-info.outputs.version }}"
PR_NUMBER="${{ steps.tag-info.outputs.pr_number }}"
CHANGELOG_URL="${{ steps.get-changelog.outputs.changelog_url }}"
PR_LINK="https://github.com/${{ github.repository }}/pull/${PR_NUMBER}"
MESSAGE="**SDK Version:** ${VERSION}\n\n**PR:** ${PR_LINK}\n\n**Changelog:** ${CHANGELOG_URL}"
echo "📨 Sending message to Webex Space..."
curl -sSf \
-H "Authorization: Bearer ${WEBEX_BOT_TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"roomId\":\"${WEBEX_ROOM_ID}\",\"markdown\":\"${MESSAGE}\"}" \
https://webexapis.com/v1/messages > /dev/null
echo "✅ Message sent successfully!"