Skip to content
Open
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
59 changes: 59 additions & 0 deletions .github/actions/db-inserts-verify/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Run report and verify inserts
description: Runs a command, parses ROWS_INSERTED=N, and enforces zero policy

inputs:
report_name:
description: Logical name of the report (for messages)
required: true
run:
description: Shell command to run the report (must print ROWS_INSERTED=N)
required: true
zero_ok:
description: 'Allow zero inserts without failing (true/false)'
required: false
default: 'false'
parse_regex:
description: RegEx to capture ROWS_INSERTED=NNN (advanced override)
required: ''
default: 'ROWS_INSERTED\s*=\s*([0-9]+)'

runs:
using: composite
steps:
- name: Run report
id: runreport
shell: bash
run: |
set -euo pipefail
echo "[verify] running: ${{ inputs.run }}"
bash -lc '${{ inputs.run }}' 2>&1 | tee report.out


# Pick regex
regex='ROWS_INSERTED=([0-9]+)'

# Find last match
count="$(grep -Eo "${{ inputs.parse_regex }}" report.out | sed -E 's/.*=([0-9]+).*/\1/' | tail -n1 || true)"
if [[ -z "${count:-}" ]]; then count=0; fi
echo "rows_inserted=${count}" >> "$GITHUB_OUTPUT"

- name: Show parsed count
shell: bash
run: echo "[verify] parsed rows_inserted=${{ steps.runreport.outputs.rows_inserted }}"

- name: Enforce non-zero inserts
if: steps.runreport.outputs.rows_inserted == '0' && inputs.zero_ok != 'true'
shell: bash
run: |
echo "::error::Report '${{ inputs.report_name }}' expected inserts but got 0"
echo "[verify] rows_inserted=0; showing last 200 lines of report.out for debugging"
tail -n 200 report.out || true
exit 1

- name: Diagnostic (zero allowed)
if: steps.runreport.outputs.rows_inserted == '0' && inputs.zero_ok == 'true'
shell: bash
run: |
echo "::warning::Report '${{ inputs.report_name }}' inserted 0 rows (allowed)"
echo "[verify] rows_inserted=0; showing last 100 lines of report.out for context"
tail -n 100 report.out || true
75 changes: 75 additions & 0 deletions .github/workflows/demo-db-insert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Demo - Verify DB insert / delete

on:
pull_request:
push:
branches:
- rpapa-db-verify
workflow_dispatch:
inputs:
branchName:
description: 'Default branch'
required: true
default: 'master'

jobs:
deploy:
name: Demo - Verify DB insert / delete
runs-on: ubuntu-latest

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

- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Establish Cloud SQL Proxy
uses: mattes/gce-cloudsql-proxy-action@v1
with:
creds: ${{ secrets.GCLOUD_AUTH }}
instance: ${{ secrets.CLOUD_SQL_CONNECTION_NAME }}
port: ${{ secrets.CLOUD_SQL_DATABASE_PORT }}

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

- 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
echo "CLOUD_SQL_DATABASE_NAME=preflight" >> $GITHUB_ENV
echo "CLOUD_SQL_DATABASE_PORT=${{ secrets.CLOUD_SQL_DATABASE_PORT }}" >> $GITHUB_ENV
echo "TESTRAIL_HOST=${{ secrets.TESTRAIL_HOST }}" >> $GITHUB_ENV
echo "TESTRAIL_USERNAME=${{ secrets.TESTRAIL_USERNAME }}" >> $GITHUB_ENV
echo "TESTRAIL_PASSWORD=${{ secrets.TESTRAIL_PASSWORD }}" >> $GITHUB_ENV
echo "ATLASSIAN_API_TOKEN=${{ secrets.ATLASSIAN_API_TOKEN }}" >> $GITHUB_ENV
echo "ATLASSIAN_HOST=${{ secrets.ATLASSIAN_HOST }}" >> $GITHUB_ENV
echo "ATLASSIAN_USERNAME=${{ secrets.ATLASSIAN_USERNAME }}" >> $GITHUB_ENV
echo "JIRA_HOST=${{ secrets.JIRA_HOST }}" >> $GITHUB_ENV
echo "JIRA_USER=${{ secrets.JIRA_USER }}" >> $GITHUB_ENV
echo "JIRA_PASSWORD=${{ secrets.JIRA_PASSWORD }}" >> $GITHUB_ENV
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
echo "BUGZILLA_API_KEY=${{ secrets.BUGZILLA_API_KEY }}" >> $GITHUB_ENV
echo "BITRISE_HOST=${{ secrets.BITRISE_HOST }}" >> $GITHUB_ENV
echo "BITRISE_APP_SLUG=${{ secrets.BITRISE_APP_SLUG }}" >> $GITHUB_ENV
echo "BITRISE_TOKEN=${{ secrets.BITRISE_TOKEN }}" >> $GITHUB_ENV
echo "SENTRY_HOST=${{ secrets.SENTRY_HOST }}" >> $GITHUB_ENV
echo "SENTRY_API_TOKEN=${{ secrets.SENTRY_API_TOKEN_CSO }}" >> $GITHUB_ENV
echo "SENTRY_ORGANIZATION_SLUG=${{ secrets.SENTRY_ORGANIZATION_SLUG }}" >> $GITHUB_ENV
echo "SENTRY_PROJECT_ID=${{ secrets.SENTRY_PROJECT_ID }}" >> $GITHUB_ENV

# TestRail
- name: Mobile Test Case Coverage & DB verify
uses: ./.github/actions/db-inserts-verify
with:
report_name: Mobile Test Case Coverage
run: python ./__main__.py --report-type testrail-test-case-coverage --platform mobile --project ALL
zero_ok: 'false'

#- name: Mobile testrail milestones
# run: python3 ./__main__.py --platform mobile --project ALL --report-type testrail-milestones

65 changes: 58 additions & 7 deletions api/testrail/api_testrail.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,10 @@ def data_pump_report_test_case_coverage(self, project='all', suite='all'):
# convert inputs to a list so we can easily
# loop thru them
project_ids_list = self.testrail_project_ids(project)
print(project_ids_list)
# TODO:
# currently only setup for test_case report
# fix this for test run data
#print(project_ids_list)

# Test suite data is dynamic. Wipe out old test suite data
# in database before updating.
# Test suite data is dynamic. Wipe out old test suite data in database
# before updating.
self.db.test_suites_delete()

for project_ids in project_ids_list:
Expand Down Expand Up @@ -210,7 +207,7 @@ def testrail_coverage_update(self, projects_id,

# Format and store data in a data payload array
payload = self.db.report_test_coverage_payload(cases)
print(payload)
#print(payload)

# Insert data in 'totals' array into DB
self.db.report_test_coverage_insert(projects_id, payload)
Expand Down Expand Up @@ -614,10 +611,12 @@ def report_test_coverage_payload(self, cases):
.reset_index()
)

'''
def report_test_coverage_insert(self, projects_id, payload):
# TODO: Error on insert
# insert data from totals into report_test_coverage table

rows = len(payload)
for index, row in payload.iterrows():
"""
# Diagnostic
Expand All @@ -644,6 +643,58 @@ def report_test_coverage_insert(self, projects_id, payload):
)
self.session.add(report)
self.session.commit()
print(f'ROWS_INSERTED={rows}')
'''


# -----
def report_test_coverage_insert(self, projects_id, payload):
"""
Insert data from totals into report_test_coverage table.
Uses a single bulk insert for performance.
DEBUG ONLY:
If you need to troubleshoot dirty rows causing failures,
uncomment the row-by-row section at the bottom of this function.
"""
try:
reports = [
ReportTestCaseCoverage(
projects_id=projects_id,
testrail_test_suites_id=row["suit"],
test_automation_status_id=row["status"],
test_automation_coverage_id=row["cov"],
test_sub_suites_id=row["sub"],
test_count=row["tally"],
)
for _, row in payload.iterrows()
]
self.session.bulk_save_objects(reports)
self.session.commit()
print("DIAGNOSTIC: batch insert!")
print(f"ROWS_INSERTED={len(reports)}")
except Exception as e:
self.session.rollback()
print(f"[error] Bulk insert failed: {e}")
# DEBUG ONLY: Uncomment this block to identify bad rows
"""
for idx, row in payload.iterrows():
try:
report = ReportTestCaseCoverage(
projects_id=projects_id,
testrail_test_suites_id=row["suit"],
test_automation_status_id=row["status"],
test_automation_coverage_id=row["cov"],
test_sub_suites_id=row["sub"],
test_count=row["tally"],
)
self.session.add(report)
self.session.commit()
except Exception as row_e:
self.session.rollback()
print(f"[debug] Row {idx} failed: {row_e}")
break
"""
# -----

def report_testrail_users_insert(self, payload):
for index, row in payload.iterrows():
Expand Down
Loading