8000 Add script to print GitHub workflow run errors by jonsimantov · Pull Request #1761 · firebase/firebase-cpp-sdk · GitHub
[go: up one dir, main page]

Skip to content

Add script to print GitHub workflow run errors #1761

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

jonsimantov
Copy link
Contributor

This script allows users to specify a workflow name and branch to find the latest run. It then identifies any failed jobs within that run and prints the last N lines of logs for each failed step.

Key features:

  • Fetches the most recent workflow run for a given workflow and branch.
  • Identifies jobs within the run that have a 'failure' conclusion.
  • For each failed job, attempts to identify failed steps and extracts their logs.
  • Prints the last 500 lines (configurable) of the log for each failed step.
  • Handles various scenarios including successful runs, running workflows, and missing data.
  • Supports GitHub token via CLI arg, env var, or ~/.github_token.
  • Auto-detects repository from git remote, or accepts via CLI args.

Description

Provide details of the change, and generalize the change in the PR title above.


Testing

Describe how you've tested these changes. Link any manually triggered Integration tests or CPP binary SDK Packaging Github Action workflows, if applicable.


Type of Change

Place an x the applicable box:

  • Bug fix. Add the issue # below if applicable.
  • New feature. A non-breaking change which adds functionality.
  • Other, such as a build process or documentation change.

Notes

  • Bug fixes and feature changes require an update to the Release Notes section of release_build_files/readme.md.
  • Read the contribution guidelines CONTRIBUTING.md.
  • Changes to the public API require an internal API review. If you'd like to help us make Firebase APIs better, please propose your change in a feature request so that we can discuss it together.

This script allows users to specify a workflow name and branch to find
the latest run. It then identifies any failed jobs within that run and
prints the last N lines of logs for each failed step.

Key features:
- Fetches the most recent workflow run for a given workflow and branch.
- Identifies jobs within the run that have a 'failure' conclusion.
- For each failed job, attempts to identify failed steps and extracts their logs.
- Prints the last 500 lines (configurable) of the log for each failed step.
- Handles various scenarios including successful runs, running workflows,
  and missing data.
- Supports GitHub token via CLI arg, env var, or ~/.github_token.
- Auto-detects repository from git remote, or accepts via CLI args.
This commit updates the `print_workflow_run_errors.py` script:

- Workflow name and branch are now optional arguments:
    - `--workflow` (or `--workflow-name`) defaults to "integration_test.yml".
    - `--branch` defaults to the current Git branch.
- Changed default log lines printed from 500 to 100 (`--log-lines`).
- Added `--all-failed-steps` flag:
    - If false (default), only logs for the first failed step in a job are printed.
    - If true, logs for all failed steps in a job are printed.

These changes provide more flexibility and sensible defaults for common use cases.
This commit introduces a grep-like feature to the
`print_workflow_run_errors.py` script.

New features:
- Added `--grep-pattern` (`-g`) argument to specify an Extended
  Regular Expression (ERE) for searching within fetched logs.
- Added `--grep-context` (`-C`) argument to specify the number of
  lines of context to show around matches (default is 5).

Behavior:
- If a grep pattern is provided, the script will use the system `grep`
  command to filter the logs of failed steps (or the full job log
  if a specific step's log cannot be isolated).
- Output clearly indicates when grep results are shown, the pattern used,
  and the context lines.
- Handles cases where `grep` finds no matches or if the `grep` command
  itself fails (e.g., not found, bad pattern).
- If no grep pattern is provided, the script defaults to its previous
  behavior of printing the last N lines of the log.
This commit refines the grep functionality in the
`print_workflow_run_errors.py` script by updating default values:

- The default `--grep-pattern` is now `"[Ee]rror[: ]"`.
  Logs will be automatically filtered for this pattern if no other
  pattern is specified.
- The default `--grep-context` is now 10 lines.

If an empty string is explicitly passed to `--grep-pattern`
(e.g., `--grep-pattern ""`), grep functionality will be disabled,
and the script will fall back to printing the last N lines of the log.
This commit introduces a new feature to filter jobs by name using a
regular expression in the `print_workflow_run_errors.py` script.

New features:
- Added `--job-pattern` argument, which accepts a regex string.
  Only jobs whose names match this pattern will be processed for failures.
- The default value for `--job-pattern` is `'^build.*'`, meaning by
  default, the script will only look at jobs starting with 'build'.

Behavior:
- Job name filtering is applied before checking for job failures.
- If an invalid regex is provided for `--job-pattern`, the script prints
  an error and exits gracefully.
- This new filter works in conjunction with existing log processing
  options (like `--grep-pattern` and `--all-failed-steps`), which are
  applied to the jobs that pass the name pattern filter and are failed.
This commit updates the default regular expression for the
`--grep-pattern` argument in the `print_workflow_run_errors.py` script.

The default pattern is changed from `"[Ee]rror[: ]"` to
`"[Ee][Rr][Rr][Oo][Rr][: ]"` for more specific matching of "Error"
(case-insensitive) followed by a colon or space.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0