diff --git a/.github/actions/theme-slack-notification-daily-tests/action.yml b/.github/actions/theme-slack-notification-daily-tests/action.yml new file mode 100644 index 00000000..cec85b0a --- /dev/null +++ b/.github/actions/theme-slack-notification-daily-tests/action.yml @@ -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>' + } + } + ] + }; + + 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 }); + NODE_SCRIPT + + - name: Notification summary + shell: bash + run: | + echo "📢 Slack notification sent!" + echo " - Channel: ${{ inputs.SLACK_CHANNEL }}" + echo " - Workflow: ${{ inputs.WORKFLOW_URL }}" + diff --git a/.github/actions/theme-slack-notification-release/action.yml b/.github/actions/theme-slack-notification-release/action.yml index a599ccbf..03c1a60f 100644 --- a/.github/actions/theme-slack-notification-release/action.yml +++ b/.github/actions/theme-slack-notification-release/action.yml @@ -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/slack-github-action@v1.23.0 - 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'); + 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 }); + NODE_SCRIPT - name: Notification summary shell: bash diff --git a/.github/scripts/send-slack-message.js b/.github/scripts/send-slack-message.js new file mode 100644 index 00000000..dbd9e5cc --- /dev/null +++ b/.github/scripts/send-slack-message.js @@ -0,0 +1,55 @@ +const https = require('https'); + +const slackToken = process.env.CLOUD_SLACK_BOT_TOKEN || ''; +const slackChannel = process.env.SLACK_CHANNEL || '#tmz-alerts'; +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; +} 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); + if (res.statusCode === 200 && response.ok) console.log('✅ Slack notification sent'); + process.exit(0); + }); +}); + +req.on('error', (error) => { + console.error('Failed to send Slack notification'); + process.exit(0); +}); + +req.write(data); +req.end(); + diff --git a/.github/workflows/daily-test-matrix.yml b/.github/workflows/daily-test-matrix.yml index eef76016..d693bec9 100644 --- a/.github/workflows/daily-test-matrix.yml +++ b/.github/workflows/daily-test-matrix.yml @@ -728,3 +728,12 @@ jobs: } else { console.log(`✅ Daily test matrix completed successfully: ${summary.success} passed out of ${summary.total} tests`); } + + - name: Send Slack notification on failure + if: failure() + continue-on-error: true + uses: ./.github/actions/theme-slack-notification-daily-tests + with: + CLOUD_SLACK_BOT_TOKEN: ${{ secrets.CLOUD_SLACK_BOT_TOKEN }} + WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + SLACK_CHANNEL: '#tmz-alerts' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 70ca0a55..1dcba52a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -526,7 +526,7 @@ jobs: if: ${{ inputs.dry_run == false && inputs.deploy_to_wporg == true }} uses: ./.github/actions/theme-slack-notification-release with: - SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + CLOUD_SLACK_BOT_TOKEN: ${{ secrets.CLOUD_SLACK_BOT_TOKEN }} PACKAGE_VERSION: ${{ env.PACKAGE_VERSION }} BUILD_ZIP_PATH: ${{ env.BUILD_ZIP_PATH }} GITHUB_RELEASE_URL: ${{ env.RELEASE_URL }}