woocommerce/.github/actions/tests/slack-summary-daily/scripts/construct-slack-payload.js

94 lines
1.7 KiB
JavaScript
Raw Normal View History

2023-08-16 00:14:22 +00:00
module.exports = ( { core } ) => {
2023-08-16 04:47:25 +00:00
const {
API_RESULT,
E2E_RESULT,
k6_RESULT,
PLUGINS_BLOCKS_PATH,
GITHUB_RUN_ID,
} = process.env;
2023-08-16 00:14:22 +00:00
const {
selectEmoji,
readContextBlocksFromJsonFiles,
} = require( './utils' );
2023-08-15 08:53:29 +00:00
2023-08-16 00:14:22 +00:00
const block_header = {
type: 'header',
text: {
type: 'plain_text',
text: 'Daily test results',
emoji: true,
},
};
2023-08-15 08:53:29 +00:00
2023-08-16 00:14:22 +00:00
const emoji_API = selectEmoji( API_RESULT );
const emoji_E2E = selectEmoji( E2E_RESULT );
const emoji_k6 = selectEmoji( k6_RESULT );
2023-08-16 04:47:25 +00:00
const blockGroup_nightlySite = [
{
type: 'section',
text: {
2023-08-16 00:14:22 +00:00
type: 'mrkdwn',
text: '*Smoke tests on daily build*',
},
2023-08-16 04:47:25 +00:00
},
{
type: 'context',
elements: [
{
type: 'mrkdwn',
text: `API ${ emoji_API }\tE2E ${ emoji_E2E }\tk6 ${ emoji_k6 }`,
},
],
},
{
type: 'divider',
},
];
const blockGroups_plugins =
readContextBlocksFromJsonFiles( PLUGINS_BLOCKS_PATH );
const block_github = {
type: 'actions',
elements: [
2023-08-16 00:14:22 +00:00
{
2023-08-16 04:47:25 +00:00
type: 'button',
text: {
type: 'plain_text',
text: 'View GitHub run logs :github:',
emoji: true,
},
url: `https://github.com/woocommerce/woocommerce/actions/runs/${ GITHUB_RUN_ID }`,
2023-08-16 00:14:22 +00:00
},
2023-08-16 04:47:25 +00:00
],
};
const block_dashboard = {
type: 'actions',
elements: [
2023-08-16 00:14:22 +00:00
{
2023-08-16 04:47:25 +00:00
type: 'button',
text: {
type: 'plain_text',
text: 'Open test reports dashboard :colorful-bar-chart:',
emoji: true,
},
url: 'https://woocommerce.github.io/woocommerce-test-reports/daily/',
2023-08-16 00:14:22 +00:00
},
],
};
2023-08-15 08:53:29 +00:00
2023-08-16 00:14:22 +00:00
const payload = {
2023-08-16 04:47:25 +00:00
blocks: [
block_header,
...blockGroup_nightlySite,
...blockGroups_plugins.flat(),
block_github,
block_dashboard,
],
2023-08-16 00:14:22 +00:00
};
2023-08-15 08:53:29 +00:00
2023-08-16 00:14:22 +00:00
const payload_stringified = JSON.stringify( payload );
2023-08-15 08:53:29 +00:00
2023-08-16 01:07:56 +00:00
core.setOutput( 'payload', payload_stringified );
2023-08-16 00:14:22 +00:00
};