-
Notifications
You must be signed in to change notification settings - Fork 246
Internal: Add slack notification to daily tests #575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7c4f070
Test slack notification
hein-obox 8256972
debug
hein-obox 183cc4f
wip
hein-obox 7ba34df
wip
hein-obox 5a47ce0
wip
hein-obox ca7a2ec
Update channel name.
hein-obox 7313fb2
Clean up initial test notification
hein-obox 6290548
Refactor
hein-obox ed0ad77
Send slack message
hein-obox 0431137
Clean up
hein-obox a89bbfc
Potential fix for code scanning alert no. 48: Log injection
hein-obox 4eea648
Potential fix for code scanning alert no. 49: Log injection
hein-obox e77a0f5
Remove error logging
hein-obox 3771346
Update .github/scripts/send-slack-message.js
hein-obox a24161f
wip
hein-obox 6ad5140
Remove redundant exports
hein-obox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
.github/actions/theme-slack-notification-daily-tests/action.yml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| name: 'Theme Slack Notification (Daily Tests)' | ||
| description: 'Send Slack notification for Hello Elementor daily test failures' | ||
| inputs: | ||
| CLOUD_SLACK_BOT_TOKEN: | ||
| required: true | ||
| description: 'Slack bot token' | ||
| WORKFLOW_URL: | ||
| required: true | ||
| description: 'GitHub workflow run URL' | ||
| SLACK_CHANNEL: | ||
| required: false | ||
| default: '#tmz-alerts' | ||
| description: 'Slack channel to send notification to' | ||
|
|
||
| runs: | ||
| using: 'composite' | ||
| steps: | ||
| - name: Post to Slack | ||
| shell: bash | ||
| env: | ||
| CLOUD_SLACK_BOT_TOKEN: ${{ inputs.CLOUD_SLACK_BOT_TOKEN }} | ||
| WORKFLOW_URL: ${{ inputs.WORKFLOW_URL }} | ||
| SLACK_CHANNEL: ${{ inputs.SLACK_CHANNEL }} | ||
| run: | | ||
| node << 'NODE_SCRIPT' | ||
| const workflowUrl = process.env.WORKFLOW_URL || ''; | ||
| const slackChannel = process.env.SLACK_CHANNEL || '#tmz-alerts'; | ||
|
|
||
| const payload = { | ||
| text: 'Failing test alert', | ||
| blocks: [ | ||
| { | ||
| type: 'section', | ||
| text: { | ||
| type: 'mrkdwn', | ||
| text: '*Failing test alert*\n\n*Theme:* Hello Elementor\n*Test report:* <' + workflowUrl + '|View Workflow Run>' | ||
hein-obox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
| process.env.SLACK_PAYLOAD = JSON.stringify(payload); | ||
|
|
||
| const { execSync } = require('child_process'); | ||
| const path = require('path'); | ||
| const scriptPath = path.join(process.env.GITHUB_WORKSPACE, '.github/scripts/send-slack-message.js'); | ||
| execSync(`node "${scriptPath}"`, { stdio: 'inherit', env: process.env }); | ||
hein-obox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| NODE_SCRIPT | ||
|
|
||
| - name: Notification summary | ||
| shell: bash | ||
| run: | | ||
| echo "📢 Slack notification sent!" | ||
hein-obox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| echo " - Channel: ${{ inputs.SLACK_CHANNEL }}" | ||
| echo " - Workflow: ${{ inputs.WORKFLOW_URL }}" | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| name: 'Theme Slack Notification (Release)' | ||
| description: 'Send Slack notification for Hello Elementor release' | ||
| inputs: | ||
| SLACK_BOT_TOKEN: | ||
| CLOUD_SLACK_BOT_TOKEN: | ||
| required: true | ||
| description: 'Slack bot token' | ||
| PACKAGE_VERSION: | ||
|
|
@@ -15,7 +15,7 @@ inputs: | |
| description: 'GitHub release URL' | ||
| SLACK_CHANNEL: | ||
| required: false | ||
| default: '#general' | ||
| default: '#tmz-hello-delivery' | ||
| description: 'Slack channel to send notification to' | ||
| WPORG_DEPLOYMENT_STATUS: | ||
| required: false | ||
|
|
@@ -56,73 +56,94 @@ runs: | |
| fi | ||
|
|
||
| - name: Post to Slack | ||
| uses: slackapi/[email protected] | ||
| with: | ||
| channel-id: ${{ inputs.SLACK_CHANNEL }} | ||
| payload: | | ||
| { | ||
| "blocks": [ | ||
| { | ||
| "type": "header", | ||
| "text": { | ||
| "type": "plain_text", | ||
| "text": "🚀 Hello Elementor v${{ inputs.PACKAGE_VERSION }} Released!" | ||
| } | ||
| }, | ||
| { | ||
| "type": "section", | ||
| "text": { | ||
| "type": "mrkdwn", | ||
| "text": "*Hello Elementor theme* has been successfully released and is ready for distribution." | ||
| shell: bash | ||
| env: | ||
| CLOUD_SLACK_BOT_TOKEN: ${{ inputs.CLOUD_SLACK_BOT_TOKEN }} | ||
| SLACK_CHANNEL: ${{ inputs.SLACK_CHANNEL }} | ||
| PACKAGE_VERSION: ${{ inputs.PACKAGE_VERSION }} | ||
| FILE_SIZE_MB: ${{ env.FILE_SIZE_MB }} | ||
| DEPLOYMENT_MESSAGE: ${{ env.DEPLOYMENT_MESSAGE }} | ||
| GITHUB_RELEASE_URL: ${{ inputs.GITHUB_RELEASE_URL }} | ||
| BUILD_ZIP_PATH: ${{ inputs.BUILD_ZIP_PATH }} | ||
| run: | | ||
| node << 'NODE_SCRIPT' | ||
| const slackChannel = process.env.SLACK_CHANNEL || '#tmz-hello-delivery'; | ||
| const packageVersion = process.env.PACKAGE_VERSION || ''; | ||
| const fileSizeMb = process.env.FILE_SIZE_MB || 'Unknown'; | ||
| const deploymentMessage = (process.env.DEPLOYMENT_MESSAGE || '').replace(/\\n/g, '\n'); | ||
hein-obox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const githubReleaseUrl = process.env.GITHUB_RELEASE_URL || ''; | ||
| const buildZipPath = process.env.BUILD_ZIP_PATH || ''; | ||
|
|
||
| const payload = { | ||
| text: `Hello Elementor v${packageVersion} Released!`, | ||
| blocks: [ | ||
| { | ||
| type: 'header', | ||
| text: { | ||
| type: 'plain_text', | ||
| text: `🚀 Hello Elementor v${packageVersion} Released!` | ||
| } | ||
| }, | ||
| { | ||
| type: 'section', | ||
| text: { | ||
| type: 'mrkdwn', | ||
| text: '*Hello Elementor theme* has been successfully released and is ready for distribution.' | ||
| } | ||
| }, | ||
| { | ||
| type: 'section', | ||
| fields: [ | ||
| { | ||
| type: 'mrkdwn', | ||
| text: `*Version:*\nv${packageVersion}` | ||
| }, | ||
| { | ||
| type: 'mrkdwn', | ||
| text: `*Package Size:*\n${fileSizeMb}` | ||
| } | ||
| }, | ||
| { | ||
| "type": "section", | ||
| "fields": [ | ||
| { | ||
| "type": "mrkdwn", | ||
| "text": "*Version:*\nv${{ inputs.PACKAGE_VERSION }}" | ||
| ] | ||
| }, | ||
| { | ||
| type: 'section', | ||
| text: { | ||
| type: 'mrkdwn', | ||
| text: deploymentMessage | ||
| } | ||
| }, | ||
| { | ||
| type: 'actions', | ||
| elements: [ | ||
| { | ||
| type: 'button', | ||
| text: { | ||
| type: 'plain_text', | ||
| text: '📥 Download Release' | ||
| }, | ||
| { | ||
| "type": "mrkdwn", | ||
| "text": "*Package Size:*\n${{ env.FILE_SIZE_MB }}" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "type": "section", | ||
| "text": { | ||
| "type": "mrkdwn", | ||
| "text": "${{ env.DEPLOYMENT_MESSAGE }}" | ||
| url: githubReleaseUrl, | ||
| style: 'primary' | ||
| } | ||
| }, | ||
| { | ||
| "type": "actions", | ||
| "elements": [ | ||
| { | ||
| "type": "button", | ||
| "text": { | ||
| "type": "plain_text", | ||
| "text": "📥 Download Release" | ||
| }, | ||
| "url": "${{ inputs.GITHUB_RELEASE_URL }}", | ||
| "style": "primary" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "type": "context", | ||
| "elements": [ | ||
| { | ||
| "type": "mrkdwn", | ||
| "text": "Build: ${{ inputs.BUILD_ZIP_PATH }}" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| env: | ||
| SLACK_BOT_TOKEN: ${{ inputs.SLACK_BOT_TOKEN }} | ||
| ] | ||
| }, | ||
| { | ||
| type: 'context', | ||
| elements: [ | ||
| { | ||
| type: 'mrkdwn', | ||
| text: `Build: ${buildZipPath}` | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
| process.env.SLACK_PAYLOAD = JSON.stringify(payload); | ||
|
|
||
| const { execSync } = require('child_process'); | ||
| const path = require('path'); | ||
| const scriptPath = path.join(process.env.GITHUB_WORKSPACE, '.github/scripts/send-slack-message.js'); | ||
| execSync(`node "${scriptPath}"`, { stdio: 'inherit', env: process.env }); | ||
hein-obox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| NODE_SCRIPT | ||
|
|
||
| - name: Notification summary | ||
| shell: bash | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| const https = require('https'); | ||
hein-obox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const slackToken = process.env.CLOUD_SLACK_BOT_TOKEN || ''; | ||
| const slackChannel = process.env.SLACK_CHANNEL || '#tmz-alerts'; | ||
hein-obox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const payloadJson = process.env.SLACK_PAYLOAD || '{}'; | ||
|
|
||
| if (!slackToken) { | ||
| console.log('⚠️ Slack token not provided, skipping notification'); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| let payload; | ||
| try { | ||
| payload = JSON.parse(payloadJson); | ||
| payload.channel = slackChannel; | ||
hein-obox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } catch (error) { | ||
| console.error('Failed to parse payload:', error.message); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const payloadStr = JSON.stringify(payload); | ||
| const data = Buffer.from(payloadStr, 'utf8'); | ||
|
|
||
| const options = { | ||
| hostname: 'slack.com', | ||
| port: 443, | ||
| path: '/api/chat.postMessage', | ||
| method: 'POST', | ||
| headers: { | ||
| 'Authorization': `Bearer ${slackToken}`, | ||
| 'Content-Type': 'application/json', | ||
| 'Content-Length': data.length | ||
| } | ||
| }; | ||
|
|
||
| const req = https.request(options, (res) => { | ||
| let responseData = ''; | ||
| res.on('data', (chunk) => { | ||
| responseData += chunk; | ||
| }); | ||
| res.on('end', () => { | ||
| const response = JSON.parse(responseData); | ||
hein-obox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (res.statusCode === 200 && response.ok) console.log('✅ Slack notification sent'); | ||
hein-obox marked this conversation as resolved.
Show resolved
Hide resolved
hein-obox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| process.exit(0); | ||
| }); | ||
| }); | ||
|
|
||
| req.on('error', (error) => { | ||
| console.error('Failed to send Slack notification'); | ||
| process.exit(0); | ||
hein-obox marked this conversation as resolved.
Show resolved
Hide resolved
hein-obox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| req.write(data); | ||
| req.end(); | ||
|
|
||
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.