From a01dadd71b2b58c1378c165a9b99f08da987cb8f Mon Sep 17 00:00:00 2001 From: FrankLeeeee Date: Mon, 9 Jan 2023 14:36:55 +0800 Subject: [PATCH 1/8] [workflow] added precommit check for code consistency --- .github/workflows/pre_commit.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/workflows/pre_commit.yml diff --git a/.github/workflows/pre_commit.yml b/.github/workflows/pre_commit.yml new file mode 100644 index 000000000000..55c781f1cbf8 --- /dev/null +++ b/.github/workflows/pre_commit.yml @@ -0,0 +1,12 @@ +name: pre-commit + +on: + pull_request: + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - uses: pre-commit/action@v3.0.0 From ceb3dc9d209c9d9fd6db6e9bf6f3a9af2f9644af Mon Sep 17 00:00:00 2001 From: FrankLeeeee Date: Mon, 9 Jan 2023 16:09:16 +0800 Subject: [PATCH 2/8] polish code --- .github/workflows/pre_commit.yml | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pre_commit.yml b/.github/workflows/pre_commit.yml index 55c781f1cbf8..b3f8809fadca 100644 --- a/.github/workflows/pre_commit.yml +++ b/.github/workflows/pre_commit.yml @@ -7,6 +7,22 @@ jobs: pre-commit: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Find the changed files + id: find-changed-files + uses: tj-actions/changed-files@v35 + with: + since_last_remote_commit: true - uses: actions/setup-python@v3 - - uses: pre-commit/action@v3.0.0 + - name: Set up pre-commit + run: | + pip install pre-commit + pre-commit install + - name: List changed files + run: | + for file in ${{ steps.find-changed-files.outputs.all_changed_files }}; do + echo "======= running pre-commit on ${file} =======" + pre-commit run --files $file + done From 161f4143274ae242a463676498744adc766766a7 Mon Sep 17 00:00:00 2001 From: FrankLeeeee Date: Mon, 9 Jan 2023 16:12:12 +0800 Subject: [PATCH 3/8] polish code --- .github/workflows/pre_commit.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pre_commit.yml b/.github/workflows/pre_commit.yml index b3f8809fadca..a33a0b86f2c7 100644 --- a/.github/workflows/pre_commit.yml +++ b/.github/workflows/pre_commit.yml @@ -10,17 +10,27 @@ jobs: - uses: actions/checkout@v2 with: fetch-depth: 0 + - name: Find the changed files id: find-changed-files uses: tj-actions/changed-files@v35 with: since_last_remote_commit: true + - uses: actions/setup-python@v3 + + - name: Cache pre-commit hooks + uses: actions/cache@v3 + with: + path: ~/.cache/pre-commit + key: ${{ runner.os }}-pre-commit-hooks + - name: Set up pre-commit run: | pip install pre-commit pre-commit install - - name: List changed files + + - name: Run pre-commit on Changed Files run: | for file in ${{ steps.find-changed-files.outputs.all_changed_files }}; do echo "======= running pre-commit on ${file} =======" From 2f7457d694e24aad66cbeed5293ae6ee47c447f0 Mon Sep 17 00:00:00 2001 From: FrankLeeeee Date: Mon, 9 Jan 2023 16:19:58 +0800 Subject: [PATCH 4/8] polish code --- .github/workflows/pre_commit.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/pre_commit.yml b/.github/workflows/pre_commit.yml index a33a0b86f2c7..b4d69c00f7fb 100644 --- a/.github/workflows/pre_commit.yml +++ b/.github/workflows/pre_commit.yml @@ -31,8 +31,27 @@ jobs: pre-commit install - name: Run pre-commit on Changed Files + id: precommit run: | for file in ${{ steps.find-changed-files.outputs.all_changed_files }}; do echo "======= running pre-commit on ${file} =======" pre-commit run --files $file done + + + + + - name: Create comment + if: always() && steps.precommit.outcome != 'success' + uses: peter-evans/create-or-update-comment@v2 + with: + body: | + Pre-commit check failed because the PR author did not apply pre-commit hooks during `git commit`. + + How to resolve: + 1. install pre-commit via `pip install pre-commit` + 2. install pre-commit hooks via `pre-commit install` in the root directory of this repository + 3. run pre-commit on a single file which is changed in the commit via `pre-commit run --files ` + + Reference: https://pre-commit.com/ + reactions: heart From 132880efe0c64c94b04ed92e6524e40bfd235f57 Mon Sep 17 00:00:00 2001 From: FrankLeeeee Date: Mon, 9 Jan 2023 16:22:28 +0800 Subject: [PATCH 5/8] polish code --- .github/workflows/pre_commit.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pre_commit.yml b/.github/workflows/pre_commit.yml index b4d69c00f7fb..29305d26f3f6 100644 --- a/.github/workflows/pre_commit.yml +++ b/.github/workflows/pre_commit.yml @@ -38,10 +38,7 @@ jobs: pre-commit run --files $file done - - - - - name: Create comment + - name: Create comment if: always() && steps.precommit.outcome != 'success' uses: peter-evans/create-or-update-comment@v2 with: @@ -54,4 +51,4 @@ jobs: 3. run pre-commit on a single file which is changed in the commit via `pre-commit run --files ` Reference: https://pre-commit.com/ - reactions: heart + reactions: heart From 131adc82afc306d6ffc9ae1a27017951d40858b1 Mon Sep 17 00:00:00 2001 From: FrankLeeeee Date: Mon, 9 Jan 2023 16:29:49 +0800 Subject: [PATCH 6/8] polish code --- .github/workflows/pre_commit.yml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/.github/workflows/pre_commit.yml b/.github/workflows/pre_commit.yml index 29305d26f3f6..62151ddd8cfd 100644 --- a/.github/workflows/pre_commit.yml +++ b/.github/workflows/pre_commit.yml @@ -37,18 +37,3 @@ jobs: echo "======= running pre-commit on ${file} =======" pre-commit run --files $file done - - - name: Create comment - if: always() && steps.precommit.outcome != 'success' - uses: peter-evans/create-or-update-comment@v2 - with: - body: | - Pre-commit check failed because the PR author did not apply pre-commit hooks during `git commit`. - - How to resolve: - 1. install pre-commit via `pip install pre-commit` - 2. install pre-commit hooks via `pre-commit install` in the root directory of this repository - 3. run pre-commit on a single file which is changed in the commit via `pre-commit run --files ` - - Reference: https://pre-commit.com/ - reactions: heart From 758db3053926c7170adcbeb7f21d701d09d9bd35 Mon Sep 17 00:00:00 2001 From: FrankLeeeee Date: Tue, 10 Jan 2023 11:29:48 +0800 Subject: [PATCH 7/8] polish code --- .github/workflows/pre_commit.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pre_commit.yml b/.github/workflows/pre_commit.yml index 62151ddd8cfd..8dbdbbc46ea1 100644 --- a/.github/workflows/pre_commit.yml +++ b/.github/workflows/pre_commit.yml @@ -9,7 +9,8 @@ jobs: steps: - uses: actions/checkout@v2 with: - fetch-depth: 0 + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.sha }} - name: Find the changed files id: find-changed-files From d0a701350e4c61ad14d0c2d9d7c9b6a990767dff Mon Sep 17 00:00:00 2001 From: FrankLeeeee Date: Tue, 10 Jan 2023 11:36:59 +0800 Subject: [PATCH 8/8] polish code --- .github/workflows/pre_commit.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/pre_commit.yml b/.github/workflows/pre_commit.yml index 8dbdbbc46ea1..128802629ce6 100644 --- a/.github/workflows/pre_commit.yml +++ b/.github/workflows/pre_commit.yml @@ -18,6 +18,12 @@ jobs: with: since_last_remote_commit: true + - name: List all changed files + run: | + for file in ${{ steps.find-changed-files.outputs.all_changed_files }}; do + echo "$file was changed" + done + - uses: actions/setup-python@v3 - name: Cache pre-commit hooks