mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-29 17:52:32 +00:00
Limit number of tests in CI comment (#21936)
* limit test comments * remove unecessary tee * fix go test condition * fix * fail test * remove ailways entirely * fix columns * make a bunch of tests fail * separate line * include Failures: * remove test fails * fix whitespace
This commit is contained in:
33
.github/scripts/report_failed_tests.sh
vendored
33
.github/scripts/report_failed_tests.sh
vendored
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
MAX_TESTS=10
|
||||
# this script expects the following env vars to be set
|
||||
# error if these are not set
|
||||
[ ${GITHUB_TOKEN:?} ]
|
||||
@@ -9,14 +9,33 @@ set -e
|
||||
[ ${REPO:?} ]
|
||||
[ ${PR_NUMBER:?} ]
|
||||
if [ -z "$TABLE_DATA" ]; then
|
||||
echo "Invalid TABLE_DATA"
|
||||
exit 1
|
||||
fi
|
||||
BODY="CI Results:
|
||||
All Go tests succeeded! :white_check_mark:"
|
||||
else
|
||||
# Remove any rows that don't have a test name
|
||||
# Only keep the test type, test package, test name, and logs column
|
||||
# Remove the scroll emoji
|
||||
# Remove "github.com/hashicorp/vault" from the package name
|
||||
TABLE_DATA=$(echo "$TABLE_DATA" | awk -F\| '{if ($4 != " - ") { print "|" $2 "|" $3 "|" $4 "|" $7 }}' | sed -r 's/ :scroll://' | sed -r 's/github.com\/hashicorp\/vault\///')
|
||||
NUM_FAILURES=$(wc -l <<< "$TABLE_DATA")
|
||||
|
||||
# Check if the number of failures is greater than the maximum tests to display
|
||||
# If so, limit the table to MAX_TESTS number of results
|
||||
if [ "$NUM_FAILURES" -gt "$MAX_TESTS" ]; then
|
||||
TABLE_DATA=$(echo "$TABLE_DATA" | head -n "$MAX_TESTS")
|
||||
NUM_OTHER=( $NUM_FAILURES - "$MAX_TESTS" )
|
||||
TABLE_DATA="$TABLE_DATA
|
||||
|
||||
# Create a comment to be posted on the PR
|
||||
# This comment reports failed jobs and the url to the failed workflow
|
||||
BODY="CI Results:
|
||||
and $NUM_OTHER other tests"
|
||||
fi
|
||||
|
||||
# Add the header for the table
|
||||
BODY="CI Results:
|
||||
Failures:
|
||||
| Test Type | Package | Test | Logs |
|
||||
| --------- | ------- | ---- | ---- |
|
||||
${TABLE_DATA}"
|
||||
fi
|
||||
|
||||
source ./.github/scripts/gh_comment.sh
|
||||
|
||||
|
||||
17
.github/workflows/ci.yml
vendored
17
.github/workflows/ci.yml
vendored
@@ -101,9 +101,9 @@ jobs:
|
||||
- verify-changes
|
||||
# Don't run this job for docs/ui only PRs
|
||||
if: |
|
||||
always() && (needs.verify-changes.result == 'skipped' ||
|
||||
needs.verify-changes.result == 'skipped' ||
|
||||
(needs.verify-changes.outputs.is_docs_change == 'false' &&
|
||||
needs.verify-changes.outputs.is_ui_change == 'false'))
|
||||
needs.verify-changes.outputs.is_ui_change == 'false')
|
||||
uses: ./.github/workflows/test-go.yml
|
||||
with:
|
||||
# The regular Go tests use an extra runner to execute the
|
||||
@@ -354,25 +354,24 @@ jobs:
|
||||
# Sort all of the summary table rows and push them to a temp file.
|
||||
temp_file_name=temp-$(date +%s)
|
||||
cat failure-summary-*.md | sort >> "$temp_file_name"
|
||||
temp_message_file_name=temp-table-$(date +%s)
|
||||
|
||||
# If there are test failures, present them in a format of a GitHub Markdown table.
|
||||
if [ -s "$temp_file_name" ]; then
|
||||
# shellcheck disable=SC2129
|
||||
# Here we create the headings for the summary table
|
||||
echo "| Test Type | Package | Test | Elapsed | Runner Index | Logs |" | tee -a "$GITHUB_STEP_SUMMARY" "$temp_message_file_name"
|
||||
echo "| --------- | ------- | ---- | ------- | ------------ | ---- |" | tee -a "$GITHUB_STEP_SUMMARY" "$temp_message_file_name"
|
||||
echo "| Test Type | Package | Test | Elapsed | Runner Index | Logs |" >> "$GITHUB_STEP_SUMMARY"
|
||||
echo "| --------- | ------- | ---- | ------- | ------------ | ---- |" >> "$GITHUB_STEP_SUMMARY"
|
||||
# shellcheck disable=SC2002
|
||||
cat "$temp_file_name" | tee -a "$GITHUB_STEP_SUMMARY" "$temp_message_file_name"
|
||||
cat "$temp_file_name" >> "$GITHUB_STEP_SUMMARY"
|
||||
else
|
||||
echo "### All Go tests passed! :white_check_mark:" | tee -a "$GITHUB_STEP_SUMMARY" "$temp_message_file_name"
|
||||
echo "### All Go tests passed! :white_check_mark:" >> "$GITHUB_STEP_SUMMARY"
|
||||
fi
|
||||
|
||||
# the random EOF is needed for a multiline environment variable
|
||||
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
|
||||
# shellcheck disable=SC2129
|
||||
echo "TABLE_TEST_RESULTS<<$EOF" >> "$GITHUB_ENV"
|
||||
cat "$temp_message_file_name" >> "$GITHUB_ENV"
|
||||
cat "$temp_file_name" >> "$GITHUB_ENV"
|
||||
echo "$EOF" >> "$GITHUB_ENV"
|
||||
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
|
||||
- name: Create comment
|
||||
@@ -383,4 +382,4 @@ jobs:
|
||||
RUN_ID: ${{ github.run_id }}
|
||||
REPO: ${{ github.event.repository.name }}
|
||||
TABLE_DATA: ${{ env.TABLE_TEST_RESULTS }}
|
||||
run: ./.github/scripts/report_failed_tests.sh
|
||||
run: ./.github/scripts/report_failed_tests.sh
|
||||
|
||||
Reference in New Issue
Block a user