Skip to content

Commit 4e366e9

Browse files
authored
Internal: Add slack notification to daily tests (#575)
1 parent 6608e2b commit 4e366e9

File tree

5 files changed

+208
-67
lines changed

5 files changed

+208
-67
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: 'Theme Slack Notification (Daily Tests)'
2+
description: 'Send Slack notification for Hello Elementor daily test failures'
3+
inputs:
4+
CLOUD_SLACK_BOT_TOKEN:
5+
required: true
6+
description: 'Slack bot token'
7+
WORKFLOW_URL:
8+
required: true
9+
description: 'GitHub workflow run URL'
10+
SLACK_CHANNEL:
11+
required: false
12+
default: '#tmz-alerts'
13+
description: 'Slack channel to send notification to'
14+
15+
runs:
16+
using: 'composite'
17+
steps:
18+
- name: Post to Slack
19+
shell: bash
20+
env:
21+
CLOUD_SLACK_BOT_TOKEN: ${{ inputs.CLOUD_SLACK_BOT_TOKEN }}
22+
WORKFLOW_URL: ${{ inputs.WORKFLOW_URL }}
23+
SLACK_CHANNEL: ${{ inputs.SLACK_CHANNEL }}
24+
run: |
25+
node << 'NODE_SCRIPT'
26+
const workflowUrl = process.env.WORKFLOW_URL || '';
27+
const slackChannel = process.env.SLACK_CHANNEL || '#tmz-alerts';
28+
29+
const payload = {
30+
text: 'Failing test alert',
31+
blocks: [
32+
{
33+
type: 'section',
34+
text: {
35+
type: 'mrkdwn',
36+
text: '*Failing test alert*\n\n*Theme:* Hello Elementor\n*Test report:* <' + workflowUrl + '|View Workflow Run>'
37+
}
38+
}
39+
]
40+
};
41+
42+
process.env.SLACK_PAYLOAD = JSON.stringify(payload);
43+
44+
const { execSync } = require('child_process');
45+
const path = require('path');
46+
const scriptPath = path.join(process.env.GITHUB_WORKSPACE, '.github/scripts/send-slack-message.js');
47+
execSync(`node "${scriptPath}"`, { stdio: 'inherit', env: process.env });
48+
NODE_SCRIPT
49+
50+
- name: Notification summary
51+
shell: bash
52+
run: |
53+
echo "📢 Slack notification sent!"
54+
echo " - Channel: ${{ inputs.SLACK_CHANNEL }}"
55+
echo " - Workflow: ${{ inputs.WORKFLOW_URL }}"
56+

.github/actions/theme-slack-notification-release/action.yml

Lines changed: 87 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: 'Theme Slack Notification (Release)'
22
description: 'Send Slack notification for Hello Elementor release'
33
inputs:
4-
SLACK_BOT_TOKEN:
4+
CLOUD_SLACK_BOT_TOKEN:
55
required: true
66
description: 'Slack bot token'
77
PACKAGE_VERSION:
@@ -15,7 +15,7 @@ inputs:
1515
description: 'GitHub release URL'
1616
SLACK_CHANNEL:
1717
required: false
18-
default: '#general'
18+
default: '#tmz-hello-delivery'
1919
description: 'Slack channel to send notification to'
2020
WPORG_DEPLOYMENT_STATUS:
2121
required: false
@@ -56,73 +56,94 @@ runs:
5656
fi
5757
5858
- name: Post to Slack
59-
uses: slackapi/[email protected]
60-
with:
61-
channel-id: ${{ inputs.SLACK_CHANNEL }}
62-
payload: |
63-
{
64-
"blocks": [
65-
{
66-
"type": "header",
67-
"text": {
68-
"type": "plain_text",
69-
"text": "🚀 Hello Elementor v${{ inputs.PACKAGE_VERSION }} Released!"
70-
}
71-
},
72-
{
73-
"type": "section",
74-
"text": {
75-
"type": "mrkdwn",
76-
"text": "*Hello Elementor theme* has been successfully released and is ready for distribution."
59+
shell: bash
60+
env:
61+
CLOUD_SLACK_BOT_TOKEN: ${{ inputs.CLOUD_SLACK_BOT_TOKEN }}
62+
SLACK_CHANNEL: ${{ inputs.SLACK_CHANNEL }}
63+
PACKAGE_VERSION: ${{ inputs.PACKAGE_VERSION }}
64+
FILE_SIZE_MB: ${{ env.FILE_SIZE_MB }}
65+
DEPLOYMENT_MESSAGE: ${{ env.DEPLOYMENT_MESSAGE }}
66+
GITHUB_RELEASE_URL: ${{ inputs.GITHUB_RELEASE_URL }}
67+
BUILD_ZIP_PATH: ${{ inputs.BUILD_ZIP_PATH }}
68+
run: |
69+
node << 'NODE_SCRIPT'
70+
const slackChannel = process.env.SLACK_CHANNEL || '#tmz-hello-delivery';
71+
const packageVersion = process.env.PACKAGE_VERSION || '';
72+
const fileSizeMb = process.env.FILE_SIZE_MB || 'Unknown';
73+
const deploymentMessage = (process.env.DEPLOYMENT_MESSAGE || '').replace(/\\n/g, '\n');
74+
const githubReleaseUrl = process.env.GITHUB_RELEASE_URL || '';
75+
const buildZipPath = process.env.BUILD_ZIP_PATH || '';
76+
77+
const payload = {
78+
text: `Hello Elementor v${packageVersion} Released!`,
79+
blocks: [
80+
{
81+
type: 'header',
82+
text: {
83+
type: 'plain_text',
84+
text: `🚀 Hello Elementor v${packageVersion} Released!`
85+
}
86+
},
87+
{
88+
type: 'section',
89+
text: {
90+
type: 'mrkdwn',
91+
text: '*Hello Elementor theme* has been successfully released and is ready for distribution.'
92+
}
93+
},
94+
{
95+
type: 'section',
96+
fields: [
97+
{
98+
type: 'mrkdwn',
99+
text: `*Version:*\nv${packageVersion}`
100+
},
101+
{
102+
type: 'mrkdwn',
103+
text: `*Package Size:*\n${fileSizeMb}`
77104
}
78-
},
79-
{
80-
"type": "section",
81-
"fields": [
82-
{
83-
"type": "mrkdwn",
84-
"text": "*Version:*\nv${{ inputs.PACKAGE_VERSION }}"
105+
]
106+
},
107+
{
108+
type: 'section',
109+
text: {
110+
type: 'mrkdwn',
111+
text: deploymentMessage
112+
}
113+
},
114+
{
115+
type: 'actions',
116+
elements: [
117+
{
118+
type: 'button',
119+
text: {
120+
type: 'plain_text',
121+
text: '📥 Download Release'
85122
},
86-
{
87-
"type": "mrkdwn",
88-
"text": "*Package Size:*\n${{ env.FILE_SIZE_MB }}"
89-
}
90-
]
91-
},
92-
{
93-
"type": "section",
94-
"text": {
95-
"type": "mrkdwn",
96-
"text": "${{ env.DEPLOYMENT_MESSAGE }}"
123+
url: githubReleaseUrl,
124+
style: 'primary'
97125
}
98-
},
99-
{
100-
"type": "actions",
101-
"elements": [
102-
{
103-
"type": "button",
104-
"text": {
105-
"type": "plain_text",
106-
"text": "📥 Download Release"
107-
},
108-
"url": "${{ inputs.GITHUB_RELEASE_URL }}",
109-
"style": "primary"
110-
}
111-
]
112-
},
113-
{
114-
"type": "context",
115-
"elements": [
116-
{
117-
"type": "mrkdwn",
118-
"text": "Build: ${{ inputs.BUILD_ZIP_PATH }}"
119-
}
120-
]
121-
}
122-
]
123-
}
124-
env:
125-
SLACK_BOT_TOKEN: ${{ inputs.SLACK_BOT_TOKEN }}
126+
]
127+
},
128+
{
129+
type: 'context',
130+
elements: [
131+
{
132+
type: 'mrkdwn',
133+
text: `Build: ${buildZipPath}`
134+
}
135+
]
136+
}
137+
]
138+
};
139+
140+
process.env.SLACK_PAYLOAD = JSON.stringify(payload);
141+
142+
const { execSync } = require('child_process');
143+
const path = require('path');
144+
const scriptPath = path.join(process.env.GITHUB_WORKSPACE, '.github/scripts/send-slack-message.js');
145+
execSync(`node "${scriptPath}"`, { stdio: 'inherit', env: process.env });
146+
NODE_SCRIPT
126147
127148
- name: Notification summary
128149
shell: bash
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const https = require('https');
2+
3+
const slackToken = process.env.CLOUD_SLACK_BOT_TOKEN || '';
4+
const slackChannel = process.env.SLACK_CHANNEL || '#tmz-alerts';
5+
const payloadJson = process.env.SLACK_PAYLOAD || '{}';
6+
7+
if (!slackToken) {
8+
console.log('⚠️ Slack token not provided, skipping notification');
9+
process.exit(0);
10+
}
11+
12+
let payload;
13+
try {
14+
payload = JSON.parse(payloadJson);
15+
payload.channel = slackChannel;
16+
} catch (error) {
17+
console.error('Failed to parse payload:', error.message);
18+
process.exit(1);
19+
}
20+
21+
const payloadStr = JSON.stringify(payload);
22+
const data = Buffer.from(payloadStr, 'utf8');
23+
24+
const options = {
25+
hostname: 'slack.com',
26+
port: 443,
27+
path: '/api/chat.postMessage',
28+
method: 'POST',
29+
headers: {
30+
'Authorization': `Bearer ${slackToken}`,
31+
'Content-Type': 'application/json',
32+
'Content-Length': data.length
33+
}
34+
};
35+
36+
const req = https.request(options, (res) => {
37+
let responseData = '';
38+
res.on('data', (chunk) => {
39+
responseData += chunk;
40+
});
41+
res.on('end', () => {
42+
const response = JSON.parse(responseData);
43+
if (res.statusCode === 200 && response.ok) console.log('✅ Slack notification sent');
44+
process.exit(0);
45+
});
46+
});
47+
48+
req.on('error', (error) => {
49+
console.error('Failed to send Slack notification');
50+
process.exit(0);
51+
});
52+
53+
req.write(data);
54+
req.end();
55+

.github/workflows/daily-test-matrix.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,3 +728,12 @@ jobs:
728728
} else {
729729
console.log(`✅ Daily test matrix completed successfully: ${summary.success} passed out of ${summary.total} tests`);
730730
}
731+
732+
- name: Send Slack notification on failure
733+
if: failure()
734+
continue-on-error: true
735+
uses: ./.github/actions/theme-slack-notification-daily-tests
736+
with:
737+
CLOUD_SLACK_BOT_TOKEN: ${{ secrets.CLOUD_SLACK_BOT_TOKEN }}
738+
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
739+
SLACK_CHANNEL: '#tmz-alerts'

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ jobs:
526526
if: ${{ inputs.dry_run == false && inputs.deploy_to_wporg == true }}
527527
uses: ./.github/actions/theme-slack-notification-release
528528
with:
529-
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
529+
CLOUD_SLACK_BOT_TOKEN: ${{ secrets.CLOUD_SLACK_BOT_TOKEN }}
530530
PACKAGE_VERSION: ${{ env.PACKAGE_VERSION }}
531531
BUILD_ZIP_PATH: ${{ env.BUILD_ZIP_PATH }}
532532
GITHUB_RELEASE_URL: ${{ env.RELEASE_URL }}

0 commit comments

Comments
 (0)