Skip to content

CI: add slash dispatch workflow to trigger pre-commit checks with comment #38444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 22, 2020

Conversation

MarcoGorelli
Copy link
Member

@MarcoGorelli MarcoGorelli commented Dec 13, 2020

This would be an on-demand bot to run pre-commit checks on a PR, which can be triggered by commenting

@github-actions pre-commit

on a pull request (see here for a demo).

Use case: if a PR is submitted and is good-to-go except for some linting error, we can just comment /pre-commit-run and have the bot fixup the errors.

@MarcoGorelli MarcoGorelli added CI Continuous Integration Code Style Code style, linting, code_checks labels Dec 13, 2020
@jorisvandenbossche
Copy link
Member

Cool, thanks!
That actually reminded me that we use something similar in the arrow repo, using comments to trigger actions: https://github.com/apache/arrow/blob/master/.github/workflows/comment_bot.yml. This seems to check the content of the comment, instead of using one workflow (with slash-command-dispatch) to trigger another, which seems a bit simpler to me?

@MarcoGorelli
Copy link
Member Author

Thanks @jorisvandenbossche ! I didn't know you could do that, that indeed does look simpler, I'll see if I can update this to do it that way

@MarcoGorelli
Copy link
Member Author

@jorisvandenbossche OK, done

If the comment-bot is now largely taken from arrow, my understanding is that we need to include their license at the top of the file - is this right?

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Dec 16, 2020

If the comment-bot is now largely taken from arrow, my understanding is that we need to include their license at the top of the file - is this right?

I don't think that that is necesaarily needed in this case. I mean, I contribute to several projects, and I am constantly applying what I tried / learned how to set up github actions in one project to other projects. Also, if you include the license, you would need to clearly state what has changed. And in the end, the main thing you copied is the line if: startsWith(github.event.comment.body, '@github-actions autotune') and the idea to use the pr-push action, for the rest it's a lot different compared to the original file from arrow.

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update!

- uses: actions/setup-python@v2
with:
python-version: 3.8
- name: install-pre-commit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- name: install-pre-commit
- name: Install pre-commit

(to be consistent with other names)

jobs:
autotune:
name: "Fixup pre-commit formatting"
if: startsWith(github.event.comment.body, '@github-actions autotune')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would maybe keep a "pre-commit" specific command

(we can always later have other bot actions, and name something combined "autotune", but for now it's just pre-commit)

- name: Commit results
run: |
git config user.name "$(git log -1 --pretty=format:%an)"
git config user.email "$(git log -1 --pretty=format:%ae)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this use the author of the last commit on the PR as commiter here?

Maybe your original "github actions" user is more transparent in who commited it?

      git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
      git config --local user.name "github-actions[bot]"
      git commit -m "Run pre-commit" -a

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, using the PR author / last commiter as commit author here is maybe good. That avoids that github wants to add the bot to the "Co-authored-by", which is not needed.
A "[automated commit]" in the commit message should be clear enough about the origin of the change.

run: |
git config user.name "$(git log -1 --pretty=format:%an)"
git config user.email "$(git log -1 --pretty=format:%ae)"
git commit -a -m 'Autoformat/render all the things [automated commit]' || echo "No changes to commit"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also keep your original message here, something more specific to pre-commit

@jorisvandenbossche
Copy link
Member

What are your thoughts on #38444 (comment) ?

@MarcoGorelli
Copy link
Member Author

Hey Joris - sorry, I missed that comment, somehow my brain only registered the review comments - I've removed the license header as I think your assessment makes perfect sense (as someone with far less experience, I was trying to tread carefully)

@jreback jreback added this to the 1.3 milestone Dec 22, 2020
@jreback
Copy link
Contributor

jreback commented Dec 22, 2020

this looks fine to me. let's give it a try.

@jreback
Copy link
Contributor

jreback commented Dec 22, 2020

@MarcoGorelli can you add somewhere the various actions that are availabel (take is in the user docs, but this one plus the backport ones could go somewhere)

@jreback jreback merged commit 4dff397 into pandas-dev:master Dec 22, 2020
@jorisvandenbossche
Copy link
Member

Thanks!

@MarcoGorelli MarcoGorelli deleted the slash-command branch December 23, 2020 08:06
@MarcoGorelli MarcoGorelli mentioned this pull request Dec 27, 2020
luckyvs1 pushed a commit to luckyvs1/pandas that referenced this pull request Jan 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Continuous Integration Code Style Code style, linting, code_checks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants