QA-7156 updated locators for Org structure and exports #445
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
# This workflow will install Python dependencies, run tests and lint with a single version of Python | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | |
name: Elastic Search Tests | |
on: | |
push: | |
branches: [ master ] | |
pull_request: | |
branches: [ master ] | |
schedule: | |
- cron: '0 0 * * 0' | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: 'Environment to run tests against' | |
required: true | |
default: 'staging' | |
type: choice | |
options: | |
- staging | |
- production | |
jobs: | |
set_matrix: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix-manual.outputs.matrix || steps.set-matrix-default.outputs.matrix }} | |
steps: | |
- id: set-matrix-manual | |
if: ${{ github.event_name == 'workflow_dispatch' }} | |
run: | | |
echo "::set-output name=matrix::{\"environment\": [\"${{ inputs.environment }}\"]}" | |
- id: set-matrix-default | |
if: ${{ !contains(github.event_name , 'dispatch') }} | |
run: | | |
echo "::set-output name=matrix::{\"environment\": [\"staging\"]}" | |
build: | |
needs: set_matrix | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJSON(needs.set_matrix.outputs.matrix) }} | |
concurrency: | |
group: ${{ github.workflow }}-${{ matrix.environment }} | |
cancel-in-progress: true | |
name: ES Test on '${{ matrix.environment }}' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Python 3.9 | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.9 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r ElasticSearchTests/requires.txt | |
- name: ES Test with pytest | |
env: | |
DIMAGIQA_ENV: ${{ matrix.environment }} #${{ secrets.DIMAGIQA_URL }} | |
DIMAGIQA_LOGIN_USERNAME: ${{ secrets.DIMAGIQA_LOGIN_USERNAME }} | |
DIMAGIQA_LOGIN_PASSWORD: ${{ secrets.DIMAGIQA_LOGIN_PASSWORD }} | |
DIMAGIQA_MAIL_USERNAME: ${{ secrets.DIMAGIQA_MAIL_USERNAME }} | |
DIMAGIQA_MAIL_PASSWORD: ${{ secrets.DIMAGIQA_MAIL_PASSWORD }} | |
DIMAGIQA_BS_USER: ${{ secrets.DIMAGIQA_BS_USER }} | |
DIMAGIQA_BS_KEY: ${{ secrets.DIMAGIQA_BS_KEY }} | |
DIMAGIQA_STAGING_AUTH_KEY: ${{ secrets.DIMAGIQA_STAGING_AUTH_KEY }} | |
DIMAGIQA_PROD_AUTH_KEY: ${{ secrets.DIMAGIQA_PROD_AUTH_KEY }} | |
DIMAGIQA_INVITED_WEBUSER_PASSWORD: ${{ secrets.DIMAGIQA_INVITED_WEBUSER_PASSWORD }} | |
DIMAGIQA_IMAP_PASSWORD: ${{secrets.DIMAGIQA_IMAP_PASSWORD}} | |
run: | | |
echo "client_payload: ${{ toJson(github.event.client_payload) }}" | |
echo "matrix environment: ${{ matrix.environment }}" | |
echo "NOW=$(date +'%m-%d %H:%M')" >> $GITHUB_ENV | |
echo ${{env.NOW}} | |
pytest -v --rootdir= ElasticSearchTests/testCases -n 4 --dist=loadfile --reruns 1 --html=es_report_${{ matrix.environment }}.html | |
- name: Parse test counts | |
id: parse_counts | |
if: always() | |
run: | | |
# Extract variables from the api_test_counts.txt file | |
while IFS= read -r line; do | |
echo "::set-output name=${line%=*}::${line#*=}" | |
done < es_test_counts_${{ matrix.environment }}.txt | |
- name: Archive test results | |
id: artifact-upload-step | |
if: ${{ success() || failure() }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: test-result-reports--${{ matrix.environment }}-${{ github.run_id }} | |
path: /home/runner/work/dimagi-qa/dimagi-qa/es_report_${{ matrix.environment }}.html | |
retention-days: 2 | |
- name: Fetch artifact ID | |
run: echo 'Artifact ID is ${{ steps.artifact-upload-step.outputs.artifact-id }}' | |
- name: Set email vars | |
if: ${{ failure() }} | |
id: configure_email | |
uses: actions/github-script@v6 | |
env: | |
JOB_STATUS: ${{ job.status }} | |
CC_ENV: ${{ matrix.environment }} | |
with: | |
script: | | |
const { promises: fs } = require('fs') | |
const {JOB_STATUS, NOW, CC_ENV, GITHUB_HEAD_REF} = process.env | |
const prefix = `[${CC_ENV}] ES Tests - ${JOB_STATUS.toUpperCase()} - Run #${context.runNumber}` | |
const suffix = `at ${NOW}` | |
let subject = `${prefix} on "deploy_success" ${suffix}` | |
if (context.eventName !== "repository_dispatch") { | |
subject = `${prefix} on branch "${GITHUB_HEAD_REF}" ${suffix}` | |
} | |
let bodyFile = './common_utilities/mail_templates/email_pass.md' | |
if (JOB_STATUS !== 'success') { | |
bodyFile = './common_utilities/mail_templates/email_fail.md' | |
} | |
let actionRunLink = context.payload.repository.html_url + `/actions/runs/${context.runId}` | |
let testSuite = 'ES Test' | |
let bodyContent = await fs.readFile(bodyFile, 'utf8') | |
bodyContent = bodyContent.replace(/{{actionRunLink}}/g, actionRunLink) | |
.replace(/{{runNumber}}/g, context.runNumber) | |
.replace(/{{environment}}/g, CC_ENV) | |
.replace(/{{testSuite}}/g, testSuite) | |
let receivers = '[email protected]' | |
if (context.eventName !== "pull_request" || context.eventName !== "push") { | |
receivers = '[email protected]' | |
} | |
return { | |
"subject": subject, | |
"body": bodyContent, | |
"reference": Math.random().toString(36).substr(2), // used to prevent threading of similar emails | |
"receivers": receivers | |
} | |
- name: Send Result Email | |
if: ${{ failure() }} | |
uses: dawidd6/action-send-mail@v3 | |
with: | |
server_address: smtp.gmail.com | |
server_port: 465 | |
username: ${{secrets.DIMAGIQA_MAIL_USERNAME}} | |
password: ${{secrets.DIMAGIQA_MAIL_PASSWORD}} | |
subject: ${{ fromJSON(steps.configure_email.outputs.result).subject }} | |
to: ${{ fromJSON(steps.configure_email.outputs.result).receivers }} | |
from: <${{secrets.DIMAGIQA_MAIL_USERNAME}}> | |
html_body: ${{ fromJSON(steps.configure_email.outputs.result).body }} | |
convert_markdown: true | |
attachments: ${{ github.workspace }}/es_report_${{ matrix.environment }}.html | |
in_reply_to: ${{ fromJSON(steps.configure_email.outputs.result).reference }} | |
- name: Post to Slack channel on Failure | |
id: slack | |
uses: slackapi/[email protected] | |
if: failure() | |
with: | |
payload: | | |
{ | |
"attachments": [ | |
{ | |
"color": "#FF0000", | |
"blocks": [ | |
{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": " Hey There!! :bye_boo: \n*${{ github.workflow }}* were just triggered! \n" | |
} | |
}, | |
{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": "*Passed:* ${{ steps.parse_counts.outputs.PASSED }} *Failed:* ${{ steps.parse_counts.outputs.FAILED }} *Error:* ${{ steps.parse_counts.outputs.ERROR }} *Skipped:* ${{ steps.parse_counts.outputs.SKIPPED }} *XFail:* ${{ steps.parse_counts.outputs.XFAIL }}\n" | |
} | |
}, | |
{ | |
"type": "context", | |
"elements": [ | |
{ | |
"type": "mrkdwn", | |
"text": "*Environment: *\n ${{ matrix.environment }} \n" | |
}, | |
{ | |
"type": "mrkdwn", | |
"text": " " | |
}, | |
{ | |
"type": "mrkdwn", | |
"text": "*Status: *\n ${{ job.status }} :x:" | |
} | |
] | |
}, | |
{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": "Here's the corresponding report :arrow_right::arrow_right:" | |
}, | |
"accessory": { | |
"type": "button", | |
"text": { | |
"type": "plain_text", | |
"text": "Click to Downlaod", | |
"emoji": true | |
}, | |
"value": "click_me_123", | |
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.artifact-upload-step.outputs.artifact-id }}", | |
"action_id": "button-action", | |
"style": "danger" | |
} | |
} | |
] | |
} | |
] | |
} | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_SMOKE }} | |
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK |