autoclose comment workflow (scikit-learn/scikit-learn)
The autoclose comment workflow from scikit-learn/scikit-learn, explained and optimized by Latchkey.
A
CI health: A - excellent
Point runs-on at Latchkey and get job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the autoclose comment workflow from the scikit-learn/scikit-learn repository, a real project running GitHub Actions. It is shown here with attribution under its BSD-3-Clause license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
workflow (.yml)
name: autoclose comment
# Post comment on PRs when labeled with "autoclose".
permissions:
contents: read
pull-requests: write
on:
pull_request_target:
types:
- labeled
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
jobs:
post_comment:
name: post_comment
if: github.event.label.name == 'autoclose'
runs-on: ubuntu-latest
steps:
- name: comment on potential autoclose
run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/$GH_REPO/issues/$PULL_REQUEST_NUMBER/comments \
-f "body=$BODY"
env:
BODY: >
⏰ This pull request might be automatically closed in two weeks from now.
Thank you for your contribution to scikit-learn and for the effort you have
put into this PR. This pull request does not yet meet the quality and
clarity needed for an effective review. Project maintainers have limited
time for code reviews, and our goal is to prioritize well-prepared
contributions to keep scikit-learn maintainable.
To increase the chance of a productive review, please refer to: [How do I
improve my issue or pull
request?](https://scikit-learn.org/dev/faq.html#how-do-i-improve-my-issue-or-pull-request)
As the author, you are responsible for driving this PR, which entails doing
necessary background research as well as presenting its context and your
thought process. If you are a [new
contributor](https://scikit-learn.org/dev/developers/contributing.html#new-contributors),
or do not know how to fulfill these requirements, we recommend that you
familiarise yourself with scikit-learn's development conventions via other
contribution types (e.g., reviewing PRs) before submitting code.
Scikit-learn maintainers cannot provide one-to-one guidance on this PR.
However, if you ask focused, well-researched questions, a community
member may be willing to help. 💬
If you substantially improve this PR within two weeks, a team member may
remove the `autoclose` label and the PR stays open. Cosmetic changes or
incomplete fixes will not be sufficient. Maintainers will assess
improvements on their own schedule. Please do not ping (`@`) maintainers.
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: autoclose comment # Post comment on PRs when labeled with "autoclose". permissions: contents: read pull-requests: write on: pull_request_target: types: - labeled env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_REPO: ${{ github.repository }} PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }} jobs: post_comment: timeout-minutes: 30 name: post_comment if: github.event.label.name == 'autoclose' runs-on: latchkey-small steps: - name: comment on potential autoclose run: | gh api \ --method POST \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ /repos/$GH_REPO/issues/$PULL_REQUEST_NUMBER/comments \ -f "body=$BODY" env: BODY: > ⏰ This pull request might be automatically closed in two weeks from now. Thank you for your contribution to scikit-learn and for the effort you have put into this PR. This pull request does not yet meet the quality and clarity needed for an effective review. Project maintainers have limited time for code reviews, and our goal is to prioritize well-prepared contributions to keep scikit-learn maintainable. To increase the chance of a productive review, please refer to: [How do I improve my issue or pull request?](https://scikit-learn.org/dev/faq.html#how-do-i-improve-my-issue-or-pull-request) As the author, you are responsible for driving this PR, which entails doing necessary background research as well as presenting its context and your thought process. If you are a [new contributor](https://scikit-learn.org/dev/developers/contributing.html#new-contributors), or do not know how to fulfill these requirements, we recommend that you familiarise yourself with scikit-learn's development conventions via other contribution types (e.g., reviewing PRs) before submitting code. Scikit-learn maintainers cannot provide one-to-one guidance on this PR. However, if you ask focused, well-researched questions, a community member may be willing to help. 💬 If you substantially improve this PR within two weeks, a team member may remove the `autoclose` label and the PR stays open. Cosmetic changes or incomplete fixes will not be sufficient. Maintainers will assess improvements on their own schedule. Please do not ping (`@`) maintainers.
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Add a job timeout so a hung step cannot burn hours of runner time.
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.