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

132 lines
2.6 KiB
JavaScript
Raw Normal View History

2023-08-17 03:37:42 +00:00
module.exports = async ( { context, core, github } ) => {
2023-08-16 04:47:25 +00:00
const {
API_RESULT,
E2E_RESULT,
k6_RESULT,
PLUGINS_BLOCKS_PATH,
2023-08-17 00:51:49 +00:00
GITHUB_REF_NAME,
2023-08-16 04:47:25 +00:00
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-17 03:37:42 +00:00
const create_blockGroup_header = async () => {
const response = await github.rest.actions.getWorkflowRun( {
owner: context.repo.owner,
repo: context.repo.repo,
run_id: GITHUB_RUN_ID,
} );
const runStartedAt = new Date( response.data.run_started_at );
const intlDateTimeFormatOptions = {
2023-08-17 00:51:49 +00:00
dateStyle: 'full',
2023-08-17 03:37:42 +00:00
timeStyle: 'long',
};
const date = new Intl.DateTimeFormat(
'en-US',
intlDateTimeFormatOptions
).format( runStartedAt );
2023-08-15 08:53:29 +00:00
2023-08-17 00:54:21 +00:00
const blocks = [
2023-08-16 00:14:22 +00:00
{
2023-08-17 00:51:49 +00:00
type: 'header',
2023-08-16 04:47:25 +00:00
text: {
type: 'plain_text',
2023-08-17 00:51:49 +00:00
text: 'Daily test results',
2023-08-16 04:47:25 +00:00
emoji: true,
},
2023-08-16 00:14:22 +00:00
},
2023-08-17 02:30:23 +00:00
{
type: 'divider',
},
2023-08-17 00:51:49 +00:00
{
type: 'context',
elements: [
{
type: 'mrkdwn',
2023-08-17 03:39:47 +00:00
text: `*Run started:* ${ date }`,
2023-08-17 00:51:49 +00:00
},
],
},
{
type: 'context',
elements: [
{
type: 'mrkdwn',
text: `*Branch:* \`${ GITHUB_REF_NAME }\``,
},
],
},
{
type: 'context',
elements: [
{
type: 'mrkdwn',
text: `*GitHub run logs:* <https://github.com/woocommerce/woocommerce/actions/runs/${ GITHUB_RUN_ID }|${ GITHUB_RUN_ID }>`,
},
],
},
{
type: 'context',
elements: [
{
type: 'mrkdwn',
text: '*Test reports dashboard:* <https://woocommerce.github.io/woocommerce-test-reports/daily/|Daily smoke tests>',
},
],
},
{
type: 'divider',
},
];
2023-08-17 00:54:21 +00:00
return blocks;
2023-08-16 04:47:25 +00:00
};
2023-08-17 00:51:49 +00:00
const create_blockGroup_nightlySite = () => {
const emoji_API = selectEmoji( API_RESULT );
const emoji_E2E = selectEmoji( E2E_RESULT );
const emoji_k6 = selectEmoji( k6_RESULT );
2023-08-17 00:54:21 +00:00
const blocks = [
2023-08-16 00:14:22 +00:00
{
2023-08-17 00:51:49 +00:00
type: 'section',
2023-08-16 04:47:25 +00:00
text: {
2023-08-17 00:51:49 +00:00
type: 'mrkdwn',
text: '*Smoke tests on daily build*',
2023-08-16 04:47:25 +00:00
},
2023-08-16 00:14:22 +00:00
},
2023-08-17 00:51:49 +00:00
{
type: 'context',
elements: [
{
type: 'mrkdwn',
text: `API ${ emoji_API }\tE2E ${ emoji_E2E }\tk6 ${ emoji_k6 }`,
},
],
},
{
type: 'divider',
},
];
2023-08-17 00:54:21 +00:00
return blocks;
2023-08-16 00:14:22 +00:00
};
2023-08-15 08:53:29 +00:00
2023-08-17 03:37:42 +00:00
const blockGroup_header = await create_blockGroup_header();
2023-08-17 00:51:49 +00:00
const blockGroup_nightlySite = create_blockGroup_nightlySite();
const blockGroups_plugins =
readContextBlocksFromJsonFiles( PLUGINS_BLOCKS_PATH );
2023-08-16 00:14:22 +00:00
const payload = {
2023-08-16 04:47:25 +00:00
blocks: [
2023-08-17 00:51:49 +00:00
...blockGroup_header,
2023-08-16 04:47:25 +00:00
...blockGroup_nightlySite,
...blockGroups_plugins.flat(),
],
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
};