|
| 1 | +name: Format Auto Review |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + types: [opened, reopened, synchronize] |
| 6 | + paths: |
| 7 | + - '**/*.md' |
| 8 | + |
| 9 | +permissions: |
| 10 | + checks: write |
| 11 | + contents: read |
| 12 | + pull-requests: write |
| 13 | + |
| 14 | +concurrency: ci-${{ github.workflow }}-${{ github.ref }} |
| 15 | + |
| 16 | +jobs: |
| 17 | + auto-review: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 25 | + ref: ${{ github.event.pull_request.head.ref }} |
| 26 | + - name: Setup Python |
| 27 | + uses: actions/setup-python@v4 |
| 28 | + with: |
| 29 | + python-version: '3.x' |
| 30 | + - name: Setup reviewdog |
| 31 | + uses: reviewdog/action-setup@v1.3.2 |
| 32 | + with: |
| 33 | + reviewdog_version: latest |
| 34 | + - name: Get changed files |
| 35 | + id: changed-files |
| 36 | + uses: tj-actions/changed-files@v46 |
| 37 | + with: |
| 38 | + files: '**/*.md' |
| 39 | + |
| 40 | + - name: Running autocorrect |
| 41 | + if: steps.changed-files.outputs.any_changed == 'true' |
| 42 | + env: |
| 43 | + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + run: | |
| 45 | + curl -sSL https://git.io/JcGER | sh |
| 46 | + autocorrect --lint --format rdjson ${{ steps.changed-files.outputs.all_changed_files }} | \ |
| 47 | + reviewdog -f=rdjson -level=warning -reporter=github-pr-review -fail-level=error |
| 48 | + - name: Running markdownlint |
| 49 | + uses: reviewdog/action-markdownlint@v0.26.2 |
| 50 | + if: ${{ !cancelled() && steps.changed-files.outputs.any_changed == 'true' }} |
| 51 | + with: |
| 52 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + reporter: github-pr-review |
| 54 | + markdownlint_flags: ${{ steps.changed-files.outputs.all_changed_files }} |
| 55 | + fail_level: error |
| 56 | + - name: Running custom punctuation checker |
| 57 | + if: ${{ !cancelled() && steps.changed-files.outputs.any_changed == 'true' }} |
| 58 | + env: |
| 59 | + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + run: | |
| 61 | + python tools/punctuation_checker.py \ |
| 62 | + "${{ steps.changed-files.outputs.all_changed_files }}" | \ |
| 63 | + reviewdog -efm="%f:%l:%t %m" -name="punctuation-check" -reporter=github-pr-review -fail-level=error -level=warning |
| 64 | +
|
| 65 | + - name: Post comment if failure |
| 66 | + uses: thollander/actions-comment-pull-request@v3 |
| 67 | + if: failure() |
| 68 | + with: |
| 69 | + comment-tag: autoreview-comment |
| 70 | + message: | |
| 71 | + 源码格式/语法检查未通过,请根据 GitHub Action 给出的 Code Review 审查建议进行修改(未给出修改建议的需根据提示手动修改),修改完成后请点击 "Resolve conversation"。 |
| 72 | +
|
| 73 | + 对于有争议的修改建议,可暂时不进行修改并在 PR 中进行讨论。 |
| 74 | +
|
| 75 | + > 注:可通过 "Files changed" 页面中的 "Add suggestion to batch" 功能来批量采纳修改建议。 |
| 76 | + - name: Post comment if success |
| 77 | + uses: thollander/actions-comment-pull-request@v3 |
| 78 | + if: success() |
| 79 | + with: |
| 80 | + comment-tag: autoreview-comment |
| 81 | + message: | |
| 82 | + 源码格式/语法检查已通过。 |
0 commit comments