-
Notifications
You must be signed in to change notification settings - Fork 46k
ci: cut Actions spend across PR/push triggers #12955
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
Closed
Closed
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1ec53c5
ci: cut Actions spend across PR/push triggers
Swiftyos ffed9da
switch conflicts check to dev as thats our working branch
Swiftyos 709a1ad
revert changes to repo workflow checker
Swiftyos 184e53d
add startup delay
Swiftyos 494a916
guard against http failures
Swiftyos 0a7b8df
ci: block upstream gate on missing runs and tie-break on run_attempt
Swiftyos 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,16 +37,16 @@ jobs: | |
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Set up Python 3.12 | ||
| - name: Set up Python 3.13 | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.12" | ||
| python-version: "3.13" | ||
|
|
||
| - name: Set up Python dependency cache | ||
| uses: actions/cache@v5 | ||
| with: | ||
| path: ~/.cache/pypoetry | ||
| key: poetry-${{ runner.os }}-py3.12-${{ hashFiles('autogpt_platform/backend/poetry.lock') }} | ||
| key: poetry-${{ runner.os }}-py3.13-${{ hashFiles('autogpt_platform/backend/poetry.lock') }} | ||
|
|
||
| - name: Install Poetry | ||
| run: | | ||
|
|
@@ -68,26 +68,22 @@ jobs: | |
| permissions: | ||
| contents: read | ||
| timeout-minutes: 10 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| python-version: ["3.11", "3.12", "3.13"] | ||
|
Comment on lines
-71
to
-74
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please put this back, it doesn't save us anything and costs cross-version coverage
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same below |
||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Set up Python ${{ matrix.python-version }} | ||
| - name: Set up Python 3.13 | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| python-version: "3.13" | ||
|
|
||
| - name: Set up Python dependency cache | ||
| uses: actions/cache@v5 | ||
| with: | ||
| path: ~/.cache/pypoetry | ||
| key: poetry-${{ runner.os }}-py${{ matrix.python-version }}-${{ hashFiles('autogpt_platform/backend/poetry.lock') }} | ||
| key: poetry-${{ runner.os }}-py3.13-${{ hashFiles('autogpt_platform/backend/poetry.lock') }} | ||
|
|
||
| - name: Install Poetry | ||
| run: | | ||
|
|
@@ -102,7 +98,7 @@ jobs: | |
| run: poetry run prisma generate && poetry run gen-prisma-stub | ||
|
|
||
| - name: Run Pyright | ||
| run: poetry run pyright --pythonversion ${{ matrix.python-version }} | ||
| run: poetry run pyright --pythonversion 3.13 | ||
|
|
||
| env: | ||
| CI: true | ||
|
|
@@ -112,10 +108,6 @@ jobs: | |
| permissions: | ||
| contents: read | ||
| timeout-minutes: 15 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| python-version: ["3.11", "3.12", "3.13"] | ||
| runs-on: ubuntu-latest | ||
|
|
||
| services: | ||
|
|
@@ -163,10 +155,10 @@ jobs: | |
| fetch-depth: 0 | ||
| submodules: true | ||
|
|
||
| - name: Set up Python ${{ matrix.python-version }} | ||
| - name: Set up Python 3.13 | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| python-version: "3.13" | ||
|
|
||
| - name: Start Redis Cluster (3 shards) | ||
| run: | | ||
|
|
@@ -243,7 +235,7 @@ jobs: | |
| uses: actions/cache@v5 | ||
| with: | ||
| path: ~/.cache/pypoetry | ||
| key: poetry-${{ runner.os }}-py${{ matrix.python-version }}-${{ hashFiles('autogpt_platform/backend/poetry.lock') }} | ||
| key: poetry-${{ runner.os }}-py3.13-${{ hashFiles('autogpt_platform/backend/poetry.lock') }} | ||
|
|
||
| - name: Install Poetry | ||
| run: | | ||
|
|
||
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,167 @@ | ||
| """Wait for upstream workflow runs (by display name) on the given head SHA. | ||
|
|
||
| Used by platform-fullstack-ci's preflight job to gate the expensive | ||
| big-boi E2E job: only run E2E if every listed upstream workflow has | ||
| completed successfully on the same SHA. Outputs ``proceed=true|false`` | ||
| to ``$GITHUB_OUTPUT`` for downstream ``if:`` conditions. | ||
|
|
||
| A workflow that did not trigger for this SHA at all (e.g. excluded by a | ||
| ``paths`` filter) is treated as a non-blocker — we only block when an | ||
| upstream workflow ran and failed. | ||
| """ | ||
|
|
||
| import os | ||
| import sys | ||
| import time | ||
| from typing import Dict, List, Optional | ||
|
|
||
| import requests | ||
|
|
||
| REQUEST_TIMEOUT = 15 | ||
| # Wait this long before we even start polling — gives webhooks + | ||
| # workflow registration time on busy queues. | ||
| INITIAL_DELAY = 60 | ||
| POLL_INTERVAL = 30 | ||
| MAX_WAIT_SECONDS = 90 * 60 | ||
| # Grace period (measured from preflight start) during which a missing | ||
| # upstream workflow is treated as "still pending registration" rather | ||
| # than "path-filtered out / never going to run". Without this, a slow | ||
| # webhook delivery could let us emit proceed=true before backend/frontend | ||
| # CI have even appeared on the SHA — defeating the cost guard. | ||
| MISSING_GRACE_SECONDS = 10 * 60 | ||
|
|
||
|
|
||
| def get_env() -> Optional[Dict[str, object]]: | ||
| raw = os.environ.get("UPSTREAM_WORKFLOWS", "") | ||
| workflows = [w.strip() for w in raw.splitlines() if w.strip()] | ||
| if not workflows: | ||
| return None | ||
| return { | ||
| "api": os.environ["GITHUB_API_URL"], | ||
| "repo": os.environ["GITHUB_REPOSITORY"], | ||
| "sha": os.environ["HEAD_SHA"], | ||
| "token": os.environ["GITHUB_TOKEN"], | ||
| "workflows": workflows, | ||
| } | ||
|
|
||
|
|
||
| def fetch_runs(env: Dict[str, object], headers: Dict[str, str]) -> List[Dict]: | ||
| runs: List[Dict] = [] | ||
| url = ( | ||
| f"{env['api']}/repos/{env['repo']}/actions/runs" | ||
| f"?head_sha={env['sha']}&per_page=100" | ||
| ) | ||
| while url: | ||
| response = requests.get(url, headers=headers, timeout=REQUEST_TIMEOUT) | ||
| response.raise_for_status() | ||
| runs.extend(response.json().get("workflow_runs", [])) | ||
| next_url = None | ||
| for part in response.headers.get("Link", "").split(","): | ||
| if 'rel="next"' in part: | ||
| next_url = part.split(";")[0].strip().strip("<>") | ||
| break | ||
| url = next_url | ||
| return runs | ||
|
|
||
|
|
||
| def latest_per_workflow(runs: List[Dict], names: List[str]) -> Dict[str, Dict]: | ||
| by_name: Dict[str, Dict] = {} | ||
| name_set = set(names) | ||
| for run in runs: | ||
| name = run.get("name") | ||
| if name not in name_set: | ||
| continue | ||
| prev = by_name.get(name) | ||
| if prev is None or run["run_number"] > prev["run_number"]: | ||
| by_name[name] = run | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| return by_name | ||
|
|
||
|
|
||
| def write_output(key: str, value: str) -> None: | ||
| out = os.environ.get("GITHUB_OUTPUT") | ||
| if out: | ||
| with open(out, "a") as f: | ||
| f.write(f"{key}={value}\n") | ||
| print(f"output: {key}={value}") | ||
|
|
||
|
|
||
| def main() -> None: | ||
| env = get_env() | ||
| if env is None: | ||
| print("No UPSTREAM_WORKFLOWS configured; proceeding.") | ||
| write_output("proceed", "true") | ||
| return | ||
|
|
||
| headers = { | ||
| "Accept": "application/vnd.github+json", | ||
| "Authorization": f"Bearer {env['token']}", | ||
| "X-GitHub-Api-Version": "2022-11-28", | ||
| } | ||
|
|
||
| print(f"Gating on upstream workflows for SHA {env['sha']}:") | ||
| for w in env["workflows"]: | ||
| print(f" - {w}") | ||
| start = time.monotonic() | ||
| print(f"Initial delay {INITIAL_DELAY}s to let upstream runs register...") | ||
| time.sleep(INITIAL_DELAY) | ||
|
|
||
| deadline = start + MAX_WAIT_SECONDS | ||
| grace_deadline = start + MISSING_GRACE_SECONDS | ||
|
|
||
| while True: | ||
| runs = fetch_runs(env, headers) | ||
| by_name = latest_per_workflow(runs, env["workflows"]) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| missing = [w for w in env["workflows"] if w not in by_name] | ||
| in_progress = [ | ||
| w for w, r in by_name.items() if r["status"] != "completed" | ||
| ] | ||
| failed = [ | ||
| f"{w}={by_name[w]['conclusion']}" | ||
| for w in by_name | ||
| if by_name[w]["status"] == "completed" | ||
| and by_name[w]["conclusion"] not in ("success", "skipped", "neutral") | ||
| ] | ||
|
|
||
| if failed: | ||
| print(f"Upstream failed: {failed}") | ||
| write_output("proceed", "false") | ||
| return | ||
|
|
||
| # Don't treat "missing" as "skipped" until the grace period | ||
| # has fully elapsed — otherwise a slow webhook / queue could | ||
| # let us pass the gate before backend/frontend CI even appears. | ||
| if missing and time.monotonic() < grace_deadline: | ||
| remaining = int(grace_deadline - time.monotonic()) | ||
| print( | ||
| f"Waiting (within {MISSING_GRACE_SECONDS}s grace, " | ||
| f"{remaining}s left): missing={missing}, " | ||
| f"in_progress={in_progress}" | ||
| ) | ||
| time.sleep(POLL_INTERVAL) | ||
| continue | ||
|
|
||
| if not in_progress: | ||
| if missing: | ||
| print( | ||
| "Workflow(s) did not trigger after grace period " | ||
| f"(treating as skipped): {missing}" | ||
| ) | ||
| print(f"Upstream passed: {list(by_name.keys())}") | ||
| write_output("proceed", "true") | ||
| return | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| if time.monotonic() > deadline: | ||
| print( | ||
| f"Timeout after {MAX_WAIT_SECONDS}s; still in_progress=" | ||
| f"{in_progress}, missing={missing}" | ||
| ) | ||
| write_output("proceed", "false") | ||
| sys.exit(1) | ||
|
|
||
| print(f"Waiting: in_progress={in_progress}, missing={missing}") | ||
| time.sleep(POLL_INTERVAL) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
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.
let's keep these rather than
classic/**.py;