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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/autoupdate-pre-commit-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Update pre-commit config packages
uses: technote-space/create-pr-action@v2
with:
GITHUB_TOKEN: ${{ secrets.ACTION_TRIGGER_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
EXECUTE_COMMANDS: |
pip install pre-commit
pre-commit autoupdate || (exit 0);
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/comment_bot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Comment-bot

on:
issue_comment:
types:
- created
- edited

jobs:
autotune:
name: "Fixup pre-commit formatting"
if: startsWith(github.event.comment.body, '@github-actions pre-commit')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: r-lib/actions/pr-fetch@master
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Cache multiple paths
uses: actions/cache@v2
with:
path: |
~/.cache/pre-commit
~/.cache/pip
key: pre-commit-dispatched-${{ runner.os }}-build
- uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install-pre-commit
run: python -m pip install --upgrade pre-commit
- name: Run pre-commit
run: pre-commit run --all-files || (exit 0)
- 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.

git commit -a -m 'Fixes from pre-commit [automated commit]' || echo "No changes to commit"
- uses: r-lib/actions/pr-push@master
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}