Skip to content

Commit f56e272

Browse files
authored
RS migration - trymerge to upload merge records to s3 (#448)
1 parent 2741151 commit f56e272

File tree

3 files changed

+50
-52
lines changed

3 files changed

+50
-52
lines changed

.github/scripts/trymerge.py

+30-52
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,6 @@ def merge_into(
11631163
# Finally, upload the record to Rockset. The list of pending and failed
11641164
# checks are at the time of the merge
11651165
save_merge_record(
1166-
collection=ROCKSET_MERGES_COLLECTION,
11671166
comment_id=comment_id,
11681167
pr_num=self.pr_num,
11691168
owner=self.org,
@@ -1179,10 +1178,8 @@ def merge_into(
11791178
merge_base_sha=self.get_merge_base(),
11801179
merge_commit_sha=merge_commit_sha,
11811180
is_failed=False,
1182-
dry_run=dry_run,
11831181
skip_mandatory_checks=skip_mandatory_checks,
11841182
ignore_current=bool(ignore_current_checks),
1185-
workspace=ROCKSET_MERGES_WORKSPACE,
11861183
)
11871184
else:
11881185
print("Missing comment ID or PR number, couldn't upload to Rockset")
@@ -1489,7 +1486,6 @@ def checks_to_markdown_bullets(
14891486

14901487
@retries_decorator()
14911488
def save_merge_record(
1492-
collection: str,
14931489
comment_id: int,
14941490
pr_num: int,
14951491
owner: str,
@@ -1505,59 +1501,44 @@ def save_merge_record(
15051501
merge_base_sha: str,
15061502
merge_commit_sha: str = "",
15071503
is_failed: bool = False,
1508-
dry_run: bool = False,
15091504
skip_mandatory_checks: bool = False,
15101505
ignore_current: bool = False,
15111506
error: str = "",
1512-
workspace: str = "commons",
15131507
) -> None:
15141508
"""
1515-
This saves the merge records into Rockset, so we can query them (for fun and profit)
1509+
This saves the merge records as a json, which can later be uploaded to s3
15161510
"""
1517-
if dry_run:
1518-
# Decide not to save the record to Rockset if dry-run is set to not pollute
1519-
# the collection
1520-
return
1521-
1522-
try:
1523-
import rockset # type: ignore[import]
1524-
1525-
# Prepare the record to be written into Rockset
1526-
data = [
1527-
{
1528-
"comment_id": comment_id,
1529-
"pr_num": pr_num,
1530-
"owner": owner,
1531-
"project": project,
1532-
"author": author,
1533-
"pending_checks": pending_checks,
1534-
"failed_checks": failed_checks,
1535-
"ignore_current_checks": ignore_current_checks,
1536-
"broken_trunk_checks": broken_trunk_checks,
1537-
"flaky_checks": flaky_checks,
1538-
"unstable_checks": unstable_checks,
1539-
"last_commit_sha": last_commit_sha,
1540-
"merge_base_sha": merge_base_sha,
1541-
"merge_commit_sha": merge_commit_sha,
1542-
"is_failed": is_failed,
1543-
"skip_mandatory_checks": skip_mandatory_checks,
1544-
"ignore_current": ignore_current,
1545-
"error": error,
1546-
}
1547-
]
15481511

1549-
client = rockset.RocksetClient(
1550-
host="api.usw2a1.rockset.com", api_key=os.environ["ROCKSET_API_KEY"]
1551-
)
1552-
client.Documents.add_documents(
1553-
collection=collection,
1554-
data=data,
1555-
workspace=workspace,
1556-
)
1512+
# Prepare the record to be written into Rockset
1513+
data = [
1514+
{
1515+
"comment_id": comment_id,
1516+
"pr_num": pr_num,
1517+
"owner": owner,
1518+
"project": project,
1519+
"author": author,
1520+
"pending_checks": pending_checks,
1521+
"failed_checks": failed_checks,
1522+
"ignore_current_checks": ignore_current_checks,
1523+
"broken_trunk_checks": broken_trunk_checks,
1524+
"flaky_checks": flaky_checks,
1525+
"unstable_checks": unstable_checks,
1526+
"last_commit_sha": last_commit_sha,
1527+
"merge_base_sha": merge_base_sha,
1528+
"merge_commit_sha": merge_commit_sha,
1529+
"is_failed": is_failed,
1530+
"skip_mandatory_checks": skip_mandatory_checks,
1531+
"ignore_current": ignore_current,
1532+
"error": error,
1533+
# This is a unique identifier for the record for deduping purposes
1534+
# in rockset. Any unique string would work
1535+
"_id": f"{project}-{pr_num}-{comment_id}-{os.environ.get('GITHUB_RUN_ID')}",
1536+
}
1537+
]
1538+
repo_root = Path(__file__).resolve().parent.parent.parent
15571539

1558-
except ModuleNotFoundError:
1559-
print("Rockset is missing, no record will be saved")
1560-
return
1540+
with open(repo_root / "merge_record.json", "w") as f:
1541+
json.dump(data, f)
15611542

15621543

15631544
@retries_decorator(rc=[])
@@ -2374,7 +2355,6 @@ def handle_exception(e: Exception, title: str = "Merge failed") -> None:
23742355
# list of pending and failed checks here, but they are not really
23752356
# needed at the moment
23762357
save_merge_record(
2377-
collection=ROCKSET_MERGES_COLLECTION,
23782358
comment_id=args.comment_id,
23792359
pr_num=args.pr_num,
23802360
owner=org,
@@ -2389,11 +2369,9 @@ def handle_exception(e: Exception, title: str = "Merge failed") -> None:
23892369
last_commit_sha=pr.last_commit().get("oid", ""),
23902370
merge_base_sha=pr.get_merge_base(),
23912371
is_failed=True,
2392-
dry_run=args.dry_run,
23932372
skip_mandatory_checks=args.force,
23942373
ignore_current=args.ignore_current,
23952374
error=str(e),
2396-
workspace=ROCKSET_MERGES_WORKSPACE,
23972375
)
23982376
else:
23992377
print("Missing comment ID or PR number, couldn't upload to Rockset")

.github/workflows/trymerge.yml

+19
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ jobs:
99
name: try_merge_pr_${{ github.event.client_payload.pr_num }}
1010
runs-on: ubuntu-latest
1111
environment: pytorchbot-env
12+
permissions:
13+
id-token: write
1214
env:
1315
GH_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
1416
steps:
@@ -45,6 +47,7 @@ jobs:
4547
IGNORE_CURRENT: ${{ github.event.client_payload.ignore_current }}
4648
ROCKSET_API_KEY: ${{ secrets.ROCKSET_API_KEY }}
4749
DRCI_BOT_KEY: ${{ secrets.DRCI_BOT_KEY }}
50+
GITHUB_RUN_ID: ${{ github.run_id }}
4851
run: |
4952
set -x
5053
if [ -n "${FORCE}" ]; then
@@ -65,6 +68,22 @@ jobs:
6568
python3 .github/scripts/trymerge.py "${PR_NUM}"
6669
fi
6770
71+
- name: configure aws credentials
72+
uses: aws-actions/configure-aws-credentials@v3
73+
continue-on-error: true
74+
with:
75+
role-to-assume: arn:aws:iam::308535385114:role/upload_to_ossci_raw_job_status
76+
aws-region: us-east-1
77+
78+
- name: Upload merge record to s3
79+
if: always()
80+
continue-on-error: true
81+
uses: seemethere/upload-artifact-s3@v5
82+
with:
83+
s3-bucket: ossci-raw-job-status
84+
s3-prefix: merges/${{ github.repository }}/${{ github.event.client_payload.pr_num }}/${{ github.event.client_payload.comment_id }}/${{ github.run_id }}
85+
path: merge_record.json
86+
6887
# We want newer merge commands to supercede old ones
6988
concurrency:
7089
group: try-merge-${{ github.event.client_payload.pr_num }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ env
127127
.circleci/scripts/COMMIT_MSG
128128
scripts/release_notes/*.json
129129
sccache-stats*.json
130+
merge_record.json
130131

131132
# These files get copied over on invoking setup.py
132133
torchgen/packaged/*

0 commit comments

Comments
 (0)