From 8ba90b96bce0d8a81cfa9dd9df95431ec33dcdd9 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 9 Oct 2020 00:34:03 -0400 Subject: [PATCH 01/11] Add slash command "/format" (#1) --- .github/workflows/format-command.yml | 44 ++++++++++++++++++++ .github/workflows/slash-command-dispatch.yml | 17 ++++++++ 2 files changed, 61 insertions(+) create mode 100644 .github/workflows/format-command.yml create mode 100644 .github/workflows/slash-command-dispatch.yml diff --git a/.github/workflows/format-command.yml b/.github/workflows/format-command.yml new file mode 100644 index 00000000000..63a9fd469c9 --- /dev/null +++ b/.github/workflows/format-command.yml @@ -0,0 +1,44 @@ +name: format-command +on: + repository_dispatch: + types: [format-command] +jobs: + format: + runs-on: ubuntu-latest + steps: + # Checkout the pull request branch + - uses: actions/checkout@v2 + with: + token: ${{ secrets.PAT }} + repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }} + ref: ${{ github.event.client_payload.pull_request.head.ref }} + + # Setup Python environment + - uses: actions/setup-python@v1 + + # Install formatting tools + - name: Install formatting tools + run: pip install black blackdoc flake8 + + # Run "make check" + - name: Style check + id: format + run: echo ::set-output name=format::$(make check || echo "true") + + # Run "make format" and commit the change to the PR branch + - name: Commit to the PR branch + if: steps.format.outputs.format == 'true' + run: | + make format + git config --global user.name 'actions-bot' + git config --global user.email '58130806+actions-bot@users.noreply.github.com' + git commit -am "[format-command] fixes" + git push + + - name: Add reaction + uses: peter-evans/create-or-update-comment@v1 + with: + token: ${{ secrets.PAT }} + repository: ${{ github.event.client_payload.github.payload.repository.full_name }} + comment-id: ${{ github.event.client_payload.github.payload.comment.id }} + reaction-type: hooray diff --git a/.github/workflows/slash-command-dispatch.yml b/.github/workflows/slash-command-dispatch.yml new file mode 100644 index 00000000000..34afe363362 --- /dev/null +++ b/.github/workflows/slash-command-dispatch.yml @@ -0,0 +1,17 @@ +name: Slash Command Dispatch +on: + issue_comment: + types: [created] + # Add "edited" type for test purposes. Where possible, avoid using to prevent processing unnecessary events. + # types: [created, edited] +jobs: + slashCommandDispatch: + runs-on: ubuntu-latest + steps: + - name: Slash Command Dispatch + uses: peter-evans/slash-command-dispatch@v2 + with: + token: ${{ secrets.PAT }} + commands: | + format + issue-type: pull-request From 7a29620d9211e91de25218953ac9e8a368492180 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 9 Oct 2020 01:11:45 -0400 Subject: [PATCH 02/11] Fix output of "make check" (#3) --- .github/workflows/format-command.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/format-command.yml b/.github/workflows/format-command.yml index 63a9fd469c9..92e5eb55d79 100644 --- a/.github/workflows/format-command.yml +++ b/.github/workflows/format-command.yml @@ -22,12 +22,14 @@ jobs: # Run "make check" - name: Style check - id: format - run: echo ::set-output name=format::$(make check || echo "true") + id: check + run: | + make check + echo ::set-output name=format::$? # Run "make format" and commit the change to the PR branch - name: Commit to the PR branch - if: steps.format.outputs.format == 'true' + if: steps.check.outputs.format != 0 run: | make format git config --global user.name 'actions-bot' From 9837239fec140e56f6fc0ae236d2f7bc277b4d5b Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 9 Oct 2020 01:17:00 -0400 Subject: [PATCH 03/11] format-command: set continue-on-error to true for the style checking step --- .github/workflows/format-command.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/format-command.yml b/.github/workflows/format-command.yml index 92e5eb55d79..2f54110c583 100644 --- a/.github/workflows/format-command.yml +++ b/.github/workflows/format-command.yml @@ -26,6 +26,7 @@ jobs: run: | make check echo ::set-output name=format::$? + continue-on-error: true # Run "make format" and commit the change to the PR branch - name: Commit to the PR branch From fd7156eadc3aa276aad4a7bf822b74916e2219e7 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 9 Oct 2020 01:22:59 -0400 Subject: [PATCH 04/11] Debug the output of an action --- .github/workflows/format-command.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/format-command.yml b/.github/workflows/format-command.yml index 2f54110c583..a8378303150 100644 --- a/.github/workflows/format-command.yml +++ b/.github/workflows/format-command.yml @@ -28,6 +28,10 @@ jobs: echo ::set-output name=format::$? continue-on-error: true + - name: Debug + run: | + echo ${{ steps.check.outputs.format }} + # Run "make format" and commit the change to the PR branch - name: Commit to the PR branch if: steps.check.outputs.format != 0 From 778378f482a7a5febe28c65b34cbc23ea687fd74 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 9 Oct 2020 01:32:33 -0400 Subject: [PATCH 05/11] Always format and commit changes if any --- .github/workflows/format-command.yml | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/.github/workflows/format-command.yml b/.github/workflows/format-command.yml index a8378303150..46b81ec853b 100644 --- a/.github/workflows/format-command.yml +++ b/.github/workflows/format-command.yml @@ -20,27 +20,16 @@ jobs: - name: Install formatting tools run: pip install black blackdoc flake8 - # Run "make check" - - name: Style check - id: check - run: | - make check - echo ::set-output name=format::$? - continue-on-error: true - - - name: Debug - run: | - echo ${{ steps.check.outputs.format }} - # Run "make format" and commit the change to the PR branch - - name: Commit to the PR branch - if: steps.check.outputs.format != 0 + - name: Commit to the PR branch if any changes run: | make format - git config --global user.name 'actions-bot' - git config --global user.email '58130806+actions-bot@users.noreply.github.com' - git commit -am "[format-command] fixes" - git push + if [ $(git ls-files -m) ]; then + git config --global user.name 'actions-bot' + git config --global user.email '58130806+actions-bot@users.noreply.github.com' + git commit -am "[format-command] fixes" + git push + fi - name: Add reaction uses: peter-evans/create-or-update-comment@v1 From 488dee65b842ac69961fd1112283a21ef7301ce8 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 9 Oct 2020 02:02:15 -0400 Subject: [PATCH 06/11] Fix checking of changed files --- .github/workflows/format-command.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/format-command.yml b/.github/workflows/format-command.yml index 46b81ec853b..99f4d4281e7 100644 --- a/.github/workflows/format-command.yml +++ b/.github/workflows/format-command.yml @@ -24,7 +24,7 @@ jobs: - name: Commit to the PR branch if any changes run: | make format - if [ $(git ls-files -m) ]; then + if [[ $(git ls-files -m) ]]; then git config --global user.name 'actions-bot' git config --global user.email '58130806+actions-bot@users.noreply.github.com' git commit -am "[format-command] fixes" From 189921c99fae93bfd114bd8d3e47579b9d922352 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 23 Oct 2020 18:50:42 -0400 Subject: [PATCH 07/11] Apply suggestions from code review Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- .github/workflows/format-command.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/format-command.yml b/.github/workflows/format-command.yml index 99f4d4281e7..c0a320ec204 100644 --- a/.github/workflows/format-command.yml +++ b/.github/workflows/format-command.yml @@ -6,10 +6,17 @@ jobs: format: runs-on: ubuntu-latest steps: + # Generate token from GenericMappingTools bot + - uses: tibdex/github-app-token@v1 + id: generate-token + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + # Checkout the pull request branch - uses: actions/checkout@v2 with: - token: ${{ secrets.PAT }} + token: ${{ steps.generate-token.outputs.token }} repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }} ref: ${{ github.event.client_payload.pull_request.head.ref }} @@ -34,7 +41,7 @@ jobs: - name: Add reaction uses: peter-evans/create-or-update-comment@v1 with: - token: ${{ secrets.PAT }} + token: ${{ steps.generate-token.outputs.token }} repository: ${{ github.event.client_payload.github.payload.repository.full_name }} comment-id: ${{ github.event.client_payload.github.payload.comment.id }} reaction-type: hooray From c3feb6b86f6ed7af82818251cdc9c231444a0955 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 23 Oct 2020 20:00:00 -0400 Subject: [PATCH 08/11] Update .github/workflows/slash-command-dispatch.yml Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- .github/workflows/slash-command-dispatch.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/slash-command-dispatch.yml b/.github/workflows/slash-command-dispatch.yml index 34afe363362..85a489ac211 100644 --- a/.github/workflows/slash-command-dispatch.yml +++ b/.github/workflows/slash-command-dispatch.yml @@ -8,10 +8,17 @@ jobs: slashCommandDispatch: runs-on: ubuntu-latest steps: + # Generate token from GenericMappingTools bot + - uses: tibdex/github-app-token@v1 + id: generate-token + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + - name: Slash Command Dispatch uses: peter-evans/slash-command-dispatch@v2 with: - token: ${{ secrets.PAT }} + token: ${{ steps.generate-token.outputs.token }} commands: | format issue-type: pull-request From 11b45b3d039c35e8b51922f1176ef219b70ebc9d Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 23 Oct 2020 20:22:04 -0400 Subject: [PATCH 09/11] Explain "/format" in the pull request template --- .github/PULL_REQUEST_TEMPLATE.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 808b806cb3d..68c7847399f 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -15,3 +15,7 @@ Fixes # - [ ] Add new public functions/methods/classes to `doc/api/index.rst`. - [ ] Write detailed docstrings for all functions/methods. - [ ] If adding new functionality, add an example to docstrings or tutorials. + +**Notes** + +- You can write `/foramt` in the first line of a comment to automatically format your codes From 908f0686cd1031a46d9395be8eab19a3d3881e30 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 23 Oct 2020 20:24:21 -0400 Subject: [PATCH 10/11] Explain "/format" in the CONTRIBUTING guide --- CONTRIBUTING.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 19dd0d6f6d8..ea95d56d5ea 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -255,9 +255,10 @@ Before committing, run it to automatically format your code: make format ``` -Don't worry if you forget to do it. -Our continuous integration systems will warn us and you can make a new commit with the -formatted code. +Don't worry if you forget to do it. Our continuous integration systems will +warn us and you can make a new commit with the formatted code. +Even better, you can just write `/format` in the first line of any comments to +automatically format your codes. We also use [flake8](http://flake8.pycqa.org/en/latest/) and [pylint](https://www.pylint.org/) to check the quality of the code and quickly catch From c74e68a9821b5ca5f83d6a539e23587aebfec9c4 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 23 Oct 2020 20:35:47 -0400 Subject: [PATCH 11/11] Apply suggestions from code review Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- CONTRIBUTING.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 68c7847399f..305e07169f8 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -18,4 +18,4 @@ Fixes # **Notes** -- You can write `/foramt` in the first line of a comment to automatically format your codes +- You can write `/format` in the first line of a comment to lint the code automatically diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ea95d56d5ea..fedba6d0783 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -257,8 +257,8 @@ make format Don't worry if you forget to do it. Our continuous integration systems will warn us and you can make a new commit with the formatted code. -Even better, you can just write `/format` in the first line of any comments to -automatically format your codes. +Even better, you can just write `/format` in the first line of any comment in a +Pull Request to lint the code automatically. We also use [flake8](http://flake8.pycqa.org/en/latest/) and [pylint](https://www.pylint.org/) to check the quality of the code and quickly catch