Skip to content

Commit f453dcd

Browse files
authored
Merge branch 'main' into main
2 parents 6d723fa + 53fd724 commit f453dcd

File tree

3,330 files changed

+138604
-65546
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,330 files changed

+138604
-65546
lines changed

.github/workflows/commit-access-review.py

Lines changed: 47 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -62,57 +62,9 @@ def __repr__(self):
6262
)
6363

6464

65-
def run_graphql_query(
66-
query: str, variables: dict, token: str, retry: bool = True
67-
) -> dict:
68-
"""
69-
This function submits a graphql query and returns the results as a
70-
dictionary.
71-
"""
72-
s = requests.Session()
73-
retries = requests.adapters.Retry(total=8, backoff_factor=2, status_forcelist=[504])
74-
s.mount("https://", requests.adapters.HTTPAdapter(max_retries=retries))
75-
76-
headers = {
77-
"Authorization": "bearer {}".format(token),
78-
# See
79-
# https://github.blog/2021-11-16-graphql-global-id-migration-update/
80-
"X-Github-Next-Global-ID": "1",
81-
}
82-
request = s.post(
83-
url="https://api.github.com/graphql",
84-
json={"query": query, "variables": variables},
85-
headers=headers,
86-
)
87-
88-
rate_limit = request.headers.get("X-RateLimit-Remaining")
89-
print(rate_limit)
90-
if rate_limit and int(rate_limit) < 10:
91-
reset_time = int(request.headers["X-RateLimit-Reset"])
92-
while reset_time - int(time.time()) > 0:
93-
time.sleep(60)
94-
print(
95-
"Waiting until rate limit reset",
96-
reset_time - int(time.time()),
97-
"seconds remaining",
98-
)
99-
100-
if request.status_code == 200:
101-
if "data" not in request.json():
102-
print(request.json())
103-
sys.exit(1)
104-
return request.json()["data"]
105-
elif retry:
106-
return run_graphql_query(query, variables, token, False)
107-
else:
108-
raise Exception(
109-
"Failed to run graphql query\nquery: {}\nerror: {}".format(
110-
query, request.json()
111-
)
112-
)
113-
114-
115-
def check_manual_requests(start_date: datetime.datetime, token: str) -> list[str]:
65+
def check_manual_requests(
66+
gh: github.Github, start_date: datetime.datetime
67+
) -> list[str]:
11668
"""
11769
Return a list of users who have been asked since ``start_date`` if they
11870
want to keep their commit access.
@@ -137,18 +89,21 @@ def check_manual_requests(start_date: datetime.datetime, token: str) -> list[str
13789
"""
13890
formatted_start_date = start_date.strftime("%Y-%m-%dT%H:%M:%S")
13991
variables = {
140-
"query": f"type:issue created:>{formatted_start_date} org:llvm repo:llvm-project label:infrastructure:commit-access"
92+
"query": f"type:issue created:>{formatted_start_date} org:llvm repo:llvm-project label:infra:commit-access"
14193
}
14294

143-
data = run_graphql_query(query, variables, token)
95+
res_header, res_data = gh._Github__requester.graphql_query(
96+
query=query, variables=variables
97+
)
98+
data = res_data["data"]
14499
users = []
145100
for issue in data["search"]["nodes"]:
146101
users.extend([user[1:] for user in re.findall("@[^ ,\n]+", issue["body"])])
147102

148103
return users
149104

150105

151-
def get_num_commits(user: str, start_date: datetime.datetime, token: str) -> int:
106+
def get_num_commits(gh: github.Github, user: str, start_date: datetime.datetime) -> int:
152107
"""
153108
Get number of commits that ``user`` has been made since ``start_date`.
154109
"""
@@ -166,7 +121,10 @@ def get_num_commits(user: str, start_date: datetime.datetime, token: str) -> int
166121
}
167122
"""
168123

169-
data = run_graphql_query(user_query, variables, token)
124+
res_header, res_data = gh._Github__requester.graphql_query(
125+
query=user_query, variables=variables
126+
)
127+
data = res_data["data"]
170128
variables["user_id"] = data["user"]["id"]
171129

172130
query = """
@@ -193,7 +151,10 @@ def get_num_commits(user: str, start_date: datetime.datetime, token: str) -> int
193151
}
194152
"""
195153
count = 0
196-
data = run_graphql_query(query, variables, token)
154+
res_header, res_data = gh._Github__requester.graphql_query(
155+
query=query, variables=variables
156+
)
157+
data = res_data["data"]
197158
for repo in data["organization"]["teams"]["nodes"][0]["repositories"]["nodes"]:
198159
count += int(repo["ref"]["target"]["history"]["totalCount"])
199160
if count >= User.THRESHOLD:
@@ -202,7 +163,7 @@ def get_num_commits(user: str, start_date: datetime.datetime, token: str) -> int
202163

203164

204165
def is_new_committer_query_repo(
205-
user: str, start_date: datetime.datetime, token: str
166+
gh: github.Github, user: str, start_date: datetime.datetime
206167
) -> bool:
207168
"""
208169
Determine if ``user`` is a new committer. A new committer can keep their
@@ -220,7 +181,10 @@ def is_new_committer_query_repo(
220181
}
221182
"""
222183

223-
data = run_graphql_query(user_query, variables, token)
184+
res_header, res_data = gh._Github__requester.graphql_query(
185+
query=user_query, variables=variables
186+
)
187+
data = res_data["data"]
224188
variables["owner"] = "llvm"
225189
variables["user_id"] = data["user"]["id"]
226190
variables["start_date"] = start_date.strftime("%Y-%m-%dT%H:%M:%S")
@@ -245,7 +209,10 @@ def is_new_committer_query_repo(
245209
}
246210
"""
247211

248-
data = run_graphql_query(query, variables, token)
212+
res_header, res_data = gh._Github__requester.graphql_query(
213+
query=query, variables=variables
214+
)
215+
data = res_data["data"]
249216
repo = data["organization"]["repository"]
250217
commits = repo["ref"]["target"]["history"]["nodes"]
251218
if len(commits) == 0:
@@ -256,18 +223,22 @@ def is_new_committer_query_repo(
256223
return True
257224

258225

259-
def is_new_committer(user: str, start_date: datetime.datetime, token: str) -> bool:
226+
def is_new_committer(
227+
gh: github.Github, user: str, start_date: datetime.datetime
228+
) -> bool:
260229
"""
261230
Wrapper around is_new_commiter_query_repo to handle exceptions.
262231
"""
263232
try:
264-
return is_new_committer_query_repo(user, start_date, token)
233+
return is_new_committer_query_repo(gh, user, start_date)
265234
except:
266235
pass
267236
return True
268237

269238

270-
def get_review_count(user: str, start_date: datetime.datetime, token: str) -> int:
239+
def get_review_count(
240+
gh: github.Github, user: str, start_date: datetime.datetime
241+
) -> int:
271242
"""
272243
Return the number of reviews that ``user`` has done since ``start_date``.
273244
"""
@@ -286,11 +257,14 @@ def get_review_count(user: str, start_date: datetime.datetime, token: str) -> in
286257
"query": f"type:pr commenter:{user} -author:{user} merged:>{formatted_start_date} org:llvm",
287258
}
288259

289-
data = run_graphql_query(query, variables, token)
260+
res_header, res_data = gh._Github__requester.graphql_query(
261+
query=query, variables=variables
262+
)
263+
data = res_data["data"]
290264
return int(data["search"]["issueCount"])
291265

292266

293-
def count_prs(triage_list: dict, start_date: datetime.datetime, token: str):
267+
def count_prs(gh: github.Github, triage_list: dict, start_date: datetime.datetime):
294268
"""
295269
Fetch all the merged PRs for the project since ``start_date`` and update
296270
``triage_list`` with the number of PRs merged for each user.
@@ -329,7 +303,10 @@ def count_prs(triage_list: dict, start_date: datetime.datetime, token: str):
329303
has_next_page = True
330304
while has_next_page:
331305
print(variables)
332-
data = run_graphql_query(query, variables, token)
306+
res_header, res_data = gh._Github__requester.graphql_query(
307+
query=query, variables=variables
308+
)
309+
data = res_data["data"]
333310
for pr in data["search"]["nodes"]:
334311
# Users can be None if the user has been deleted.
335312
if not pr["author"]:
@@ -365,14 +342,14 @@ def main():
365342

366343
print("Start:", len(triage_list), "triagers")
367344
# Step 0 Check if users have requested commit access in the last year.
368-
for user in check_manual_requests(one_year_ago, token):
345+
for user in check_manual_requests(gh, one_year_ago):
369346
if user in triage_list:
370347
print(user, "requested commit access in the last year.")
371348
del triage_list[user]
372349
print("After Request Check:", len(triage_list), "triagers")
373350

374351
# Step 1 count all PRs authored or merged
375-
count_prs(triage_list, one_year_ago, token)
352+
count_prs(gh, triage_list, one_year_ago)
376353

377354
print("After PRs:", len(triage_list), "triagers")
378355

@@ -381,7 +358,7 @@ def main():
381358

382359
# Step 2 check for reviews
383360
for user in list(triage_list.keys()):
384-
review_count = get_review_count(user, one_year_ago, token)
361+
review_count = get_review_count(gh, user, one_year_ago)
385362
triage_list[user].add_reviewed(review_count)
386363

387364
print("After Reviews:", len(triage_list), "triagers")
@@ -391,7 +368,7 @@ def main():
391368

392369
# Step 3 check for number of commits
393370
for user in list(triage_list.keys()):
394-
num_commits = get_num_commits(user, one_year_ago, token)
371+
num_commits = get_num_commits(gh, user, one_year_ago)
395372
# Override the total number of commits to not double count commits and
396373
# authored PRs.
397374
triage_list[user].set_authored(num_commits)
@@ -401,7 +378,7 @@ def main():
401378
# Step 4 check for new committers
402379
for user in list(triage_list.keys()):
403380
print("Checking", user)
404-
if is_new_committer(user, one_year_ago, token):
381+
if is_new_committer(gh, user, one_year_ago):
405382
print("Removing new committer: ", user)
406383
del triage_list[user]
407384

.github/workflows/docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,14 @@ jobs:
148148
cmake -B libunwind-build -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RUNTIMES="libunwind" -DLLVM_ENABLE_SPHINX=ON ./runtimes
149149
TZ=UTC ninja -C libunwind-build docs-libunwind-html
150150
mkdir built-docs/libunwind
151-
cp -r libunwind-build/docs/* built-docs/libunwind
151+
cp -r libunwind-build/libunwind/docs/* built-docs/libunwind
152152
- name: Build libcxx docs
153153
if: steps.docs-changed-subprojects.outputs.libcxx_any_changed == 'true'
154154
run: |
155155
cmake -B libcxx-build -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RUNTIMES="libcxxabi;libcxx;libunwind" -DLLVM_ENABLE_SPHINX=ON ./runtimes
156156
TZ=UTC ninja -C libcxx-build docs-libcxx-html
157157
mkdir built-docs/libcxx
158-
cp -r libcxx-build/docs/* built-docs/libcxx/
158+
cp -r libcxx-build/libcxx/docs/* built-docs/libcxx/
159159
- name: Build libc docs
160160
if: steps.docs-changed-subprojects.outputs.libc_any_changed == 'true'
161161
run: |

.github/workflows/libcxx-restart-preempted-jobs.yaml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,91 @@ jobs:
130130
run_id: context.payload.workflow_run.id
131131
})
132132
await create_check_run('success', 'Restarted workflow run due to preempted job')
133+
134+
restart-test:
135+
if: github.repository_owner == 'llvm' && (github.event.workflow_run.conclusion == 'failure' || github.event.workflow_run.conclusion == 'cancelled') && github.event.actor.login == 'ldionne' # TESTING ONLY
136+
name: "Restart Job (test)"
137+
permissions:
138+
statuses: read
139+
checks: write
140+
actions: write
141+
runs-on: ubuntu-latest
142+
steps:
143+
- name: "Restart Job (test)"
144+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1
145+
with:
146+
script: |
147+
const FAILURE_REGEX = /Process completed with exit code 1./
148+
const PREEMPTION_REGEX = /(The runner has received a shutdown signal)|(The operation was canceled)/
149+
150+
function log(msg) {
151+
core.notice(msg)
152+
}
153+
154+
const wf_run = context.payload.workflow_run
155+
log(`Running on "${wf_run.display_title}" by @${wf_run.actor.login} (event: ${wf_run.event})\nWorkflow run URL: ${wf_run.html_url}`)
156+
157+
log('Listing check runs for suite')
158+
const check_suites = await github.rest.checks.listForSuite({
159+
owner: context.repo.owner,
160+
repo: context.repo.repo,
161+
check_suite_id: context.payload.workflow_run.check_suite_id,
162+
per_page: 100 // FIXME: We don't have 100 check runs yet, but we should handle this better.
163+
})
164+
165+
preemptions = [];
166+
legitimate_failures = [];
167+
for (check_run of check_suites.data.check_runs) {
168+
log(`Checking check run: ${check_run.id}`);
169+
if (check_run.status != 'completed') {
170+
log('Check run was not completed. Skipping.');
171+
continue;
172+
}
173+
174+
if (check_run.conclusion != 'failure' && check_run.conclusion != 'cancelled') {
175+
log(`Check run had conclusion: ${check_run.conclusion}. Skipping.`);
176+
continue;
177+
}
178+
179+
annotations = await github.rest.checks.listAnnotations({
180+
owner: context.repo.owner,
181+
repo: context.repo.repo,
182+
check_run_id: check_run.id
183+
})
184+
185+
preemption_annotation = annotations.data.find(function(annotation) {
186+
return annotation.annotation_level == 'failure' &&
187+
annotation.message.match(PREEMPTION_REGEX) != null;
188+
});
189+
if (preemption_annotation != null) {
190+
log(`Found preemption message: ${preemption_annotation.message}`);
191+
preemptions.push(check_run);
192+
break;
193+
}
194+
195+
failure_annotation = annotations.data.find(function(annotation) {
196+
return annotation.annotation_level == 'failure' &&
197+
annotation.message.match(FAILURE_REGEX) != null;
198+
});
199+
if (failure_annotation != null) {
200+
log(`Found legitimate failure annotation: ${failure_annotation.message}`);
201+
legitimate_failures.push(check_run);
202+
break;
203+
}
204+
}
205+
206+
if (preemptions) {
207+
log('Found some preempted jobs');
208+
if (legitimate_failures) {
209+
log('Also found some legitimate failures, so not restarting the workflow.');
210+
} else {
211+
log('Did not find any legitimate failures. Restarting workflow.');
212+
await github.rest.actions.reRunWorkflowFailedJobs({
213+
owner: context.repo.owner,
214+
repo: context.repo.repo,
215+
run_id: context.payload.workflow_run.id
216+
})
217+
}
218+
} else {
219+
log('Did not find any preempted jobs. Not restarting the workflow.');
220+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ autoconf/autom4te.cache
5959
# VS2017 and VSCode config files.
6060
.vscode
6161
.vs
62+
#zed config files
63+
.zed
6264
# pythonenv for github Codespaces
6365
pythonenv*
6466
# clangd index. (".clangd" is a config file now, thus trailing slash)

0 commit comments

Comments
 (0)