-
Notifications
You must be signed in to change notification settings - Fork 630
Trigger Tableau TDVT in connectors on snapshot publish and release (CON-264) #2875
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
+212
−0
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a6aed60
Trigger Tableau TDVT in connectors on snapshot publish and release
ShimonSte 6c475ea
Mirror Tableau TDVT results in nightly and release workflows.
ShimonSte d329310
Address review: strict correlation-id run matching in mirror_tdvt.py
ShimonSte 0b4f933
release.yml: read TDVT dispatch version from the VERSION file
ShimonSte 88250c0
Match TDVT runs by exact [corr:…] token in the run title.
ShimonSte 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
Some comments aren't visible on the classic Files Changed page.
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,148 @@ | ||
| #!/usr/bin/env python3 | ||
| """Dispatch Tableau TDVT and mirror its result. Used by nightly.yml and release.yml.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| import os | ||
| import subprocess | ||
| import sys | ||
| import time | ||
| from datetime import datetime, timedelta, timezone | ||
|
|
||
| TDVT_REPO = "ClickHouse/clickhouse-tableau-tdvt" | ||
| WORKFLOW = "tableau-tdvt.yml" | ||
| POLL_ATTEMPTS = 24 | ||
| POLL_INTERVAL_SEC = 15 | ||
| WATCH_INTERVAL_SEC = 30 | ||
| CREATED_FILTER_SKEW_SEC = 120 | ||
|
|
||
|
|
||
| def fail(message: str) -> None: | ||
| print(f"::error::{message}", file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| def gh_json(*args: str) -> dict | list: | ||
| result = subprocess.run(["gh", *args], check=True, capture_output=True, text=True) | ||
| return json.loads(result.stdout) | ||
|
|
||
|
|
||
| def gh_api_call(path: str, *fields: str) -> None: | ||
| args = ["gh", "api", path] | ||
| for field in fields: | ||
| flag = "-F" if field.startswith("client_payload[") else "-f" | ||
| args.extend([flag, field]) | ||
| subprocess.run(args, check=True) | ||
|
|
||
|
|
||
| def latest_run_id(repo: str) -> int: | ||
| data = gh_json( | ||
| "api", | ||
| f"repos/{repo}/actions/workflows/{WORKFLOW}/runs?event=repository_dispatch&per_page=1", | ||
| ) | ||
| runs = data.get("workflow_runs", []) | ||
| return runs[0]["id"] if runs else 0 | ||
|
|
||
|
|
||
| def list_runs(repo: str, created_since: str) -> list[dict]: | ||
| data = gh_json( | ||
| "api", | ||
| f"repos/{repo}/actions/workflows/{WORKFLOW}/runs" | ||
| f"?event=repository_dispatch&created=>={created_since}&per_page=20", | ||
| ) | ||
| return data.get("workflow_runs", []) | ||
|
|
||
|
|
||
| def title_has_correlation(display_title: str, correlation_id: str) -> bool: | ||
| # TDVT run-name: "... [corr:{correlation_id}]" — match the bracketed token exactly. | ||
| return f"[corr:{correlation_id}]" in display_title | ||
|
|
||
|
|
||
| def find_run_id(runs: list[dict], threshold: int, correlation_id: str) -> int | None: | ||
| matches = [ | ||
| run | ||
| for run in runs | ||
| if run.get("id", 0) > threshold | ||
| and title_has_correlation(run.get("display_title", ""), correlation_id) | ||
| ] | ||
| return matches[0]["id"] if len(matches) == 1 else None | ||
|
|
||
|
|
||
| def write_summary(version: str, run_url: str, info: dict) -> None: | ||
| path = os.environ.get("GITHUB_STEP_SUMMARY") | ||
| if not path: | ||
| return | ||
| lines = [ | ||
| f"## Tableau TDVT - clickhouse-jdbc `{version}`", | ||
| "", | ||
| f"[Full TDVT run]({run_url})", | ||
| "", | ||
| f"**Conclusion: {info.get('conclusion', '')}**", | ||
| "", | ||
| "| Job | Result |", | ||
| "|---|---|", | ||
| ] | ||
| for job in info.get("jobs", []): | ||
| result = job.get("conclusion") or job.get("status") or "" | ||
| lines.append(f"| {job.get('name', '')} | {result} |") | ||
| with open(path, "a", encoding="utf-8") as summary: | ||
| summary.write("\n".join(lines) + "\n") | ||
|
|
||
|
|
||
| def main() -> None: | ||
| parser = argparse.ArgumentParser(description=__doc__) | ||
| parser.add_argument("--event-type", required=True, choices=("jdbc-snapshot", "jdbc-release")) | ||
| parser.add_argument("--version", required=True) | ||
| parser.add_argument("--correlation-id", required=True) | ||
| parser.add_argument("--tdvt-repo", default=TDVT_REPO) | ||
| args = parser.parse_args() | ||
|
|
||
| if not os.environ.get("GH_TOKEN"): | ||
| fail("GH_TOKEN is required") | ||
|
|
||
| print( | ||
| f"Dispatching TDVT for clickhouse-jdbc {args.version} " | ||
| f"(correlation: {args.correlation_id})" | ||
| ) | ||
|
|
||
| prev_id = latest_run_id(args.tdvt_repo) | ||
| created_since = ( | ||
| datetime.now(timezone.utc) - timedelta(seconds=CREATED_FILTER_SKEW_SEC) | ||
| ).strftime("%Y-%m-%dT%H:%M:%SZ") | ||
| gh_api_call( | ||
| f"repos/{args.tdvt_repo}/dispatches", | ||
| f"event_type={args.event_type}", | ||
| f"client_payload[jdbc_version]={args.version}", | ||
| f"client_payload[correlation_id]={args.correlation_id}", | ||
| ) | ||
|
|
||
| run_id = None | ||
| for _ in range(POLL_ATTEMPTS): | ||
| run_id = find_run_id(list_runs(args.tdvt_repo, created_since), prev_id, args.correlation_id) | ||
| if run_id is not None: | ||
| break | ||
| time.sleep(POLL_INTERVAL_SEC) | ||
|
|
||
| if run_id is None: | ||
| fail(f"TDVT run for correlation id '{args.correlation_id}' did not appear after dispatch") | ||
|
|
||
| run_url = f"https://github.com/{args.tdvt_repo}/actions/runs/{run_id}" | ||
| print(f"TDVT run: {run_url}") | ||
|
|
||
| subprocess.run( | ||
| ["gh", "run", "watch", str(run_id), "--repo", args.tdvt_repo, "--interval", str(WATCH_INTERVAL_SEC)], | ||
| check=False, | ||
| ) | ||
| info = gh_json("run", "view", str(run_id), "--repo", args.tdvt_repo, "--json", "conclusion,jobs") | ||
| conclusion = info.get("conclusion") or "" | ||
| print(f"TDVT concluded: {conclusion}") | ||
| write_summary(args.version, run_url, info) | ||
|
|
||
| if conclusion != "success": | ||
| fail(f"Tableau TDVT did not pass (conclusion: {conclusion}) - {run_url}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| 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
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 |
|---|---|---|
|
|
@@ -65,3 +65,7 @@ performance/jmh-simple-results.json | |
| *.key | ||
| *.srl | ||
| *.csr | ||
|
|
||
| # Python | ||
| __pycache__/ | ||
| *.pyc | ||
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.