Skip to content

FHIR Bundle SmokeTest #1232

FHIR Bundle SmokeTest

FHIR Bundle SmokeTest #1232

name: FHIR Bundle SmokeTest
on:
schedule:
- cron: '0 */1 * * *'
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
if: ${{ github.repository == 'tech-by-design/polyglot-prime' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'corretto'
cache: maven
- name: Download and setup JMeter
run: |
curl -O https://dlcdn.apache.org//jmeter/binaries/apache-jmeter-5.6.3.tgz
tar -xzf apache-jmeter-5.6.3.tgz
sudo mv apache-jmeter-5.6.3 ./test-automation/
- name: Decode the .p12 file
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"
- 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
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/user.properties
echo "javax.net.ssl.keyStorePassword=" >> $CONFIG_DIR/user.properties
echo "javax.net.ssl.keyStoreType=pkcs12" >> $CONFIG_DIR/user.properties
- name: Run FHIR Bundle SmokeTest for Environments
id: run-tests
run: |
# 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
# Show the log in console
cat $result_dir/$env.log
# 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
# 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
# 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: "FHIR Bundle SmokeTest Failures"
body: |
Hello Team,
The FHIR Bundle SmokeTest encountered failures in the following environments:
${{ env.failure_report }}
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], [email protected]
attachments: ${{ env.failure_attachments }}