Send Slack summary of release test results (#38180)

Check out files from WIP branch
This commit is contained in:
rodelgc 2023-05-12 05:29:12 +08:00 committed by GitHub
parent 36d4ad1150
commit 68fe31abe4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 385 additions and 3 deletions

View File

@ -9,6 +9,11 @@ inputs:
tests:
description: Specific tests to run, separated by single whitespace. See https://playwright.dev/docs/test-cli
outputs:
result:
description: Whether the test passed or failed.
value: ${{ steps.run-api-tests.conclusion }}
runs:
using: composite
steps:

View File

@ -12,6 +12,11 @@ inputs:
description: The Playwright configuration file to use.
default: playwright.config.js
outputs:
result:
description: Whether the test passed or failed.
value: ${{ steps.run-e2e-tests.conclusion }}
runs:
using: composite
steps:

View File

@ -0,0 +1,59 @@
name: Compose a Slack block for release tests
description: Create a Slack block that shows the API and E2E test results from one of the release tests, and upload it as an artifact.
permissions: {}
inputs:
test-name:
required: true
api-result:
required: true
type: choice
default: skipped
options:
- success
- failure
- cancelled
- skipped
e2e-result:
required: true
type: choice
default: skipped
options:
- success
- failure
- cancelled
- skipped
env-slug:
required: true
release-version:
required: true
runs:
using: composite
steps:
- name: Create context block as a JSON object
id: generate-json
uses: actions/github-script@v6
with:
script: |
const script = require('./.github/actions/tests/slack-summary-on-release/slack-blocks/scripts/create-result-block');
return script();
env:
API_RESULT: ${{ inputs.api-result }}
E2E_RESULT: ${{ inputs.e2e-result }}
ENV_SLUG: ${{ inputs.env-slug }}
TEST_NAME: ${{ inputs.test-name }}
RELEASE_VERSION: ${{ inputs.release-version }}
- name: Write JSON file
working-directory: /tmp
shell: bash
env:
CONTEXT_JSON: ${{ toJSON(steps.generate-json.outputs.result) }}
run: echo ${{ env.CONTEXT_JSON }} > "${{ inputs.test-name }}.json"
- name: Upload JSON file as artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.SLACK_BLOCKS_ARTIFACT }}
path: /tmp/${{ inputs.test-name }}.json

View File

@ -0,0 +1,31 @@
module.exports = () => {
const { API_RESULT, E2E_RESULT, ENV_SLUG, TEST_NAME, RELEASE_VERSION } =
process.env;
const { setElementText } = require( './utils' );
const apiLinkText = setElementText( {
testType: 'API',
result: API_RESULT,
envSlug: ENV_SLUG,
releaseVersion: RELEASE_VERSION,
} );
const e2eLinkText = setElementText( {
testType: 'E2E',
result: E2E_RESULT,
envSlug: ENV_SLUG,
releaseVersion: RELEASE_VERSION,
} );
const elementText = `*${ TEST_NAME }*\n ${ apiLinkText } ${ e2eLinkText }`;
const contextBlock = {
type: 'context',
elements: [
{
type: 'mrkdwn',
text: elementText,
},
],
};
return contextBlock;
};

View File

@ -0,0 +1,5 @@
const { setElementText } = require( './set-element-text' );
module.exports = {
setElementText,
};

View File

@ -0,0 +1,26 @@
const emojis = {
PASSED: ':workflow-passed:',
FAILED: ':workflow-failed:',
SKIPPED: ':workflow-skipped:',
CANCELLED: ':workflow-cancelled:',
UNKNOWN: ':grey_question:',
};
const selectEmoji = ( result ) => {
switch ( result ) {
case 'success':
return emojis.PASSED;
case 'failure':
return emojis.FAILED;
case 'skipped':
return emojis.SKIPPED;
case 'cancelled':
return emojis.CANCELLED;
default:
return emojis.UNKNOWN;
}
};
module.exports = {
selectEmoji,
};

View File

@ -0,0 +1,12 @@
const setElementText = ( { testType, result, envSlug, releaseVersion } ) => {
const { selectEmoji } = require( './select-emoji' );
const allureReportURL = `https://woocommerce.github.io/woocommerce-test-reports/release/${ releaseVersion }/${ envSlug }/${ testType.toLowerCase() }`;
const emoji = selectEmoji( result );
const textValue = `<${ allureReportURL }|${ testType.toUpperCase() } ${ emoji }>`;
return textValue;
};
module.exports = {
setElementText,
};

View File

@ -0,0 +1,27 @@
name: Combine all Slack blocks
description: Combine all Slack blocks to construct the payload for the Slack GitHub action
permissions: {}
inputs:
release-version:
required: true
blocks-dir:
require: true
outputs:
payload:
value: ${{ steps.payload.outputs.result }}
runs:
using: composite
steps:
- name: Construct payload from all blocks
id: payload
uses: actions/github-script@v6
env:
RELEASE_VERSION: ${{ inputs.release-version }}
BLOCKS_DIR: ${{ inputs.blocks-dir }}
with:
script: |
const script = require('./.github/actions/tests/slack-summary-on-release/slack-payload/scripts/construct-payload');
return script();

View File

@ -0,0 +1,36 @@
module.exports = () => {
const { RELEASE_VERSION, BLOCKS_DIR } = process.env;
const {
filterContextBlocks,
readContextBlocksFromJsonFiles,
} = require( './utils' );
const headerText = `Test summary for ${ RELEASE_VERSION }`;
const headerBlock = {
type: 'header',
text: {
type: 'plain_text',
text: headerText,
emoji: true,
},
};
const blocks_all = readContextBlocksFromJsonFiles( BLOCKS_DIR );
const blocks_wcUpdate = filterContextBlocks( blocks_all, 'WC Update' );
const blocks_wpVersions = filterContextBlocks( blocks_all, 'WP Latest' );
const blocks_phpVersions = filterContextBlocks( blocks_all, 'PHP' );
const blocks_plugins = filterContextBlocks( blocks_all, 'With' );
const blocksPayload = [ headerBlock ]
.concat( blocks_wcUpdate )
.concat( blocks_wpVersions )
.concat( blocks_phpVersions )
.concat( blocks_plugins );
const payload = {
text: headerText,
blocks: blocksPayload,
};
return payload;
};

View File

@ -0,0 +1,42 @@
const fs = require( 'fs' );
const path = require( 'path' );
const readContextBlocksFromJsonFiles = ( blocksDir ) => {
const jsonsDir = path.resolve( blocksDir );
const jsons = fs.readdirSync( jsonsDir );
let contextBlocks = [];
for ( const json of jsons ) {
const jsonPath = path.resolve( jsonsDir, json );
const contextBlock = require( jsonPath );
contextBlocks.push( contextBlock );
}
return contextBlocks;
};
const filterContextBlocks = ( blocks, testName ) => {
const divider = {
type: 'divider',
};
let filteredBlocks = [];
const matchingBlocks = blocks.filter( ( { elements } ) =>
elements[ 0 ].text.includes( testName )
);
matchingBlocks.forEach( ( block ) => {
filteredBlocks.push( block );
filteredBlocks.push( divider );
} );
return filteredBlocks;
};
module.exports = {
filterContextBlocks,
readContextBlocksFromJsonFiles,
};

View File

@ -0,0 +1,6 @@
const {
filterContextBlocks,
readContextBlocksFromJsonFiles,
} = require( './get-context-blocks' );
module.exports = { filterContextBlocks, readContextBlocksFromJsonFiles };

View File

@ -14,7 +14,7 @@ permissions: {}
env:
E2E_WP_LATEST_ARTIFACT: E2E test on release smoke test site with WP Latest (run ${{ github.run_number }})
E2E_UPDATE_WC_ARTIFACT: WooCommerce version update test on release smoke test site (run ${{ github.run_number }})
SLACK_BLOCKS_ARTIFACT: slack-blocks
jobs:
get-tag:
name: Get WooCommerce release tag
@ -122,12 +122,26 @@ jobs:
-f test_type="e2e" \
--repo woocommerce/woocommerce-test-reports
- name: Create Slack block
if: |
success() || (
failure() && steps.run-e2e-composite-action.outputs.result == 'failure'
)
uses: ./.github/actions/tests/slack-summary-on-release/slack-blocks
with:
test-name: WC Update test
e2e-result: ${{ steps.run-e2e-composite-action.outputs.result }}
env-slug: wp-latest
release-version: ${{ needs.get-tag.outputs.tag }}
api-wp-latest:
name: API on WP Latest
runs-on: ubuntu-20.04
needs: [get-tag, e2e-update-wc]
permissions:
contents: read
outputs:
result: ${{ steps.run-api-composite-action.outputs.result }}
env:
ALLURE_REPORT_DIR: ${{ github.workspace }}/plugins/woocommerce/tests/api-core-tests/api-test-report/allure-report
ALLURE_RESULTS_DIR: ${{ github.workspace }}/plugins/woocommerce/tests/api-core-tests/api-test-report/allure-results
@ -178,6 +192,18 @@ jobs:
-f test_type="api" \
--repo woocommerce/woocommerce-test-reports
- name: Create Slack block
if: |
success() || (
failure() && steps.run-api-composite-action.outputs.result == 'failure'
)
uses: ./.github/actions/tests/slack-summary-on-release/slack-blocks
with:
test-name: WP Latest
api-result: ${{ steps.run-api-composite-action.outputs.result }}
env-slug: wp-latest
release-version: ${{ needs.get-tag.outputs.tag }}
e2e-wp-latest:
name: E2E on WP Latest
runs-on: ubuntu-20.04
@ -268,6 +294,19 @@ jobs:
-f test_type="e2e" \
--repo woocommerce/woocommerce-test-reports
- name: Create Slack block
if: |
success() || (
failure() && steps.run-e2e-composite-action.outputs.result == 'failure'
)
uses: ./.github/actions/tests/slack-summary-on-release/slack-blocks
with:
test-name: WP Latest
api-result: ${{ needs.api-wp-latest.outputs.result }}
e2e-result: ${{ steps.run-e2e-composite-action.outputs.result }}
env-slug: wp-latest
release-version: ${{ needs.get-tag.outputs.tag }}
get-wp-versions:
name: Get WP L-1 & L-2 version numbers
needs: [get-tag]
@ -328,6 +367,8 @@ jobs:
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
build-filters: woocommerce
- name: Launch WP Env
working-directory: plugins/woocommerce
@ -360,7 +401,7 @@ jobs:
uses: ./.github/actions/tests/run-api-tests
with:
report-name: ${{ env.API_WP_LATEST_X_ARTIFACT }}
tests: hello
tests: hello.test.js
env:
ALLURE_RESULTS_DIR: ${{ env.API_ALLURE_RESULTS_DIR }}
ALLURE_REPORT_DIR: ${{ env.API_ALLURE_REPORT_DIR }}
@ -435,6 +476,22 @@ jobs:
-f test_type="e2e" \
--repo woocommerce/woocommerce-test-reports
- name: Create Slack block
if: |
success() || (
failure() && (
steps.run-api-composite-action.outputs.result == 'failure' ||
steps.run-e2e-composite-action.outputs.result == 'failure'
)
)
uses: ./.github/actions/tests/slack-summary-on-release/slack-blocks
with:
test-name: ${{ matrix.version.description }} (${{ matrix.version.number }})
api-result: ${{ steps.run-api-composite-action.outputs.result }}
e2e-result: ${{ steps.run-e2e-composite-action.outputs.result }}
env-slug: ${{ matrix.version.env_description }}
release-version: ${{ needs.get-wp-versions.outputs.tag }}
test-php-versions:
name: Test against PHP ${{ matrix.php_version }}
runs-on: ubuntu-20.04
@ -456,6 +513,8 @@ jobs:
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
build-filters: woocommerce
- name: Launch WP Env
working-directory: plugins/woocommerce
@ -482,7 +541,7 @@ jobs:
uses: ./.github/actions/tests/run-api-tests
with:
report-name: ${{ env.API_ARTIFACT }}
tests: hello
tests: hello.test.js
env:
ALLURE_RESULTS_DIR: ${{ env.API_ALLURE_RESULTS_DIR }}
ALLURE_REPORT_DIR: ${{ env.API_ALLURE_REPORT_DIR }}
@ -557,6 +616,22 @@ jobs:
-f test_type="e2e" \
--repo woocommerce/woocommerce-test-reports
- name: Create Slack block
if: |
success() || (
failure() && (
steps.run-api-composite-action.outputs.result == 'failure' ||
steps.run-e2e-composite-action.outputs.result == 'failure'
)
)
uses: ./.github/actions/tests/slack-summary-on-release/slack-blocks
with:
test-name: PHP ${{ matrix.php_version }}
api-result: ${{ steps.run-api-composite-action.outputs.result }}
e2e-result: ${{ steps.run-e2e-composite-action.outputs.result }}
env-slug: php-${{ matrix.php_version }}
release-version: ${{ needs.get-tag.outputs.tag }}
test-plugins:
name: With ${{ matrix.plugin }}
runs-on: ubuntu-20.04
@ -594,6 +669,8 @@ jobs:
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
build-filters: woocommerce
- name: Launch WP Env
working-directory: plugins/woocommerce
@ -656,3 +733,54 @@ jobs:
-f env_description="${{ matrix.env_description }}" \
-f test_type="e2e" \
--repo woocommerce/woocommerce-test-reports
- name: Create Slack block
if: |
success() || (
failure() && steps.run-e2e-composite-action.outputs.result == 'failure' )
uses: ./.github/actions/tests/slack-summary-on-release/slack-blocks
with:
test-name: With ${{ matrix.plugin }}
e2e-result: ${{ steps.run-e2e-composite-action.outputs.result }}
env-slug: ${{ matrix.env_description }}
release-version: ${{ needs.get-tag.outputs.tag }}
post-slack-summary:
name: Post Slack summary
runs-on: ubuntu-20.04
permissions:
contents: read
if: |
success() || (
failure() && contains( needs.*.result, 'failure' )
)
needs:
- e2e-wp-latest
- get-tag
- test-php-versions
- test-plugins
- test-wp-versions
steps:
- uses: actions/checkout@v3
- name: Download all slack blocks
id: download-slack-blocks
uses: actions/download-artifact@v3
with:
name: ${{ env.SLACK_BLOCKS_ARTIFACT }}
path: /tmp/slack-payload
- name: Construct payload from all blocks
id: run-payload-action
uses: ./.github/actions/tests/slack-summary-on-release/slack-payload
with:
release-version: ${{ needs.get-tag.outputs.tag }}
blocks-dir: ${{ steps.download-slack-blocks.outputs.download-path }}
- name: Send Slack message
uses: slackapi/slack-github-action@v1.23.0
with:
channel-id: ${{ secrets.RELEASE_TEST_SLACK_CHANNEL }}
payload: ${{ steps.run-payload-action.outputs.payload }}
env:
SLACK_BOT_TOKEN: ${{ secrets.E2E_SLACK_TOKEN }}