-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: update scheduler to notify if test fails
- Loading branch information
Showing
1 changed file
with
91 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
name: FHIR Bundle SmokeTest | ||
name: FHIR Bundle SmokeTest (PLAIN) | ||
on: | ||
schedule: | ||
- cron: '0 */1 * * *' | ||
workflow_dispatch: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test: | ||
|
@@ -29,87 +29,119 @@ jobs: | |
env: | ||
P12_FILE_BASE64: ${{ secrets.TECHBD_PHI_QA_KEY_BASE64 }} | ||
run: | | ||
CERT_DIR="./test-automation/Certificates" | ||
mkdir -p $CERT_DIR | ||
echo "$P12_FILE_BASE64" | base64 -d > "$CERT_DIR/techbd-phi-QA-key.p12" | ||
CERT_DIR="./test-automation/Certificates" | ||
mkdir -p $CERT_DIR | ||
echo "$P12_FILE_BASE64" | base64 -d > "$CERT_DIR/techbd-phi-QA-key.p12" | ||
- name: Update SSL paths in JMeter configuration files | ||
run: | | ||
CONFIG_DIR="./test-automation/apache-jmeter-5.6.3/bin" | ||
CERT_PATH="./test-automation/Certificates/techbd-phi-QA-key.p12" | ||
echo "javax.net.ssl.keyStore=$CERT_PATH" >> $CONFIG_DIR/jmeter.properties | ||
echo "javax.net.ssl.keyStorePassword=" >> $CONFIG_DIR/jmeter.properties | ||
echo "javax.net.ssl.keyStoreType=pkcs12" >> $CONFIG_DIR/jmeter.properties | ||
CONFIG_DIR="./test-automation/apache-jmeter-5.6.3/bin" | ||
CERT_PATH="./test-automation/Certificates/techbd-phi-QA-key.p12" | ||
echo "javax.net.ssl.keyStore=$CERT_PATH" >> $CONFIG_DIR/jmeter.properties | ||
echo "javax.net.ssl.keyStorePassword=" >> $CONFIG_DIR/jmeter.properties | ||
echo "javax.net.ssl.keyStoreType=pkcs12" >> $CONFIG_DIR/jmeter.properties | ||
# Update system.properties | ||
echo "javax.net.ssl.keyStore=$CERT_PATH" >> $CONFIG_DIR/system.properties | ||
echo "javax.net.ssl.keyStorePassword=" >> $CONFIG_DIR/system.properties | ||
echo "javax.net.ssl.keyStoreType=pkcs12" >> $CONFIG_DIR/system.properties | ||
echo "javax.net.ssl.keyStore=$CERT_PATH" >> $CONFIG_DIR/system.properties | ||
echo "javax.net.ssl.keyStorePassword=" >> $CONFIG_DIR/system.properties | ||
echo "javax.net.ssl.keyStoreType=pkcs12" >> $CONFIG_DIR/system.properties | ||
# Update user.properties | ||
echo "javax.net.ssl.keyStore=$CERT_PATH" >> $CONFIG_DIR/user.properties | ||
echo "javax.net.ssl.keyStorePassword=" >> $CONFIG_DIR/user.properties | ||
echo "javax.net.ssl.keyStoreType=pkcs12" >> $CONFIG_DIR/user.properties | ||
echo "javax.net.ssl.keyStore=$CERT_PATH" >> $CONFIG_DIR/user.properties | ||
echo "javax.net.ssl.keyStorePassword=" >> $CONFIG_DIR/user.properties | ||
echo "javax.net.ssl.keyStoreType=pkcs12" >> $CONFIG_DIR/user.properties | ||
- name: Verify updates | ||
- name: Run FHIR Bundle SmokeTest for Environments | ||
id: run-tests | ||
run: | | ||
CONFIG_DIR="./test-automation/apache-jmeter-5.6.3/bin" | ||
echo "Verifying jmeter.properties:" | ||
grep ssl $CONFIG_DIR/jmeter.properties | ||
# Array of environments and their paths | ||
environments=("Staging" "PHI-QA") | ||
environment_paths=( | ||
"./test-automation/FHIR-Bundle-SmokeTest-Stage/Bundle.jmx" | ||
"./test-automation/FHIR-Bundle-SmokeTest-PHI-QA/Bundle.jmx" | ||
) | ||
# Initialize failure report and attachments arrays | ||
counter=1 | ||
failure_report="" | ||
attachments=() | ||
# Loop through environments and run the tests | ||
for i in "${!environments[@]}"; do | ||
env="${environments[$i]}" | ||
path="${environment_paths[$i]}" | ||
result_dir="./test-automation/Jmeter${env}Result" | ||
report_dir="./test-automation/Jmeter${env}Report" | ||
zip_file="./test-automation/Jmeter${env}Report.zip" | ||
# Create necessary directories | ||
mkdir -p "$result_dir" | ||
mkdir -p "$report_dir" | ||
# Run the JMeter test and generate reports | ||
./test-automation/apache-jmeter-5.6.3/bin/jmeter -n -t "$path" -l "$result_dir/bundletest.jtl" > "$result_dir/$env.log" | ||
./test-automation/apache-jmeter-5.6.3/bin/jmeter -g "$result_dir/bundletest.jtl" -o "$report_dir/" | ||
# Check for errors in the JMeter log file | ||
errors=$(grep "summary =" "$result_dir/$env.log" | tail -1 | grep -oP "Err:\s+\K\d+") | ||
echo "${env}_errors=$errors" >> $GITHUB_ENV | ||
echo "Verifying system.properties:" | ||
grep ssl $CONFIG_DIR/system.properties | ||
# Show the log in console | ||
cat $result_dir/$env.log | ||
echo "Verifying user.properties:" | ||
grep ssl $CONFIG_DIR/user.properties | ||
# If errors found, add environment and report to failure | ||
if [[ "$errors" -gt 0 ]]; then | ||
failure_report="${failure_report}${counter}. ${env}, " | ||
counter=$((counter + 1)) | ||
attachments+=("$zip_file") | ||
fi | ||
done | ||
# If no failures, set a default message | ||
if [[ -z "$failure_report" ]]; then | ||
failure_report="No failures detected." | ||
else | ||
# Remove trailing comma and space | ||
failure_report=$(echo "$failure_report" | sed 's/, $//') | ||
fi | ||
- name: Run FHIR Bundle SmokeTest - Staging | ||
run: | | ||
mkdir -p ./test-automation/JmeterStageReport/ | ||
./test-automation/apache-jmeter-5.6.3/bin/jmeter -n -t "./test-automation/FHIR-Bundle-SmokeTest-Stage/Bundle.jmx" -l "./test-automation/JmeterStageResult/bundletest.jtl" | ||
./test-automation/apache-jmeter-5.6.3/bin/jmeter -g "./test-automation/JmeterStageResult/bundletest.jtl" -o "./test-automation/JmeterStageReport/" | ||
- name: Run FHIR Bundle SmokeTest - PHI-QA | ||
run: | | ||
mkdir -p ./test-automation/JmeterPHIQAReport/ | ||
./test-automation/apache-jmeter-5.6.3/bin/jmeter -n -t "./test-automation/FHIR-Bundle-SmokeTest-PHI-QA/Bundle.jmx" -l "./test-automation/JmeterPHIQAResult/bundletest.jtl" | ||
./test-automation//apache-jmeter-5.6.3/bin/jmeter -g "./test-automation/JmeterPHIQAResult/bundletest.jtl" -o "./test-automation/JmeterPHIQAReport/" | ||
# Convert attachments array to a comma-separated string for GitHub Actions | ||
failure_attachments=$(IFS=,; echo "${attachments[*]}") | ||
echo "failure_attachments=$failure_attachments" >> $GITHUB_ENV | ||
# Export the failure_report to GitHub Actions environment | ||
echo "failure_report=$failure_report" >> $GITHUB_ENV | ||
- name: Archive JMeter Reports into ZIP files | ||
run: | | ||
sudo apt-get install -y zip | ||
cd ./test-automation | ||
zip -r ./JmeterStageReport.zip ./JmeterStageReport/ | ||
zip -r ./JmeterPHIQAReport.zip ./JmeterPHIQAReport/ | ||
- name: Send email with JMeter reports | ||
# Ensure the report directories are zipped | ||
for env in "Staging" "PHI-QA"; do | ||
mkdir -p "./Jmeter${env}Report" | ||
zip -r "./Jmeter${env}Report.zip" "./Jmeter${env}Report/" | ||
done | ||
- name: Send Email Notification (Conditional) | ||
if: env.failure_report != 'No failures detected.' | ||
uses: dawidd6/action-send-mail@v3 | ||
with: | ||
server_address: email-smtp.us-east-1.amazonaws.com | ||
server_port: 587 | ||
username: ${{ secrets.SES_SMTP_USERNAME }} | ||
password: ${{ secrets.SES_SMTP_PASSWORD }} | ||
subject: "TechBD FHIR Bundle SmokeTest" | ||
subject: "FHIR Bundle SmokeTest Failures" | ||
body: | | ||
Hello Team, | ||
This is an automated notification for the FHIR Bundle scheduled SmokeTest results. | ||
Hello Team, | ||
Test Summary: | ||
- Staging Report: Attached | ||
- QA Report: Attached | ||
The FHIR Bundle SmokeTest encountered failures in the following environments: | ||
Please find the attached reports for detailed results of the tests executed. | ||
${{ env.failure_report }} | ||
Regards, | ||
Tech by Design Automation Team | ||
Please find the attached reports for the same. | ||
Regards, | ||
Tech by Design Automation Team | ||
content_type: "text/plain" | ||
from: "Tech by Design FHIR SmokeTest Result <[email protected]>" | ||
to: [email protected], [email protected], [email protected] | ||
attachments: | | ||
./test-automation/JmeterStageReport.zip | ||
./test-automation/JmeterPHIQAReport.zip | ||
to: [email protected] | ||
attachments: ${{ env.failure_attachments }} |