diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8b527922c4d39..fb919989738fb 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.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() @@ -78,6 +86,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 d414fe92975a0..d67492957510e 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() @@ -152,15 +152,21 @@ 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" + "## ✔️ 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](" @@ -169,6 +175,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 @@ -245,6 +252,7 @@ def create_or_update_comment(comment, message, repo, pr_number, token): 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"] @@ -261,7 +269,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, @@ -273,7 +288,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,