Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 29 additions & 24 deletions .github/workflows/staging-weekly-desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,29 @@ on:
workflow_dispatch:

jobs:
deploy:
name: Desktop TestOps Report (WEEKLY) - Production
reports:
name: Weekly reports (${{ matrix.name }})
runs-on: ubuntu-latest

strategy:
fail-fast: false
max-parallel: 4
matrix:
include:
- name: Query Test Plans and Runs
args: --report-type testrail-test-results --project firefox-desktop
- name: Query Test Run Average Health
args: --report-type testrail-test-health --project firefox-desktop --platform desktop --num-days 7
- name: Query Bugzilla Release Flags Bugs
args: --report-type bugzilla-desktop-release-flags-for-bugs
- name: Query Bugzilla Overall Bugs
args: --report-type bugzilla-desktop-overall-bugs

steps:
- name: Check out source repository
uses: actions/checkout@v6

- name: Setup python
- name: Setup python
uses: actions/setup-python@v6

- name: Establish Cloud SQL Proxy
Expand All @@ -26,10 +40,10 @@ jobs:
port: ${{ secrets.CLOUD_SQL_DATABASE_PORT }}
proxy_version: "1.37.11"

- name: Install requirements
- name: Install requirements
run: pip install -r requirements.txt

- name: Set env vars
- name: Set env vars
run: |
echo "CLOUD_SQL_DATABASE_USERNAME=${{ secrets.CLOUD_SQL_DATABASE_USERNAME }}" >> $GITHUB_ENV
echo "CLOUD_SQL_DATABASE_PASSWORD=${{ secrets.CLOUD_SQL_DATABASE_PASSWORD }}" >> $GITHUB_ENV
Expand All @@ -46,29 +60,21 @@ jobs:
echo "JIRA_HOST=${{ secrets.JIRA_HOST }}" >> $GITHUB_ENV
echo "JIRA_USER=${{ secrets.JIRA_USER }}" >> $GITHUB_ENV
echo "JIRA_PASSWORD=${{ secrets.JIRA_PASSWORD }}" >> $GITHUB_ENV

- name: Query Test Plans and Runs
run: python ./__main__.py --report-type testrail-test-results --project firefox-desktop
continue-on-error: true

- name: Query Test Run Average Health
run: python ./__main__.py --report-type testrail-test-health --project firefox-desktop --platform desktop --num-days 7
- run: python ./__main__.py ${{ matrix.args }}
continue-on-error: true

- name: Query Bugzilla Release Flags Bugs
run: python ./__main__.py --report-type bugzilla-desktop-release-flags-for-bugs
continue-on-error: true

- name: Query Bugzilla Overall Bugs
run: python ./__main__.py --report-type bugzilla-desktop-overall-bugs

notify:
name: Send workflow status notification
runs-on: ubuntu-latest
needs: [reports]
if: always()
steps:
- uses: actions/checkout@v6
- name: Set job log URL
if: always()
run: echo "JOB_LOG_URL=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> $GITHUB_ENV

- name: Send custom JSON data to Slack workflow
if: always()
id: slack
- name: Send workflow status to Slack
uses: slackapi/slack-github-action@v2.1.1
env:
WORKFLOW_NAME: ${{ github.workflow }}
Expand All @@ -77,9 +83,8 @@ jobs:
JOB_STATUS_COLOR: ${{ job.status == 'success' && '#36a64f' || job.status == 'failure' && '#FF0000' }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_MOBILE_ALERTS_TOOLING }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK

with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL_MOBILE_ALERTS_TOOLING }}
webhook-type: webhook-trigger
payload-templated: true
payload-file-path: "./config/payload-slack-content.json"
payload-file-path: "./config/payload-slack-content.json"
49 changes: 25 additions & 24 deletions api/testrail/report_test_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from api.testrail.client import TestRail
from api.testrail.helpers import testrail_project_ids


_DB = None
_TR = None

Expand Down Expand Up @@ -93,21 +92,18 @@ def update_testrail_test_health_row(payload, update_list):

def increment_average(starting_count, starting_average, new_value) -> float:
return (
float(starting_average)
* (float(starting_count) / float(starting_count + 1))
) + (float(new_value) * (1.0 / float(starting_count + 1)))
((float(starting_average) * float(starting_count)) + float(new_value))
/ (float(starting_count) + 1)
)

new_row["testrail_case_id"] = payload.get("case_id")
new_row["testrail_project_id"] = payload.get("project_id")
new_row["testrail_case_name"] = payload.get("case_name")
new_row["testrail_suite_name"] = payload.get("suite_name")

try:
matching_update = [
u for u in update_list if u["testrail_case_id"] == payload["case_id"]
]
if matching_update:
row = Update(**matching_update[0])
if payload["case_id"] in update_list:
row = Update(**(update_list.get(payload["case_id"])))
else:
row = db.session.scalars(
select(ReportTestRailTestHealth).where(
Expand Down Expand Up @@ -153,7 +149,9 @@ def testrail_test_health(project, num_days=1):

# Dictionary of project ids and their respective service acct user id
AUTOUSERS = {17: 976}
updates = []
suite_cache = {}
test_cache = {}
updates = {}
project_ids_list = testrail_project_ids(project)[0]
start_date = datetime.now() - timedelta(days=int(num_days))
for project_id in project_ids_list:
Expand All @@ -171,12 +169,22 @@ def testrail_test_health(project, num_days=1):
plan_details = tr.get_test_plan(plan.get("id"))
for entry in plan_details.get("entries"):
for run in entry.get("runs"):
for result in tr.test_results_for_run(run.get("id")).get("results"):
run_id = run.get("id")
suite_id = run.get("suite_id")
if suite_id not in suite_cache:
suite_cache[suite_id] = tr.test_suite(
suite_id).get("name")
print(f"Processing Run: {run.get('name')}...")
run_results = tr.test_results_for_run(run_id).get("results", [])
print(f"Processing {len(run_results)} test results...")
for result in run_results:
if not result.get("elapsed"):
continue
test = tr.get_test(result.get("test_id"))
suite_name = tr.test_suite(
run.get("suite_id")).get("name")
test_id = result.get("test_id")
if test_id not in test_cache:
test_cache[test_id] = tr.get_test(test_id)
test = test_cache.get(test_id)
suite_name = suite_cache.get(suite_id)
update_payload = {
"case_id": test.get("case_id"),
"project_id": project_id,
Expand All @@ -191,23 +199,16 @@ def testrail_test_health(project, num_days=1):
new_row = update_testrail_test_health_row(
update_payload, updates
)
matching_row = [
u
for u in updates
if u.get("testrail_case_id") == new_row["testrail_case_id"]
]
if matching_row:
updates.remove(matching_row[0])
updates.append(new_row)
updates[new_row.get("testrail_case_id")] = new_row

report_test_health_update(updates)


def report_test_health_update(payload):
db = _db()
for row in payload:
for testrail_case_id, row in payload.items():
matching_row = db.session.query(ReportTestRailTestHealth).filter(
ReportTestRailTestHealth.testrail_case_id == row["testrail_case_id"]
ReportTestRailTestHealth.testrail_case_id == testrail_case_id
)
if matching_row.all():
matching_row.update(row, synchronize_session="fetch")
Expand Down