Repository navigation
feat: implement issue #1390 — [Fleet Monitor] petry-projects/.github-private — .github/workflows/pr-auto-review.yml #1391
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
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,105 @@ | ||
| #!/usr/bin/env python3 | ||
| """Validate that the pr-auto-review.yml caller stub skips Dependabot-triggered events. | ||
|
|
||
| A Dependabot `pull_request` run has no access to org/repo secrets, so the caller's | ||
| `secrets.GH_PAT_DON_PETRY || secrets.GH_PAT_WORKFLOWS` resolves to an empty string and | ||
| the reusable's ready-check tooling checkout fails at startup with | ||
| "Input required and not supplied: token" (the 20% failure the Fleet Monitor flagged in | ||
| #1390). The fix mirrors the documented #864 precedent in dev-lead-reusable.yml: guard the | ||
| calling job with `if: github.actor != 'dependabot[bot]'` so it skips cleanly before the | ||
| reusable's checkout. Dependabot PRs are handled by dependabot-automerge.yml and never need | ||
| the review-agent dispatch. | ||
|
|
||
| Regression guard: dropping the Dependabot guard (or repinning off the @pr-auto-review/v1-next | ||
| channel) reintroduces the failure class. | ||
| """ | ||
| from __future__ import annotations | ||
|
|
||
| import sys | ||
|
|
||
| try: | ||
| import yaml | ||
| except ImportError: | ||
| yaml = None | ||
|
|
||
| WORKFLOW = ".github/workflows/pr-auto-review.yml" | ||
| REUSABLE = "petry-projects/.github/.github/workflows/pr-auto-review-reusable.yml" | ||
| EXPECTED_REF = "@pr-auto-review/v1-next" | ||
| DEPENDABOT_ACTOR = "dependabot[bot]" | ||
|
|
||
|
|
||
| def main() -> int: | ||
| if yaml is None: | ||
| print("FAIL: PyYAML is required (pip install pyyaml)", file=sys.stderr) | ||
| return 2 | ||
|
|
||
| try: | ||
| with open(WORKFLOW, encoding="utf-8") as fh: | ||
| doc = yaml.safe_load(fh) | ||
| except FileNotFoundError: | ||
| print(f"FAIL: {WORKFLOW} not found") | ||
| return 1 | ||
| except yaml.YAMLError as exc: | ||
| print(f"FAIL: {WORKFLOW} contains invalid YAML: {exc}", file=sys.stderr) | ||
| return 1 | ||
|
|
||
| if not isinstance(doc, dict): | ||
| print(f"FAIL: {WORKFLOW} did not parse as a YAML mapping") | ||
| return 1 | ||
|
|
||
| jobs = doc.get("jobs") or {} | ||
| if not isinstance(jobs, dict): | ||
| print(f"FAIL: {WORKFLOW} 'jobs' key is not a mapping") | ||
| return 1 | ||
|
|
||
| caller_jobs = [ | ||
| job | ||
| for job in jobs.values() | ||
| if isinstance(job, dict) and isinstance(job.get("uses"), str) and REUSABLE in job["uses"] | ||
| ] | ||
|
|
||
| if not caller_jobs: | ||
| print(f"FAIL: {WORKFLOW} does not call {REUSABLE}") | ||
| return 1 | ||
|
|
||
| failures = [] | ||
| for job in caller_jobs: | ||
| ref = job["uses"] | ||
| if not ref.endswith(EXPECTED_REF): | ||
| failures.append( | ||
| f" Wrong ref: {ref!r}\n" | ||
| f" Expected: '{REUSABLE}{EXPECTED_REF}'\n" | ||
| " Reason: first-party reusable must stay on the @pr-auto-review/v1-next\n" | ||
| " moving channel (AGENTS.md §Release channel tags)." | ||
| ) | ||
|
|
||
| expected_guard = ( | ||
| f"github.actor != '{DEPENDABOT_ACTOR}' && " | ||
| f"github.event.pull_request.user.login != '{DEPENDABOT_ACTOR}'" | ||
| ) | ||
| guard = job.get("if") | ||
| if not isinstance(guard, str) or guard.strip() != expected_guard: | ||
| failures.append( | ||
| f" Missing Dependabot guard: job 'if' is {guard!r}\n" | ||
| f" Expected exactly:\n" | ||
| f" if: {expected_guard}\n" | ||
| " Reason: actor-only guard is bypassed on re-runs; PR-author check\n" | ||
| " also skips pull_request_review events on Dependabot PRs.\n" | ||
| " Dependabot runs lack GH_PAT_WORKFLOWS, so the reusable's\n" | ||
| " checkout fails with 'Input required and not supplied: token' (#1390, #864)." | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| ) | ||
|
qodo-code-review[bot] marked this conversation as resolved.
|
||
|
|
||
| if failures: | ||
| print(f"FAIL: {WORKFLOW} caller stub is misconfigured:") | ||
| for msg in failures: | ||
| print(msg) | ||
| return 1 | ||
|
|
||
| print( | ||
| f"PASS: {WORKFLOW} pins {REUSABLE}{EXPECTED_REF} and skips {DEPENDABOT_ACTOR}" | ||
| ) | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.