-
Notifications
You must be signed in to change notification settings - Fork 8
Github Action validator for DB insert #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rpappalax
wants to merge
1
commit into
master
Choose a base branch
from
rpapa-action-validate-db
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -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 |
This file contains hidden or 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 |
|---|---|---|
| @@ -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 | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file is to demo how this works and if it will fill our needs for DB insert validation.
I have coded this for on push to a personal branch but this is temporary and can be changed.
The idea is to remove this demo workflow altogether but add these few lines to our other workflows where DB validation is required