From e98d01d97fe508bf3d1a447d8ebcb619b773fc37 Mon Sep 17 00:00:00 2001 From: Alexander Koz Date: Thu, 4 Apr 2024 17:39:06 +0400 Subject: [PATCH] CI: improve format test for PRs --- .github/workflows/tests.yml | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2b822954..d5f59707 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -348,18 +348,29 @@ jobs: defaults: run: shell: bash - runs-on: ubuntu-latest + permissions: + actions: read + contents: read + pull-requests: write steps: - uses: actions/checkout@v4 - # - name: Check - # if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }} - # uses: clechasseur/rs-fmt-check@v2.0.1 - # # with: - # # toolchain: nightly - - name: Check - # if: ${{ github.event_name != 'pull_request' && github.event_name != 'pull_request_target' }} - run: cargo fmt -- --check + id: check + continue-on-error: true + run: >- + cargo fmt --all -- --check || + (echo "::error::Rust format error." && exit 1) + + - name: Format + id: format + if: steps.check.outcome == 'failure' && (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') + run: cargo fmt --all + + - name: Suggest Changes + if: success() && (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') + # https://docs.github.com/en/rest/pulls/reviews?apiVersion=2022-11-28#create-a-review-for-a-pull-request + uses: parkerbxyz/suggest-changes@v1 + # with: comment: Rustfmt suggested the formatting changes.