Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub Action to report test failures in the workflow summary #6076

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions .github/actions/test-summary-report/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

name: 'Test Summary Report'
description: 'Parses JUnit test reports and publishes them to the GitHub workflow summary'
inputs:
test-report-xml-base-dir:
description: 'The base directory from which to search for JUnit XML reports'
required: true
default: '.'
test-report-xml-includes:
description: 'The path glob for files to examine when generating the test report summary'
required: true
default: '**/target/*-reports/TEST-*.xml'

runs:
using: "composite"
steps:
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install script dependencies
shell: bash
run: |
npm install junit2json
- name: Generate test summary
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const junit = require('junit2json');
const testReportGlobPattern = "${{ inputs.test-report-xml-base-dir }}/${{ inputs.test-report-xml-includes }}".replace(/\.+\/+/g, "")
const summaryData = [];

// Configure test summary table headers
summaryData.push([
{data: 'Test Class', header: true},
{data: 'Test Name', header: true},
{data: 'Failure', header: true},
{data: 'Details', header: true}
]);

// Iterate and parse surefire / failsafe reports and use the info to build the summary
const globber = await glob.create(testReportGlobPattern);
for await (const reportFile of globber.globGenerator()) {
const file = fs.readFileSync(reportFile);
const report = junit.parse(file).then((report) => {
if (report.errors > 0 || report.failures > 0) {
report.testcase.forEach((testCase) => {
if (testCase.failure !== undefined) {
const shortClassName = `<code>${testCase.classname.substring(testCase.classname.lastIndexOf('.') + 1)}</code>`;
const className = `<details><summary>${shortClassName}</summary>\n<code>${testCase.classname}</code></details>`;
const details = `<details><summary>View</summary>\n<pre>${testCase.failure[0].inner}</pre></details>`;
let testName = `<code>${testCase.name}</code>`;
if (testCase.length > 25) {
testName = `<details><summary>View</summary>\n<code>${testCase.name}</code></details>`;
}

let message = `<pre>${testCase.failure[0].message}</pre>`;
if (message.length > 50) {
message = `<details><summary>View</summary>\n${message}</details>`;
}
summaryData.push([className, testName, message, details]);
}
});
}
});
}

// Write the summary data if there were test failures
if (summaryData.length > 1) {
await core.summary
.addHeading("Test Failures", "3")
.addTable(summaryData)
.write();
}
50 changes: 49 additions & 1 deletion .github/workflows/camel-master-cron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ jobs:
--fail-at-end \
-pl "${NATIVE_MODULES[*]}"
fi
- name: Report test failures
uses: ./.github/actions/test-summary-report
if: ${{ failure() }}
with:
test-report-xml-base-dir: integration-tests
- name: Fail if there are uncommitted changes
shell: bash
run: |
Expand Down Expand Up @@ -258,33 +263,58 @@ jobs:
-Dformatter.skip -Dimpsort.skip -Denforcer.skip -Dcamel-quarkus.update-extension-doc-page.skip \
--fail-at-end \
test
- name: Report test failures
uses: ./.github/actions/test-summary-report
if: ${{ failure() }}
with:
test-report-xml-base-dir: extensions-core
- name: cd extensions && mvn test
run: |
cd extensions
../mvnw ${CQ_MAVEN_ARGS} \
-Dformatter.skip -Dimpsort.skip -Denforcer.skip -Dcamel-quarkus.update-extension-doc-page.skip \
--fail-at-end \
test
- name: Report test failures
uses: ./.github/actions/test-summary-report
if: ${{ failure() }}
with:
test-report-xml-base-dir: extensions
- name: cd test-framework && mvn test
run: |
cd test-framework
../mvnw ${CQ_MAVEN_ARGS} \
-Dformatter.skip -Dimpsort.skip -Denforcer.skip -Dcamel-quarkus.update-extension-doc-page.skip \
--fail-at-end \
test
- name: Report test failures
uses: ./.github/actions/test-summary-report
if: ${{ failure() }}
with:
test-report-xml-base-dir: test-framework
- name: cd tooling && mvn verify
run: |
cd tooling
../mvnw ${CQ_MAVEN_ARGS} \
-Dformatter.skip -Dimpsort.skip -Denforcer.skip \
--fail-at-end \
verify
- name: Report test failures
uses: ./.github/actions/test-summary-report
if: ${{ failure() }}
with:
test-report-xml-base-dir: tooling
- name: cd catalog && mvn test
run: |
cd catalog
../mvnw ${CQ_MAVEN_ARGS} \
-Dformatter.skip -Dimpsort.skip -Denforcer.skip \
test
- name: Report test failures
uses: ./.github/actions/test-summary-report
if: ${{ failure() }}
with:
test-report-xml-base-dir: catalog
- name: Report Build Failure
if: failure() || cancelled()
run: |
Expand Down Expand Up @@ -335,6 +365,11 @@ jobs:
-Dformatter.skip -Dimpsort.skip -Denforcer.skip \
--fail-at-end \
clean test
- name: Report test failures
uses: ./.github/actions/test-summary-report
if: ${{ failure() }}
with:
test-report-xml-base-dir: integration-tests-jvm
- name: Report Build Failure
if: failure() || cancelled()
run: |
Expand Down Expand Up @@ -390,6 +425,11 @@ jobs:
-Dformatter.skip -Dimpsort.skip -Denforcer.skip \
--fail-at-end \
clean verify
- name: Report test failures
uses: ./.github/actions/test-summary-report
if: ${{ failure() }}
with:
test-report-xml-base-dir: integration-tests

integration-tests-alternative-platform:
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -435,6 +475,11 @@ jobs:
-Dskip-testcontainers-tests -Dformatter.skip -Dimpsort.skip -Denforcer.skip \
--fail-at-end \
clean verify
- name: Report test failures
uses: ./.github/actions/test-summary-report
if: ${{ failure() }}
with:
test-report-xml-base-dir: integration-tests
- name: Report Build Failure
if: failure() || cancelled()
shell: bash
Expand Down Expand Up @@ -515,13 +560,16 @@ jobs:
done

if [[ ${#BUILD_FAILURES[@]} -gt 0 ]]; then
echo -e "\nBuild errors were encountred in the following projects:\n"
echo -e "\nBuild errors were encountered in the following projects:\n"
for FAILURE in ${BUILD_FAILURES[@]}; do
echo "* ${FAILURE}"
done
echo -e "\nCheck build logs for further information."
exit 1
fi
- name: Report test failures
uses: ./.github/actions/test-summary-report
if: ${{ failure() }}
- name: Report Build Failure
if: failure() || cancelled()
run: |
Expand Down
50 changes: 49 additions & 1 deletion .github/workflows/ci-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ jobs:
--fail-at-end \
-pl "${NATIVE_MODULES[*]}"
fi
- name: Report test failures
uses: ./.github/actions/test-summary-report
if: ${{ failure() }}
with:
test-report-xml-base-dir: integration-tests
- name: Fail if there are uncommitted changes
shell: bash
run: |
Expand Down Expand Up @@ -321,33 +326,58 @@ jobs:
-Dformatter.skip -Dimpsort.skip -Denforcer.skip -Dcamel-quarkus.update-extension-doc-page.skip \
--fail-at-end \
test
- name: Report test failures
uses: ./.github/actions/test-summary-report
if: ${{ failure() }}
with:
test-report-xml-base-dir: extensions-core
- name: cd extensions && mvn test
run: |
cd extensions
../mvnw ${CQ_MAVEN_ARGS} ${BRANCH_OPTIONS} \
-Dformatter.skip -Dimpsort.skip -Denforcer.skip -Dcamel-quarkus.update-extension-doc-page.skip \
--fail-at-end \
test
- name: Report test failures
uses: ./.github/actions/test-summary-report
if: ${{ failure() }}
with:
test-report-xml-base-dir: extensions
- name: cd test-framework && mvn test
run: |
cd test-framework
../mvnw ${CQ_MAVEN_ARGS} ${BRANCH_OPTIONS} \
-Dformatter.skip -Dimpsort.skip -Denforcer.skip -Dcamel-quarkus.update-extension-doc-page.skip \
--fail-at-end \
test
- name: Report test failures
uses: ./.github/actions/test-summary-report
if: ${{ failure() }}
with:
test-report-xml-base-dir: test-framework
- name: cd tooling && mvn verify
run: |
cd tooling
../mvnw ${CQ_MAVEN_ARGS} ${BRANCH_OPTIONS} \
-Dformatter.skip -Dimpsort.skip -Denforcer.skip \
--fail-at-end \
verify
- name: Report test failures
uses: ./.github/actions/test-summary-report
if: ${{ failure() }}
with:
test-report-xml-base-dir: tooling
- name: cd catalog && mvn test
run: |
cd catalog
../mvnw ${CQ_MAVEN_ARGS} ${BRANCH_OPTIONS} \
-Dformatter.skip -Dimpsort.skip -Denforcer.skip \
test
- name: Report test failures
uses: ./.github/actions/test-summary-report
if: ${{ failure() }}
with:
test-report-xml-base-dir: catalog

extensions-jvm-tests:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -388,6 +418,11 @@ jobs:
-Dformatter.skip -Dimpsort.skip -Denforcer.skip \
--fail-at-end \
clean test
- name: Report test failures
uses: ./.github/actions/test-summary-report
if: ${{ failure() }}
with:
test-report-xml-base-dir: integration-tests-jvm

integration-tests-alternative-jdk:
name: Integration Tests Alternative JDK 21 ${{matrix.name}}
Expand Down Expand Up @@ -435,6 +470,11 @@ jobs:
-Dformatter.skip -Dimpsort.skip -Denforcer.skip \
--fail-at-end \
clean verify
- name: Report test failures
uses: ./.github/actions/test-summary-report
if: ${{ failure() }}
with:
test-report-xml-base-dir: integration-tests

integration-tests-alternative-platform:
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -481,6 +521,11 @@ jobs:
-Dskip-testcontainers-tests -Dformatter.skip -Dimpsort.skip -Denforcer.skip \
--fail-at-end \
clean verify
- name: Report test failures
uses: ./.github/actions/test-summary-report
if: ${{ failure() }}
with:
test-report-xml-base-dir: integration-tests

examples-tests:
name: Examples Tests - ${{matrix.name}}
Expand Down Expand Up @@ -548,10 +593,13 @@ jobs:
done

if [[ ${#BUILD_FAILURES[@]} -gt 0 ]]; then
echo -e "\nBuild errors were encountred in the following projects:\n"
echo -e "\nBuild errors were encountered in the following projects:\n"
for FAILURE in ${BUILD_FAILURES[@]}; do
echo "* ${FAILURE}"
done
echo -e "\nCheck build logs for further information."
exit 1
fi
- name: Report test failures
uses: ./.github/actions/test-summary-report
if: ${{ failure() }}
Loading
Loading