8000 CI Linter Bot: add concurrency group and a link to the commit (#26638) · scikit-learn/scikit-learn@9477fc2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9477fc2

Browse files
adrinjalalijeremiedbb
authored andcommitted
CI Linter Bot: add concurrency group and a link to the commit (#26638)
1 parent 8a2bf90 commit 9477fc2

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

.github/workflows/lint.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ name: linter
66
on:
77
- pull_request_target
88

9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
913
jobs:
1014
lint:
1115
runs-on: ubuntu-latest
@@ -32,7 +36,11 @@ jobs:
3236
pip install pytest ruff $(get_dep mypy min) $(get_dep black min) cython-lint
3337
3438
- name: Run linting
35-
run: ./build_tools/linting.sh &> /tmp/linting_output.txt
39+
# We download the linting script from main, since this workflow is run
40+
# from main itself.
41+
run: |
42+
curl https://raw.githubusercontent.com/scikit-learn/scikit-learn/main/build_tools/linting.sh -o ./build_tools/linting.sh
43+
./build_tools/linting.sh &> /tmp/linting_output.txt
3644
3745
- name: Upload Artifact
3846
if: always()
@@ -78,6 +86,7 @@ jobs:
7886
env:
7987
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8088
PR_NUMBER: ${{ github.event.pull_request.number }}
89+
BRANCH_SHA: ${{ github.event.pull_request.head.sha }}
8190
RUN_ID: ${{ github.run_id }}
8291
LOG_FILE: linting_output.txt
8392
run: python ./build_tools/get_comment.py

build_tools/get_comment.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def get_step_message(log, start, end, title, message, details):
5252
return res
5353

5454

55-
def get_message(log_file, repo, run_id, details):
55+
def get_message(log_file, repo, pr_number, sha, run_id, details):
5656
with open(log_file, "r") as f:
5757
log = f.read()
5858

@@ -152,15 +152,21 @@ def get_message(log_file, repo, run_id, details):
152152
details=details,
153153
)
154154

155+
commit_link = (
156+
"\n\n_Generated for commit:"
157+
f" [{sha[:7]}](https://github.com/{repo}/pull/{pr_number}/commits/{sha})_"
158+
)
159+
155160
if not message:
156161
# no issues detected, so this script "fails"
157162
return (
158-
"## Linting Passed\n"
163+
"## ✔️ Linting Passed\n"
159164
"All linting checks passed. Your pull request is in excellent shape! ☀️"
165+
+ commit_link
160166
)
161167

162168
message = (
163-
"## Linting issues\n\n"
169+
"## Linting issues\n\n"
164170
"This PR is introducing linting issues. Here's a summary of the issues. "
165171
"Note that you can avoid having linting issues by enabling `pre-commit` "
166172
"hooks. Instructions to enable them can be found [here]("
@@ -169,6 +175,7 @@ def get_message(log_file, repo, run_id, details):
169175
"You can see the details of the linting issues under the `lint` job [here]"
170176
f"(https://github.com/{repo}/actions/runs/{run_id})\n\n"
171177
+ message
178+
+ commit_link
172179
)
173180

174181
return message
@@ -245,6 +252,7 @@ def create_or_update_comment(comment, message, repo, pr_number, token):
245252
repo = os.environ["GITHUB_REPOSITORY"]
246253
token = os.environ["GITHUB_TOKEN"]
247254
pr_number = os.environ["PR_NUMBER"]
255+
sha = os.environ["BRANCH_SHA"]
248256
log_file = os.environ["LOG_FILE"]
249257
run_id = os.environ["RUN_ID"]
250258

@@ -261,7 +269,14 @@ def create_or_update_comment(comment, message, repo, pr_number, token):
261269
exit(0)
262270

263271
try:
264-
message = get_message(log_file, repo=repo, run_id=run_id, details=True)
272+
message = get_message(
273+
log_file,
274+
repo=repo,
275+
pr_number=pr_number,
276+
sha=sha,
277+
run_id=run_id,
278+
details=True,
279+
)
265280
create_or_update_comment(
266281
comment=comment,
267282
message=message,
@@ -273,7 +288,14 @@ def create_or_update_comment(comment, message, repo, pr_number, token):
273288
except requests.HTTPError:
274289
# The above fails if the message is too long. In that case, we
275290
# try again without the details.
276-
message = get_message(log_file, repo=repo, run_id=run_id, details=False)
291+
message = get_message(
292+
log_file,
293+
repo=repo,
294+
pr_number=pr_number,
295+
sha=sha,
296+
run_id=run_id,
297+
details=False,
298+
)
277299
create_or_update_comment(
278300
comment=comment,
279301
message=message,

0 commit comments

Comments
 (0)
0