mirror of
https://github.com/splunk/security_content
synced 2026-06-08 17:32:49 +00:00
Code to generate and upload
pass rate badge after completion of a scheduled run. Also uploads the summary_test_results.json file for use on research.splunk.com
This commit is contained in:
@@ -287,8 +287,8 @@ jobs:
|
||||
name: DetectionFailureManifest
|
||||
path: |
|
||||
bin/docker_detection_tester/detection_failure_manifest.json
|
||||
|
||||
|
||||
|
||||
#Always clean these up, they make the output messy
|
||||
- name: Clean up intermediate Files
|
||||
uses: geekyeggo/delete-artifact@v1
|
||||
@@ -305,7 +305,34 @@ jobs:
|
||||
config_tests_7.json.results
|
||||
config_tests_8.json.results
|
||||
config_tests_9.json.results
|
||||
|
||||
- name: Upload S3 Badge and Summary Artifacts for Nightly Scheduled Run
|
||||
if: ${{ github.event_name == 'schedule' }}
|
||||
uses: aws-actions/configure-aws-credentials@v1
|
||||
with:
|
||||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
|
||||
aws-region: us-west-2
|
||||
run: |
|
||||
cd bin/docker_detection_tester
|
||||
python generate_detection_coverage_badge.py --input_summary_file summary_test_results.json --output_badge_file detection_coverage.svg --badge_string "Pass Rate"
|
||||
|
||||
|
||||
#Upload artifact (summary test results)
|
||||
aws s3 cp summary_test_results.json s3://security_content/reporting/summary_test_results.json
|
||||
|
||||
# make the file public since it is not by default
|
||||
aws s3api put-object-acl --bucket security-content --key summary_test_results.json --acl public-read
|
||||
|
||||
|
||||
#Upload artifact (test results coverage badge)
|
||||
aws s3 cp detection_coverage.svg s3://security_content/reporting/detection_coverage.svg
|
||||
|
||||
# make the file public since it is not by default
|
||||
aws s3api put-object-acl --bucket security-content --key detection_coverage.svg --acl public-read
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
|
||||
RAW_BADGE_SVG = '''<?xml version="1.0"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="20">
|
||||
<linearGradient id="a" x2="0" y2="100%">
|
||||
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
||||
<stop offset="2" stop-opacity=".1"/>
|
||||
</linearGradient>
|
||||
|
||||
<rect rx="3" width="60" height="20" fill="#555"/> <!-- Comment -->
|
||||
<rect rx="3" x="60" width="40" height="20" fill="#4c1"/>
|
||||
|
||||
<path fill="#4c1" d="M58 0h4v20h-4z"/>
|
||||
|
||||
<rect rx="3" width="100" height="20" fill="url(#a)"/>
|
||||
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
|
||||
<text x="30" y="14">{}</text>
|
||||
<text x="80" y="14">{}</text>
|
||||
</g>
|
||||
</svg>'''
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description='Use a summary.json file to generate a test coverage badge')
|
||||
parser.add_argument('-i', "--input_summary_file", type=argparse.FileType('r'), required = True,
|
||||
help='Summary file to use to generate the pass percentage badge')
|
||||
parser.add_argument('-o', "--output_badge_file", type=argparse.FileType('w'), required = True,
|
||||
help='Name of the badge to output')
|
||||
parser.add_argument('-s', "--badge_string", type=str, required = True,
|
||||
help='Name of the badge to output')
|
||||
|
||||
|
||||
|
||||
try:
|
||||
results = parser.parse_args()
|
||||
except Exception as e:
|
||||
print(f"Error parsing arguments: {str(e)}")
|
||||
exit(1)
|
||||
|
||||
try:
|
||||
summary_info = json.loads(results.input_summary_file.read())
|
||||
except Exception as e:
|
||||
print(f"Error loading {results.input_summary_file.name} JSON file: {str(e)}")
|
||||
sys.exit(1)
|
||||
|
||||
if 'summary' not in summary_info:
|
||||
print("Missing 'summary' key in {results.input_summary_file.name}")
|
||||
sys.exit(1)
|
||||
elif 'PASS_RATE' not in summary_info['summary'] or 'TESTS_PASSED' not in summary_info['summary']:
|
||||
print(f"Missing PASS_RATE in 'summary' section of {results.input_summary_file.name}")
|
||||
sys.exit(1)
|
||||
pass_percent = 100 * summary_info['summary']['PASS_RATE']
|
||||
|
||||
|
||||
try:
|
||||
results.output_badge_file.write(RAW_BADGE_SVG.format(results.badge_string, "{:2.1f}%".format(pass_percent)))
|
||||
except Exception as e:
|
||||
print(f"Error generating badge: {str(e)}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
print("Badge {results.output_badge_file.name} successfully generated!")
|
||||
sys.exit(0)
|
||||
|
||||
Reference in New Issue
Block a user