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-09-01 05:13:46 +00:00
|
|
|
PLUGIN_TESTS_RESULT,
|
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-23 00:46:17 +00:00
|
|
|
const URL_GITHUB_RUN_LOG = `https://github.com/woocommerce/woocommerce/actions/runs/${ GITHUB_RUN_ID }`;
|
|
|
|
|
2023-08-17 03:37:42 +00:00
|
|
|
const create_blockGroup_header = async () => {
|
2023-08-17 03:51:02 +00:00
|
|
|
const getRunStartDate = 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 = {
|
|
|
|
dateStyle: 'full',
|
|
|
|
timeStyle: 'long',
|
|
|
|
};
|
|
|
|
const date = new Intl.DateTimeFormat(
|
|
|
|
'en-US',
|
|
|
|
intlDateTimeFormatOptions
|
|
|
|
).format( runStartedAt );
|
|
|
|
|
|
|
|
return date;
|
2023-08-17 03:37:42 +00:00
|
|
|
};
|
2023-08-17 03:51:02 +00:00
|
|
|
|
|
|
|
const readableDate = await getRunStartDate();
|
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:51:02 +00:00
|
|
|
text: `*Run started:* ${ readableDate }`,
|
2023-08-17 00:51:49 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'context',
|
|
|
|
elements: [
|
|
|
|
{
|
|
|
|
type: 'mrkdwn',
|
|
|
|
text: `*Branch:* \`${ GITHUB_REF_NAME }\``,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'context',
|
|
|
|
elements: [
|
|
|
|
{
|
|
|
|
type: 'mrkdwn',
|
2023-08-23 00:46:17 +00:00
|
|
|
text: `*GitHub run logs:* <${ URL_GITHUB_RUN_LOG }|${ GITHUB_RUN_ID }>`,
|
2023-08-17 00:51:49 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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-23 00:46:17 +00:00
|
|
|
const url_API =
|
|
|
|
'https://woocommerce.github.io/woocommerce-test-reports/daily/nightly-site/api';
|
|
|
|
const url_E2E =
|
|
|
|
'https://woocommerce.github.io/woocommerce-test-reports/daily/nightly-site/e2e';
|
|
|
|
const url_k6 = URL_GITHUB_RUN_LOG;
|
2023-08-17 00:51:49 +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: 'section',
|
2023-08-16 04:47:25 +00:00
|
|
|
text: {
|
2023-08-17 00:51:49 +00:00
|
|
|
type: 'mrkdwn',
|
2023-09-14 07:32:50 +00:00
|
|
|
text: `<${ URL_GITHUB_RUN_LOG }|*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',
|
2023-08-23 00:46:17 +00:00
|
|
|
text: `<${ url_API }|API> ${ emoji_API }\t<${ url_E2E }|E2E> ${ emoji_E2E }\t<${ url_k6 }|k6> ${ emoji_k6 }`,
|
2023-08-17 00:51:49 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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-09-01 03:35:37 +00:00
|
|
|
const create_blockGroups_plugins = () => {
|
2023-09-01 05:13:46 +00:00
|
|
|
const pluginTestsSkipped = PLUGIN_TESTS_RESULT === 'skipped';
|
|
|
|
const blocks_pluginTestsSkipped = [
|
2023-09-01 03:35:37 +00:00
|
|
|
{
|
|
|
|
type: 'section',
|
|
|
|
text: {
|
|
|
|
type: 'mrkdwn',
|
|
|
|
text: ':warning: *Plugin tests were not run!*',
|
|
|
|
},
|
|
|
|
},
|
2023-09-01 05:13:46 +00:00
|
|
|
{
|
|
|
|
type: 'context',
|
|
|
|
elements: [
|
|
|
|
{
|
|
|
|
type: 'mrkdwn',
|
|
|
|
text: `Head over to the <${ URL_GITHUB_RUN_LOG }|GitHub workflow run log> to see what went wrong.`,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2023-09-01 03:35:37 +00:00
|
|
|
{
|
|
|
|
type: 'divider',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2023-09-01 05:13:46 +00:00
|
|
|
return pluginTestsSkipped
|
|
|
|
? blocks_pluginTestsSkipped
|
|
|
|
: readContextBlocksFromJsonFiles( PLUGINS_BLOCKS_PATH );
|
2023-09-01 03:35:37 +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();
|
2023-09-01 03:35:37 +00:00
|
|
|
const blockGroups_plugins = create_blockGroups_plugins();
|
2023-08-23 01:09:17 +00:00
|
|
|
const blocks_all = [
|
2023-08-23 00:46:17 +00:00
|
|
|
...blockGroup_header,
|
|
|
|
...blockGroup_nightlySite,
|
|
|
|
...blockGroups_plugins.flat(),
|
|
|
|
];
|
2023-08-16 00:14:22 +00:00
|
|
|
const payload = {
|
2023-08-23 00:46:17 +00:00
|
|
|
text: 'Daily test results',
|
2023-08-23 01:09:17 +00:00
|
|
|
blocks: blocks_all,
|
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
|
|
|
};
|