Skip to content

Commit 212efe7

Browse files
committed
Drop unnecessary changes
1 parent c7283b5 commit 212efe7

File tree

5 files changed

+171
-68
lines changed

5 files changed

+171
-68
lines changed

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

Lines changed: 83 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -62,56 +62,93 @@ def __repr__(self):
6262
)
6363

6464

65-
def check_manual_requests(
66-
gh: github.Github, start_date: datetime.datetime
67-
) -> list[str]:
65+
def run_graphql_query(
66+
query: str, variables: dict, token: str, retry: bool = True
67+
) -> dict:
6868
"""
69-
Return a list of users who have been asked since ``start_date`` if they
70-
want to keep their commit access or if they have applied for commit
71-
access since ``start_date``
69+
This function submits a graphql query and returns the results as a
70+
dictionary.
7271
"""
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+
73114

115+
def check_manual_requests(start_date: datetime.datetime, token: str) -> list[str]:
116+
"""
117+
Return a list of users who have been asked since ``start_date`` if they
118+
want to keep their commit access.
119+
"""
74120
query = """
75-
query ($query: String!, $after: String) {
76-
search(query: $query, type: ISSUE, first: 100, after: $after) {
121+
query ($query: String!) {
122+
search(query: $query, type: ISSUE, first: 100) {
77123
nodes {
78124
... on Issue {
79-
author {
80-
login
81-
}
82125
body
126+
comments (first: 100) {
127+
nodes {
128+
author {
129+
login
130+
}
131+
}
132+
}
83133
}
84134
}
85-
pageInfo {
86-
hasNextPage
87-
endCursor
88-
}
89135
}
90136
}
91137
"""
92138
formatted_start_date = start_date.strftime("%Y-%m-%dT%H:%M:%S")
93139
variables = {
94-
"query": f"type:issue created:>{formatted_start_date} org:llvm repo:llvm-project label:infra:commit-access,infra:commit-access-request"
140+
"query": f"type:issue created:>{formatted_start_date} org:llvm repo:llvm-project label:infrastructure:commit-access"
95141
}
96142

97-
has_next_page = True
143+
data = run_graphql_query(query, variables, token)
98144
users = []
99-
while has_next_page:
100-
res_header, res_data = gh._Github__requester.graphql_query(
101-
query=query, variables=variables
102-
)
103-
data = res_data["data"]
104-
for issue in data["search"]["nodes"]:
105-
users.extend([user[1:] for user in re.findall("@[^ ,\n]+", issue["body"])])
106-
if issue["author"]:
107-
users.append(issue["author"]["login"])
108-
has_next_page = data["search"]["pageInfo"]["hasNextPage"]
109-
if has_next_page:
110-
variables["after"] = data["search"]["pageInfo"]["endCursor"]
145+
for issue in data["search"]["nodes"]:
146+
users.extend([user[1:] for user in re.findall("@[^ ,\n]+", issue["body"])])
147+
111148
return users
112149

113150

114-
def get_num_commits(gh: github.Github, user: str, start_date: datetime.datetime) -> int:
151+
def get_num_commits(user: str, start_date: datetime.datetime, token: str) -> int:
115152
"""
116153
Get number of commits that ``user`` has been made since ``start_date`.
117154
"""
@@ -129,10 +166,7 @@ def get_num_commits(gh: github.Github, user: str, start_date: datetime.datetime)
129166
}
130167
"""
131168

132-
res_header, res_data = gh._Github__requester.graphql_query(
133-
query=user_query, variables=variables
134-
)
135-
data = res_data["data"]
169+
data = run_graphql_query(user_query, variables, token)
136170
variables["user_id"] = data["user"]["id"]
137171

138172
query = """
@@ -159,10 +193,7 @@ def get_num_commits(gh: github.Github, user: str, start_date: datetime.datetime)
159193
}
160194
"""
161195
count = 0
162-
res_header, res_data = gh._Github__requester.graphql_query(
163-
query=query, variables=variables
164-
)
165-
data = res_data["data"]
196+
data = run_graphql_query(query, variables, token)
166197
for repo in data["organization"]["teams"]["nodes"][0]["repositories"]["nodes"]:
167198
count += int(repo["ref"]["target"]["history"]["totalCount"])
168199
if count >= User.THRESHOLD:
@@ -171,7 +202,7 @@ def get_num_commits(gh: github.Github, user: str, start_date: datetime.datetime)
171202

172203

173204
def is_new_committer_query_repo(
174-
gh: github.Github, user: str, start_date: datetime.datetime
205+
user: str, start_date: datetime.datetime, token: str
175206
) -> bool:
176207
"""
177208
Determine if ``user`` is a new committer. A new committer can keep their
@@ -189,10 +220,7 @@ def is_new_committer_query_repo(
189220
}
190221
"""
191222

192-
res_header, res_data = gh._Github__requester.graphql_query(
193-
query=user_query, variables=variables
194-
)
195-
data = res_data["data"]
223+
data = run_graphql_query(user_query, variables, token)
196224
variables["owner"] = "llvm"
197225
variables["user_id"] = data["user"]["id"]
198226
variables["start_date"] = start_date.strftime("%Y-%m-%dT%H:%M:%S")
@@ -217,10 +245,7 @@ def is_new_committer_query_repo(
217245
}
218246
"""
219247

220-
res_header, res_data = gh._Github__requester.graphql_query(
221-
query=query, variables=variables
222-
)
223-
data = res_data["data"]
248+
data = run_graphql_query(query, variables, token)
224249
repo = data["organization"]["repository"]
225250
commits = repo["ref"]["target"]["history"]["nodes"]
226251
if len(commits) == 0:
@@ -231,22 +256,18 @@ def is_new_committer_query_repo(
231256
return True
232257

233258

234-
def is_new_committer(
235-
gh: github.Github, user: str, start_date: datetime.datetime
236-
) -> bool:
259+
def is_new_committer(user: str, start_date: datetime.datetime, token: str) -> bool:
237260
"""
238261
Wrapper around is_new_commiter_query_repo to handle exceptions.
239262
"""
240263
try:
241-
return is_new_committer_query_repo(gh, user, start_date)
264+
return is_new_committer_query_repo(user, start_date, token)
242265
except:
243266
pass
244267
return True
245268

246269

247-
def get_review_count(
248-
gh: github.Github, user: str, start_date: datetime.datetime
249-
) -> int:
270+
def get_review_count(user: str, start_date: datetime.datetime, token: str) -> int:
250271
"""
251272
Return the number of reviews that ``user`` has done since ``start_date``.
252273
"""
@@ -265,14 +286,11 @@ def get_review_count(
265286
"query": f"type:pr commenter:{user} -author:{user} merged:>{formatted_start_date} org:llvm",
266287
}
267288

268-
res_header, res_data = gh._Github__requester.graphql_query(
269-
query=query, variables=variables
270-
)
271-
data = res_data["data"]
289+
data = run_graphql_query(query, variables, token)
272290
return int(data["search"]["issueCount"])
273291

274292

275-
def count_prs(gh: github.Github, triage_list: dict, start_date: datetime.datetime):
293+
def count_prs(triage_list: dict, start_date: datetime.datetime, token: str):
276294
"""
277295
Fetch all the merged PRs for the project since ``start_date`` and update
278296
``triage_list`` with the number of PRs merged for each user.
@@ -311,10 +329,7 @@ def count_prs(gh: github.Github, triage_list: dict, start_date: datetime.datetim
311329
has_next_page = True
312330
while has_next_page:
313331
print(variables)
314-
res_header, res_data = gh._Github__requester.graphql_query(
315-
query=query, variables=variables
316-
)
317-
data = res_data["data"]
332+
data = run_graphql_query(query, variables, token)
318333
for pr in data["search"]["nodes"]:
319334
# Users can be None if the user has been deleted.
320335
if not pr["author"]:
@@ -350,14 +365,14 @@ def main():
350365

351366
print("Start:", len(triage_list), "triagers")
352367
# Step 0 Check if users have requested commit access in the last year.
353-
for user in check_manual_requests(gh, one_year_ago):
368+
for user in check_manual_requests(one_year_ago, token):
354369
if user in triage_list:
355370
print(user, "requested commit access in the last year.")
356371
del triage_list[user]
357372
print("After Request Check:", len(triage_list), "triagers")
358373

359374
# Step 1 count all PRs authored or merged
360-
count_prs(gh, triage_list, one_year_ago)
375+
count_prs(triage_list, one_year_ago, token)
361376

362377
print("After PRs:", len(triage_list), "triagers")
363378

@@ -366,7 +381,7 @@ def main():
366381

367382
# Step 2 check for reviews
368383
for user in list(triage_list.keys()):
369-
review_count = get_review_count(gh, user, one_year_ago)
384+
review_count = get_review_count(user, one_year_ago, token)
370385
triage_list[user].add_reviewed(review_count)
371386

372387
print("After Reviews:", len(triage_list), "triagers")
@@ -376,7 +391,7 @@ def main():
376391

377392
# Step 3 check for number of commits
378393
for user in list(triage_list.keys()):
379-
num_commits = get_num_commits(gh, user, one_year_ago)
394+
num_commits = get_num_commits(user, one_year_ago, token)
380395
# Override the total number of commits to not double count commits and
381396
# authored PRs.
382397
triage_list[user].set_authored(num_commits)
@@ -386,7 +401,7 @@ def main():
386401
# Step 4 check for new committers
387402
for user in list(triage_list.keys()):
388403
print("Checking", user)
389-
if is_new_committer(gh, user, one_year_ago):
404+
if is_new_committer(user, one_year_ago, token):
390405
print("Removing new committer: ", user)
391406
del triage_list[user]
392407

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/clang/cmake/caches/BOLT-PGO.cmake b/clang/cmake/caches/BOLT-PGO.cmake
2+
index 1a04ca9a74e5..d092820e4115 100644
3+
--- a/clang/cmake/caches/BOLT-PGO.cmake
4+
+++ b/clang/cmake/caches/BOLT-PGO.cmake
5+
@@ -4,6 +4,8 @@ set(CLANG_BOOTSTRAP_TARGETS
6+
stage2-clang-bolt
7+
stage2-distribution
8+
stage2-install-distribution
9+
+ clang
10+
+ lld
11+
CACHE STRING "")
12+
set(BOOTSTRAP_CLANG_BOOTSTRAP_TARGETS
13+
clang-bolt
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
FROM docker.io/library/ubuntu:22.04 as base
2+
ENV LLVM_SYSROOT=/opt/llvm
3+
4+
FROM base as stage1-toolchain
5+
ENV LLVM_VERSION=18.1.8
6+
7+
RUN apt-get update && \
8+
apt-get install -y \
9+
wget \
10+
gcc \
11+
g++ \
12+
cmake \
13+
ninja-build \
14+
python3 \
15+
git \
16+
curl
17+
18+
RUN curl -O -L https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-$LLVM_VERSION.tar.gz && tar -xf llvmorg-$LLVM_VERSION.tar.gz
19+
20+
WORKDIR /llvm-project-llvmorg-$LLVM_VERSION
21+
22+
COPY bootstrap.patch /
23+
24+
# TODO(boomanaiden154): Remove the bootstrap patch once we unsplit the build
25+
# and no longer need to explicitly build the stage2 dependencies.
26+
RUN cat /bootstrap.patch | patch -p1
27+
28+
RUN mkdir build
29+
30+
RUN cmake -B ./build -G Ninja ./llvm \
31+
-C ./clang/cmake/caches/BOLT-PGO.cmake \
32+
-DBOOTSTRAP_LLVM_ENABLE_LLD=ON \
33+
-DBOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_LLD=ON \
34+
-DPGO_INSTRUMENT_LTO=Thin \
35+
-DLLVM_ENABLE_RUNTIMES="compiler-rt" \
36+
-DCMAKE_INSTALL_PREFIX="$LLVM_SYSROOT" \
37+
-DLLVM_ENABLE_PROJECTS="bolt;clang;lld;clang-tools-extra" \
38+
-DLLVM_DISTRIBUTION_COMPONENTS="lld;compiler-rt;clang-format;scan-build" \
39+
-DCLANG_DEFAULT_LINKER="lld" \
40+
-DBOOTSTRAP_CLANG_PGO_TRAINING_DATA_SOURCE_DIR=/llvm-project-llvmorg-$LLVM_VERSION/llvm
41+
42+
RUN ninja -C ./build stage2-instrumented-clang stage2-instrumented-lld
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM docker.io/library/ubuntu:22.04 as base
2+
ENV LLVM_SYSROOT=/opt/llvm
3+
4+
FROM stage1-toolchain AS stage2-toolchain
5+
6+
RUN ninja -C ./build stage2-clang-bolt stage2-install-distribution && ninja -C ./build install-distribution && rm -rf ./build
7+
8+
FROM base
9+
10+
COPY --from=stage2-toolchain $LLVM_SYSROOT $LLVM_SYSROOT
11+
12+
# Need to install curl for hendrikmuhs/ccache-action
13+
# Need nodejs for some of the GitHub actions.
14+
# Need perl-modules for clang analyzer tests.
15+
# Need git for SPIRV-Tools tests.
16+
RUN apt-get update && \
17+
apt-get install -y \
18+
binutils \
19+
cmake \
20+
curl \
21+
git \
22+
libstdc++-11-dev \
23+
ninja-build \
24+
nodejs \
25+
perl-modules \
26+
python3-psutil
27+
28+
ENV LLVM_SYSROOT=$LLVM_SYSROOT
29+
ENV PATH=${LLVM_SYSROOT}/bin:${PATH}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[storage]
2+
driver = "overlay"
3+
runroot = "/mnt/podman/container"
4+
graphroot = "/mnt/podman/image"

0 commit comments

Comments
 (0)