From b85e9481395e8444ffa0d5266b6ebbb2a2341823 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Tue, 20 Jun 2023 17:25:09 +0200 Subject: [PATCH 1/5] MNT Linter Bot: add concurrency group and a link to the commit for the comment --- .github/workflows/lint.yml | 1 + build_tools/get_comment.py | 31 ++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3ae009e45f26e..b15c97b30a26b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -78,6 +78,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_NUMBER: ${{ github.event.pull_request.number }} + BRANCH_SHA: ${{ github.event.pull_request.head.sha }} RUN_ID: ${{ github.run_id }} LOG_FILE: linting_output.txt run: python ./build_tools/get_comment.py diff --git a/build_tools/get_comment.py b/build_tools/get_comment.py index 5115a085ff8b5..85088ac3a3737 100644 --- a/build_tools/get_comment.py +++ b/build_tools/get_comment.py @@ -52,7 +52,7 @@ def get_step_message(log, start, end, title, message, details): return res -def get_message(log_file, repo, run_id, details): +def get_message(log_file, repo, pr_number, sha, run_id, details): with open(log_file, "r") as f: log = f.read() @@ -151,11 +151,17 @@ def get_message(log_file, repo, run_id, details): details=details, ) + commit_link = ( + "\n\n_Generated for commit:" + f" [{sha[:7]}](https://github.com/{repo}/pull/{pr_number}/commits/{sha})_" + ) + if not message: # no issues detected, so this script "fails" return ( "## Linting Passed\n" "All linting checks passed. Your pull request is in excellent shape! ☀️" + + commit_link ) message = ( @@ -168,6 +174,7 @@ def get_message(log_file, repo, run_id, details): "You can see the details of the linting issues under the `lint` job [here]" f"(https://github.com/{repo}/actions/runs/{run_id})\n\n" + message + + commit_link ) return message @@ -241,9 +248,13 @@ def create_or_update_comment(comment, message, repo, pr_number, token): if __name__ == "__main__": + for key, value in os.environ.items(): + print(f"{key}={value}") + repo = os.environ["GITHUB_REPOSITORY"] token = os.environ["GITHUB_TOKEN"] pr_number = os.environ["PR_NUMBER"] + sha = os.environ["BRANCH_SHA"] log_file = os.environ["LOG_FILE"] run_id = os.environ["RUN_ID"] @@ -260,7 +271,14 @@ def create_or_update_comment(comment, message, repo, pr_number, token): exit(0) try: - message = get_message(log_file, repo=repo, run_id=run_id, details=True) + message = get_message( + log_file, + repo=repo, + pr_number=pr_number, + sha=sha, + run_id=run_id, + details=True, + ) create_or_update_comment( comment=comment, message=message, @@ -272,7 +290,14 @@ def create_or_update_comment(comment, message, repo, pr_number, token): except requests.HTTPError: # The above fails if the message is too long. In that case, we # try again without the details. - message = get_message(log_file, repo=repo, run_id=run_id, details=False) + message = get_message( + log_file, + repo=repo, + pr_number=pr_number, + sha=sha, + run_id=run_id, + details=False, + ) create_or_update_comment( comment=comment, message=message, From 3963ebef801d9abb2d28601a028b377b6a76cd20 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Wed, 21 Jun 2023 14:17:41 +0200 Subject: [PATCH 2/5] add marks, download linter from main --- .github/workflows/lint.yml | 10 +++++++++- build_tools/get_comment.py | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5bc4af21cea10..b9714bcb9fece 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -6,6 +6,10 @@ name: linter on: - pull_request_target +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + jobs: lint: runs-on: ubuntu-latest @@ -32,7 +36,11 @@ jobs: pip install pytest ruff $(get_dep mypy min) $(get_dep black min) cython-lint - name: Run linting - run: ./build_tools/linting.sh &> /tmp/linting_output.txt + # We download the linting script from main, since this workflow is run + # from main itself. + run: | + curl https://raw.githubusercontent.com/scikit-learn/scikit-learn/main/build_tools/linting.sh -o ./build_tools/linting.sh + ./build_tools/linting.sh &> /tmp/linting_output.txt - name: Upload Artifact if: always() diff --git a/build_tools/get_comment.py b/build_tools/get_comment.py index 713bd2608bba5..463b12ed3a09f 100644 --- a/build_tools/get_comment.py +++ b/build_tools/get_comment.py @@ -160,13 +160,13 @@ def get_message(log_file, repo, pr_number, sha, run_id, details): if not message: # no issues detected, so this script "fails" return ( - "## Linting Passed\n" + "## ✔️ Linting Passed\n" "All linting checks passed. Your pull request is in excellent shape! ☀️" + commit_link ) message = ( - "## Linting issues\n\n" + "## ❌ Linting issues\n\n" "This PR is introducing linting issues. Here's a summary of the issues. " "Note that you can avoid having linting issues by enabling `pre-commit` " "hooks. Instructions to enable them can be found [here](" From b5eea2059cfb34ea0ba56fa391acdeba59bd8e01 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Wed, 21 Jun 2023 14:18:25 +0200 Subject: [PATCH 3/5] remove debug prints --- build_tools/get_comment.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/build_tools/get_comment.py b/build_tools/get_comment.py index 463b12ed3a09f..d67492957510e 100644 --- a/build_tools/get_comment.py +++ b/build_tools/get_comment.py @@ -249,9 +249,6 @@ def create_or_update_comment(comment, message, repo, pr_number, token): if __name__ == "__main__": - for key, value in os.environ.items(): - print(f"{key}={value}") - repo = os.environ["GITHUB_REPOSITORY"] token = os.environ["GITHUB_TOKEN"] pr_number = os.environ["PR_NUMBER"] From 95a090b2eb3b262ee295bfeab67ff8fc6e3a6b94 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Wed, 21 Jun 2023 15:05:37 +0200 Subject: [PATCH 4/5] always PR --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b9714bcb9fece..522b56bbd12b0 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -7,7 +7,7 @@ on: - pull_request_target concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} cancel-in-progress: true jobs: From f8f21a2dc1acc6d765ce01aef145ece5c0217cd8 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Wed, 21 Jun 2023 15:09:11 +0200 Subject: [PATCH 5/5] use github.ref --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 522b56bbd12b0..fb919989738fb 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -7,7 +7,7 @@ on: - pull_request_target concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number }} + group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: